Documentation ¶
Index ¶
- type BadgerKV
- 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) LoadCommit(height uint64) (*types.Commit, error)
- func (s *DefaultStore) LoadCommitByHash(hash [32]byte) (*types.Commit, error)
- func (s *DefaultStore) LoadState() (state.State, error)
- func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit) error
- func (s *DefaultStore) UpdateState(state state.State) error
- type KVStore
- type PrefixKV
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerKV ¶
type BadgerKV struct {
// contains filtered or unexported fields
}
BadgerKV is a implementation of KVStore using Badger v3.
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) 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() (state.State, error)
LoadState returns last state saved with UpdateState.
func (*DefaultStore) SaveBlock ¶
SaveBlock adds block to the store along with corresponding commit. Stored height is updated if block height is greater than stored value.
func (*DefaultStore) UpdateState ¶
func (s *DefaultStore) UpdateState(state state.State) error
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. }
KVStore encapsulates key-value store abstraction, in minimalistic interface.
KVStore MUST be thread safe.
func NewInMemoryKVStore ¶
func NewInMemoryKVStore() KVStore
NewInMemoryKVStore builds KVStore that works in-memory (without accessing disk).
type PrefixKV ¶
type PrefixKV struct {
// contains filtered or unexported fields
}
func NewPrefixKV ¶
type Store ¶
type Store interface { // Height returns height of the highest block in store. 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) 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) // 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 state.State) error // LoadState returns last state saved with UpdateState. LoadState() (state.State, error) }
Store is minimal interface for storing and retrieving blocks, commits and state.