Documentation ¶
Index ¶
- Variables
- type BadgerBatch
- type BadgerIterator
- type BadgerKV
- type Batch
- type DefaultStore
- func (s *DefaultStore) Height() uint64
- func (s *DefaultStore) LoadBlock(height uint64) (*types.Block, error)
- func (s *DefaultStore) LoadBlockByHash(hash [32]byte) (*types.Block, error)
- func (s *DefaultStore) LoadBlockResponses(height uint64) (*tmstate.ABCIResponses, error)
- func (s *DefaultStore) LoadCommit(height uint64) (*types.Commit, error)
- func (s *DefaultStore) LoadCommitByHash(hash [32]byte) (*types.Commit, error)
- func (s *DefaultStore) LoadState() (types.State, error)
- func (s *DefaultStore) LoadValidators(height uint64) (*tmtypes.ValidatorSet, error)
- func (s *DefaultStore) NewBatch() Batch
- func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit, batch Batch) (Batch, error)
- func (s *DefaultStore) SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses, batch Batch) (Batch, error)
- func (s *DefaultStore) SaveValidators(height uint64, validatorSet *tmtypes.ValidatorSet, batch Batch) (Batch, error)
- func (s *DefaultStore) SetHeight(height uint64)
- func (s *DefaultStore) UpdateState(state types.State, batch Batch) (Batch, error)
- type Iterator
- type KVStore
- type PrefixKV
- type PrefixKVBatch
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound is returned if key is not found in KVStore. ErrKeyNotFound = errors.New("key not found") )
Functions ¶
This section is empty.
Types ¶
type BadgerBatch ¶
type BadgerBatch struct {
// contains filtered or unexported fields
}
BadgerBatch encapsulates badger transaction
func (*BadgerBatch) Delete ¶
func (bb *BadgerBatch) Delete(key []byte) error
Delete removes the key and associated value from store
func (*BadgerBatch) Set ¶
func (bb *BadgerBatch) Set(key, value []byte) error
Set accumulates key-value entries in a transaction
type BadgerIterator ¶
type BadgerIterator struct {
// contains filtered or unexported fields
}
BadgerIterator encapsulates prefix iterator for badger kv store.
func (*BadgerIterator) Discard ¶
func (i *BadgerIterator) Discard()
Discard has to be called to free iterator resources.
func (*BadgerIterator) Error ¶
func (i *BadgerIterator) Error() error
Error returns last error that occurred during iteration.
func (*BadgerIterator) Key ¶
func (i *BadgerIterator) Key() []byte
Key returns key pointed by iterator.
func (*BadgerIterator) Next ¶
func (i *BadgerIterator) Next()
Next progresses iterator to the next key-value pair.
func (*BadgerIterator) Valid ¶
func (i *BadgerIterator) Valid() bool
Valid returns true if iterator is inside its prefix, false otherwise.
func (*BadgerIterator) Value ¶
func (i *BadgerIterator) Value() []byte
Value returns value pointer by iterator.
type BadgerKV ¶
type BadgerKV struct {
// contains filtered or unexported fields
}
BadgerKV is a implementation of KVStore using Badger v3.
func (*BadgerKV) NewBatch ¶
NewBatch creates new batch. Note: badger batches should be short lived as they use extra resources.
func (*BadgerKV) PrefixIterator ¶
PrefixIterator returns instance of prefix Iterator for BadgerKV.
type Batch ¶
type Batch interface { Set(key, value []byte) error // Accumulates KV entries in a transaction. Delete(key []byte) error // Deletes the given key. Commit() error // Commits the transaction. Discard() // Discards the transaction. }
Batch enables batching of transactions.
type DefaultStore ¶
type DefaultStore struct {
// contains filtered or unexported fields
}
DefaultStore is a default store implmementation.
func (*DefaultStore) Height ¶
func (s *DefaultStore) Height() uint64
Height returns height of the highest block saved in the Store.
func (*DefaultStore) LoadBlock ¶
func (s *DefaultStore) LoadBlock(height uint64) (*types.Block, error)
LoadBlock returns block at given height, or error if it's not found in Store. TODO(tzdybal): what is more common access pattern? by height or by hash? currently, we're indexing height->hash, and store blocks by hash, but we might as well store by height and index hash->height
func (*DefaultStore) LoadBlockByHash ¶
func (s *DefaultStore) LoadBlockByHash(hash [32]byte) (*types.Block, error)
LoadBlockByHash returns block with given block header hash, or error if it's not found in Store.
func (*DefaultStore) LoadBlockResponses ¶
func (s *DefaultStore) LoadBlockResponses(height uint64) (*tmstate.ABCIResponses, error)
LoadBlockResponses returns block results at given height, or error if it's not found in Store.
func (*DefaultStore) LoadCommit ¶
func (s *DefaultStore) LoadCommit(height uint64) (*types.Commit, error)
LoadCommit returns commit for a block at given height, or error if it's not found in Store.
func (*DefaultStore) LoadCommitByHash ¶
func (s *DefaultStore) LoadCommitByHash(hash [32]byte) (*types.Commit, error)
LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store.
func (*DefaultStore) LoadState ¶
func (s *DefaultStore) LoadState() (types.State, error)
LoadState returns last state saved with UpdateState.
func (*DefaultStore) LoadValidators ¶
func (s *DefaultStore) LoadValidators(height uint64) (*tmtypes.ValidatorSet, error)
LoadValidators loads validator set at given block height from store.
func (*DefaultStore) NewBatch ¶
func (s *DefaultStore) NewBatch() Batch
NewBatch creates a new db batch.
func (*DefaultStore) SaveBlock ¶
func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit, batch Batch) (Batch, error)
SaveBlock adds block to the store along with corresponding commit. Stored height is updated if block height is greater than stored value. In case a batch is provided, the block and commit are added to the batch and not saved.
func (*DefaultStore) SaveBlockResponses ¶
func (s *DefaultStore) SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses, batch Batch) (Batch, error)
SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store.
func (*DefaultStore) SaveValidators ¶
func (s *DefaultStore) SaveValidators(height uint64, validatorSet *tmtypes.ValidatorSet, batch Batch) (Batch, error)
SaveValidators stores validator set for given block height in store.
func (*DefaultStore) SetHeight ¶
func (s *DefaultStore) SetHeight(height uint64)
SetHeight sets the height saved in the Store if it is higher than the existing height
func (*DefaultStore) UpdateState ¶
UpdateState updates state saved in Store. Only one State is stored. If there is no State in Store, state will be saved.
type KVStore ¶
type KVStore interface { Get(key []byte) ([]byte, error) // Get gets the value for a key. Set(key []byte, value []byte) error // Set updates the value for a key. Delete(key []byte) error // Delete deletes a key. NewBatch() Batch // NewBatch creates a new batch. PrefixIterator(prefix []byte) Iterator // PrefixIterator creates iterator to traverse given prefix. }
KVStore encapsulates key-value store abstraction, in minimalistic interface.
KVStore MUST be thread safe.
func NewDefaultInMemoryKVStore ¶
func NewDefaultInMemoryKVStore() KVStore
NewDefaultInMemoryKVStore builds KVStore that works in-memory (without accessing disk).
func NewDefaultKVStore ¶
NewDefaultKVStore creates instance of default key-value store.
type PrefixKV ¶
type PrefixKV struct {
// contains filtered or unexported fields
}
PrefixKV is a key-value store that prepends all keys with given prefix.
func NewPrefixKV ¶
NewPrefixKV creates new PrefixKV on top of other KVStore.
func (*PrefixKV) PrefixIterator ¶
PrefixIterator creates iterator to traverse given prefix.
type PrefixKVBatch ¶
type PrefixKVBatch struct {
// contains filtered or unexported fields
}
PrefixKVBatch enables batching of operations on PrefixKV.
func (*PrefixKVBatch) Commit ¶
func (pb *PrefixKVBatch) Commit() error
Commit applies all operations in the batch atomically.
func (*PrefixKVBatch) Delete ¶
func (pb *PrefixKVBatch) Delete(key []byte) error
Delete adds delete operation to batch.
func (*PrefixKVBatch) Discard ¶
func (pb *PrefixKVBatch) Discard()
Discard discards all operations in the batch.
func (*PrefixKVBatch) Set ¶
func (pb *PrefixKVBatch) Set(key, value []byte) error
Set adds key-value pair to batch.
type Store ¶
type Store interface { // NewBatch creates a new db batch. NewBatch() Batch // Height returns height of the highest block in store. Height() uint64 // SetHeight sets the height saved in the Store if it is higher than the existing height. SetHeight(height uint64) // SaveBlock saves block along with its seen commit (which will be included in the next block). SaveBlock(block *types.Block, commit *types.Commit, batch Batch) (Batch, error) // LoadBlock returns block at given height, or error if it's not found in Store. LoadBlock(height uint64) (*types.Block, error) // LoadBlockByHash returns block with given block header hash, or error if it's not found in Store. LoadBlockByHash(hash [32]byte) (*types.Block, error) // SaveBlockResponses saves block responses (events, tx responses, validator set updates, etc) in Store. SaveBlockResponses(height uint64, responses *tmstate.ABCIResponses, batch Batch) (Batch, error) // LoadBlockResponses returns block results at given height, or error if it's not found in Store. LoadBlockResponses(height uint64) (*tmstate.ABCIResponses, error) // LoadCommit returns commit for a block at given height, or error if it's not found in Store. LoadCommit(height uint64) (*types.Commit, error) // LoadCommitByHash returns commit for a block with given block header hash, or error if it's not found in Store. LoadCommitByHash(hash [32]byte) (*types.Commit, error) // UpdateState updates state saved in Store. Only one State is stored. // If there is no State in Store, state will be saved. UpdateState(state types.State, batch Batch) (Batch, error) // LoadState returns last state saved with UpdateState. LoadState() (types.State, error) SaveValidators(height uint64, validatorSet *tmtypes.ValidatorSet, batch Batch) (Batch, error) LoadValidators(height uint64) (*tmtypes.ValidatorSet, error) }
Store is minimal interface for storing and retrieving blocks, commits and state.