kvstore

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: Apache-2.0 Imports: 11 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 Tendermint'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

This section is empty.

Variables

View Source
var (
	ProtocolVersion uint64 = 0x1
)

Functions

func InitKVStore

func InitKVStore(app *PersistentKVStoreApplication)

InitKVStore initializes the kvstore app with some data, which allows tests to pass and is fine as long as you don't make any tx that modify the validator state

func RandVal

func RandVal(i int) abci.ValidatorUpdate

RandVal creates one random validator, with a key derived from the input value

func RandVals

func RandVals(cnt int) []abci.ValidatorUpdate

RandVals returns a list of cnt validators for initializing the application. Note that the keys are deterministically derived from the index in the array, while the power is random (Change this if not desired)

Types

type Application

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

func NewApplication

func NewApplication() *Application

func (*Application) ApplySnapshotChunk

func (*Application) CheckTx

func (*Application) Commit

func (*Application) Echo

func (app *Application) Echo(ctx context.Context, req *abci.EchoRequest) (*abci.EchoResponse, error)

func (*Application) ExtendVote

func (*Application) FinalizeBlock

func (*Application) Info

func (app *Application) Info(ctx context.Context, req *abci.InfoRequest) (*abci.InfoResponse, error)

func (*Application) InitChain

func (*Application) ListSnapshots

func (*Application) LoadSnapshotChunk

func (*Application) OfferSnapshot

func (*Application) PrepareProposal

Additional methods required by the Application interface

func (*Application) ProcessProposal

func (*Application) Query

func (app *Application) Query(ctx context.Context, reqQuery *abci.QueryRequest) (*abci.QueryResponse, error)

Returns an associated value or nil if missing.

func (*Application) VerifyVoteExtension

type PersistentKVStoreApplication

type PersistentKVStoreApplication struct {

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

func NewPersistentKVStoreApplication

func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication

func (*PersistentKVStoreApplication) ApplySnapshotChunk

func (*PersistentKVStoreApplication) CheckTx

func (*PersistentKVStoreApplication) Commit

Commit will panic if InitChain was not called

func (*PersistentKVStoreApplication) Echo

func (*PersistentKVStoreApplication) ExtendVote

func (*PersistentKVStoreApplication) FinalizeBlock

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

Additional required methods for the Application interface

func (*PersistentKVStoreApplication) ProcessProposal

func (*PersistentKVStoreApplication) Query

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) SetLogger

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

func (*PersistentKVStoreApplication) VerifyVoteExtension

type State

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

Jump to

Keyboard shortcuts

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