kvstore

package
v0.0.0-...-2be76b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

KVStore

There are two app's here: the KVStoreApplication and the PersistentKVStoreApplication.

KVStoreApplication

The KVStoreApplication is a simple merkle key-value store. Transactions of the form key=value are stored as key-value pairs in the tree. Transactions without an = sign set the value to the key. The app has no replay protection (other than what the mempool provides).

PersistentKVStoreApplication

The PersistentKVStoreApplication wraps the KVStoreApplication and provides two additional features:

  1. persistence of state across app restarts (using CometBFT's ABCI-Handshake mechanism)
  2. validator set changes

The state is persisted in leveldb along with the last block committed, and the Handshake allows any necessary blocks to be replayed. Validator set changes are effected using the following transaction format:

"val:pubkey1!power1,pubkey2!power2,pubkey3!power3"

where pubkeyN is a base64-encoded 32-byte ed25519 key and powerN is a new voting power for the validator with pubkeyN (possibly a new one). To remove a validator from the validator set, set power to 0. There is no sybil protection against new validators joining.

Documentation

Index

Constants

View Source
const (
	PreparePrefix = "prepare"
	ReplacePrefix = "replace"
)
View Source
const (
	ValidatorSetChangePrefix string = "val:"
)

Variables

View Source
var (
	ErrInvalidValidatorCount = errors.New("validator count must be between 1 and 100")
	ErrNilApplication        = errors.New("application cannot be nil")
)
View Source
var (
	ProtocolVersion uint64 = 0x1
)

Functions

func InitializeApp

func InitializeApp(app *PersistentKVStoreApplication) error

InitializeApp initializes a KVStore application with default settings

func InitializeAppWithValidators

func InitializeAppWithValidators(app *PersistentKVStoreApplication, validatorCount int) error

InitializeAppWithValidators initializes a KVStore application with a specific number of validators

func MakeValSetChangeTx

func MakeValSetChangeTx(pubkey pc.PublicKey, power int64) []byte

Types

type Application

type Application struct {
	types.BaseApplication

	RetainBlocks int64 // blocks to retain after commit (via ResponseCommit.RetainHeight)
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication() *Application

func (*Application) BeginBlock

func (*Application) CheckTx

func (*Application) Commit

func (app *Application) Commit() types.ResponseCommit

func (*Application) DeliverTx

tx is either "key=value" or just arbitrary bytes

func (*Application) Info

func (app *Application) Info(req types.RequestInfo) (resInfo types.ResponseInfo)

func (*Application) ProcessProposal

func (*Application) Query

func (app *Application) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery)

Returns an associated value or nil if missing.

func (*Application) SetGenBlockEvents

func (app *Application) SetGenBlockEvents()

type PersistentKVStoreApplication

type PersistentKVStoreApplication struct {

	// validator set
	ValUpdates []types.ValidatorUpdate
	// contains filtered or unexported fields
}

func NewPersistentKVStoreApplication

func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication

func (*PersistentKVStoreApplication) ApplySnapshotChunk

func (*PersistentKVStoreApplication) BeginBlock

Track the block hash and header information

func (*PersistentKVStoreApplication) CheckTx

func (*PersistentKVStoreApplication) Commit

Commit will panic if InitChain was not called

func (*PersistentKVStoreApplication) DeliverTx

tx is either "val:pubkey!power" or "key=value" or just arbitrary bytes

func (*PersistentKVStoreApplication) EndBlock

Update the validator set

func (*PersistentKVStoreApplication) Info

func (*PersistentKVStoreApplication) InitChain

Save the validators in the merkle tree

func (*PersistentKVStoreApplication) ListSnapshots

func (*PersistentKVStoreApplication) LoadSnapshotChunk

func (*PersistentKVStoreApplication) OfferSnapshot

func (*PersistentKVStoreApplication) PrepareProposal

func (*PersistentKVStoreApplication) ProcessProposal

func (*PersistentKVStoreApplication) Query

func (app *PersistentKVStoreApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery)

When path=/val and data={validator address}, returns the validator update (types.ValidatorUpdate) varint encoded. For any other path, returns an associated value or nil if missing.

func (*PersistentKVStoreApplication) SetGenBlockEvents

func (app *PersistentKVStoreApplication) SetGenBlockEvents()

func (*PersistentKVStoreApplication) SetLogger

func (app *PersistentKVStoreApplication) SetLogger(l log.Logger)

func (*PersistentKVStoreApplication) Validators

func (app *PersistentKVStoreApplication) Validators() (validators []types.ValidatorUpdate)

type State

type State struct {
	Size    int64  `json:"size"`
	Height  int64  `json:"height"`
	AppHash []byte `json:"app_hash"`
	// contains filtered or unexported fields
}

type ValidatorGenerator

type ValidatorGenerator struct {
	// contains filtered or unexported fields
}

ValidatorGenerator handles creation of validator updates

func NewValidatorGenerator

func NewValidatorGenerator(pubKeyLength int) *ValidatorGenerator

NewValidatorGenerator creates a new validator generator with custom settings

func (*ValidatorGenerator) GenerateValidator

func (vg *ValidatorGenerator) GenerateValidator(index int) types.ValidatorUpdate

GenerateValidator creates a single random validator with deterministic public key derived from the input index and random power value

func (*ValidatorGenerator) GenerateValidators

func (vg *ValidatorGenerator) GenerateValidators(count int) ([]types.ValidatorUpdate, error)

GenerateValidators creates a specified number of random validators

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL