store

package
v0.0.0-...-4c58a3e Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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.

func (*BadgerKV) Delete

func (b *BadgerKV) Delete(key []byte) error

Delete removes key and corresponding value from store.

func (*BadgerKV) Get

func (b *BadgerKV) Get(key []byte) ([]byte, error)

Get returns value for given key, or error.

func (*BadgerKV) Set

func (b *BadgerKV) Set(key []byte, value []byte) error

Set saves key-value mapping in store.

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

func (s *DefaultStore) SaveBlock(block *types.Block, commit *types.Commit) error

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

func NewPrefixKV(kv KVStore, prefix []byte) *PrefixKV

func (*PrefixKV) Delete

func (p *PrefixKV) Delete(key []byte) error

func (*PrefixKV) Get

func (p *PrefixKV) Get(key []byte) ([]byte, error)

func (*PrefixKV) Set

func (p *PrefixKV) Set(key []byte, value []byte) error

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.

func New

func New(kv KVStore) Store

New returns new, default store.

Jump to

Keyboard shortcuts

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