kvstore

package
v0.27.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: Apache-2.0 Imports: 13 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,addr2/power2,addr3/power3"

where power1 is the new voting power for the validator with pubkey1 (possibly a new one). There is no sybil protection against new validators joining. Validators can be removed by setting their power to 0.

Documentation

Index

Constants

View Source
const (
	ValidatorSetChangePrefix string = "val:"
)

Variables

View Source
var (
	ProtocolVersion version.Protocol = 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 MakeValSetChangeTx

func MakeValSetChangeTx(pubkey types.PubKey, power int64) []byte

func RandVal

func RandVal(i int) types.ValidatorUpdate

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

func RandVals

func RandVals(cnt int) []types.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 KVStoreApplication

type KVStoreApplication struct {
	types.BaseApplication
	// contains filtered or unexported fields
}

func NewKVStoreApplication

func NewKVStoreApplication() *KVStoreApplication

func (*KVStoreApplication) CheckTx

func (app *KVStoreApplication) CheckTx(tx []byte) types.ResponseCheckTx

func (*KVStoreApplication) Commit

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

func (*KVStoreApplication) DeliverTx

func (app *KVStoreApplication) DeliverTx(tx []byte) types.ResponseDeliverTx

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

func (*KVStoreApplication) Info

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

func (*KVStoreApplication) Query

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

type PersistentKVStoreApplication

type PersistentKVStoreApplication struct {

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

func NewPersistentKVStoreApplication

func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication

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

func (*PersistentKVStoreApplication) SetLogger

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

func (*PersistentKVStoreApplication) SetOption

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
}

Jump to

Keyboard shortcuts

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