Documentation
¶
Index ¶
- Constants
- func GenerateKey(fields []string) string
- func NewDefaultKVStore(rootDir, dbPath, dbName string) (ds.Batching, error)
- func NewTestInMemoryKVStore() (ds.Batching, error)
- func PrefixEntries(ctx context.Context, store ds.Datastore, prefix string) (dsq.Results, error)
- type Batch
- type DefaultBatch
- func (b *DefaultBatch) Commit() error
- func (b *DefaultBatch) Delete(key ds.Key) error
- func (b *DefaultBatch) Put(key ds.Key, value []byte) error
- func (b *DefaultBatch) SaveBlockData(header *types.SignedHeader, data *types.Data, signature *types.Signature) error
- func (b *DefaultBatch) SetHeight(height uint64) error
- func (b *DefaultBatch) UpdateState(state types.State) error
- type DefaultStore
- func (s *DefaultStore) Close() error
- func (s *DefaultStore) GetBlockByHash(ctx context.Context, hash []byte) (*types.SignedHeader, *types.Data, error)
- func (s *DefaultStore) GetBlockData(ctx context.Context, height uint64) (*types.SignedHeader, *types.Data, error)
- func (s *DefaultStore) GetHeader(ctx context.Context, height uint64) (*types.SignedHeader, error)
- func (s *DefaultStore) GetMetadata(ctx context.Context, key string) ([]byte, error)
- func (s *DefaultStore) GetSignature(ctx context.Context, height uint64) (*types.Signature, error)
- func (s *DefaultStore) GetSignatureByHash(ctx context.Context, hash []byte) (*types.Signature, error)
- func (s *DefaultStore) GetState(ctx context.Context) (types.State, error)
- func (s *DefaultStore) GetStateAtHeight(ctx context.Context, height uint64) (types.State, error)
- func (s *DefaultStore) Height(ctx context.Context) (uint64, error)
- func (s *DefaultStore) NewBatch(ctx context.Context) (Batch, error)
- func (s *DefaultStore) Rollback(ctx context.Context, height uint64, aggregator bool) error
- func (s *DefaultStore) SetMetadata(ctx context.Context, key string, value []byte) error
- type Reader
- type Rollback
- type Store
Constants ¶
const ( // GenesisDAHeightKey is the key used for persisting the first DA included height in store. // It avoids to walk over the HeightToDAHeightKey to find the first DA included height. GenesisDAHeightKey = "gdh" // HeightToDAHeightKey is the key prefix used for persisting the mapping from a Evolve height // to the DA height where the block's header/data was included. // Full keys are like: rhb/<evolve_height>/h and rhb/<evolve_height>/d HeightToDAHeightKey = "rhb" // DAIncludedHeightKey is the key used for persisting the da included height in store. DAIncludedHeightKey = "d" // LastBatchDataKey is the key used for persisting the last batch data in store. LastBatchDataKey = "l" // LastSubmittedHeaderHeightKey is the key used for persisting the last submitted header height in store. LastSubmittedHeaderHeightKey = "last-submitted-header-height" )
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey creates a key from a slice of string fields, joining them with slashes.
func NewDefaultKVStore ¶
NewDefaultKVStore creates instance of default key-value store.
func NewTestInMemoryKVStore ¶
NewTestInMemoryKVStore builds KVStore that works in-memory (without accessing disk).
Types ¶
type Batch ¶
type Batch interface {
// SaveBlockData atomically saves the block header, data, and signature
SaveBlockData(header *types.SignedHeader, data *types.Data, signature *types.Signature) error
// SetHeight sets the height in the batch
SetHeight(height uint64) error
// UpdateState updates the state in the batch
UpdateState(state types.State) error
// Commit commits all batch operations atomically
Commit() error
// Put adds a put operation to the batch (used internally for rollback)
Put(key ds.Key, value []byte) error
// Delete adds a delete operation to the batch (used internally for rollback)
Delete(key ds.Key) error
}
Batch provides atomic operations for the store
type DefaultBatch ¶
type DefaultBatch struct {
// contains filtered or unexported fields
}
DefaultBatch provides a batched write interface for atomic store operations
func (*DefaultBatch) Commit ¶
func (b *DefaultBatch) Commit() error
Commit commits all batched operations atomically
func (*DefaultBatch) Delete ¶
func (b *DefaultBatch) Delete(key ds.Key) error
Delete adds a delete operation to the batch
func (*DefaultBatch) Put ¶
func (b *DefaultBatch) Put(key ds.Key, value []byte) error
Put adds a put operation to the batch
func (*DefaultBatch) SaveBlockData ¶
func (b *DefaultBatch) SaveBlockData(header *types.SignedHeader, data *types.Data, signature *types.Signature) error
SaveBlockData saves block data to the batch
func (*DefaultBatch) SetHeight ¶
func (b *DefaultBatch) SetHeight(height uint64) error
SetHeight sets the height in the batch
func (*DefaultBatch) UpdateState ¶
func (b *DefaultBatch) UpdateState(state types.State) error
UpdateState updates the state in the batch
type DefaultStore ¶
type DefaultStore struct {
// contains filtered or unexported fields
}
DefaultStore is a default store implementation.
func (*DefaultStore) Close ¶
func (s *DefaultStore) Close() error
Close safely closes underlying data storage, to ensure that data is actually saved.
func (*DefaultStore) GetBlockByHash ¶
func (s *DefaultStore) GetBlockByHash(ctx context.Context, hash []byte) (*types.SignedHeader, *types.Data, error)
GetBlockByHash returns block with given block header hash, or error if it's not found in Store.
func (*DefaultStore) GetBlockData ¶
func (s *DefaultStore) GetBlockData(ctx context.Context, height uint64) (*types.SignedHeader, *types.Data, error)
GetBlockData returns block header and data at given height, or error if it's not found in Store.
func (*DefaultStore) GetHeader ¶
func (s *DefaultStore) GetHeader(ctx context.Context, height uint64) (*types.SignedHeader, error)
GetHeader returns the header at the given height or error if it's not found in Store.
func (*DefaultStore) GetMetadata ¶
GetMetadata returns values stored for given key with SetMetadata.
func (*DefaultStore) GetSignature ¶
GetSignature returns signature for a block with given block header hash, or error if it's not found in Store.
func (*DefaultStore) GetSignatureByHash ¶
func (s *DefaultStore) GetSignatureByHash(ctx context.Context, hash []byte) (*types.Signature, error)
GetSignatureByHash returns signature for a block at given height, or error if it's not found in Store.
func (*DefaultStore) GetStateAtHeight ¶
GetStateAtHeight returns the state at the given height. If no state is stored at that height, it returns an error.
func (*DefaultStore) Height ¶
func (s *DefaultStore) Height(ctx context.Context) (uint64, error)
Height returns height of the highest block saved in the Store.
func (*DefaultStore) NewBatch ¶
func (s *DefaultStore) NewBatch(ctx context.Context) (Batch, error)
NewBatch creates a new batch for atomic operations
func (*DefaultStore) Rollback ¶
Rollback rolls back block data until the given height from the store. When aggregator is true, it will check the latest data included height and prevent rollback further than that. NOTE: this function does not rollback metadata. Those should be handled separately if required. Other stores are not rolled back either.
func (*DefaultStore) SetMetadata ¶
SetMetadata saves arbitrary value in the store.
Metadata is separated from other data by using prefix in KV.
type Reader ¶
type Reader interface {
// Height returns height of the highest block in store.
Height(ctx context.Context) (uint64, error)
// GetBlockData returns block at given height, or error if it's not found in Store.
GetBlockData(ctx context.Context, height uint64) (*types.SignedHeader, *types.Data, error)
// GetBlockByHash returns block with given block header hash, or error if it's not found in Store.
GetBlockByHash(ctx context.Context, hash []byte) (*types.SignedHeader, *types.Data, error)
// GetSignature returns signature for a block at given height, or error if it's not found in Store.
GetSignature(ctx context.Context, height uint64) (*types.Signature, error)
// GetSignatureByHash returns signature for a block with given block header hash, or error if it's not found in Store.
GetSignatureByHash(ctx context.Context, hash []byte) (*types.Signature, error)
// GetHeader returns the header at given height, or error if it's not found in Store.
GetHeader(ctx context.Context, height uint64) (*types.SignedHeader, error)
// GetState returns last state saved with UpdateState.
GetState(ctx context.Context) (types.State, error)
// GetStateAtHeight returns state saved at given height, or error if it's not found in Store.
GetStateAtHeight(ctx context.Context, height uint64) (types.State, error)
// GetMetadata returns values stored for given key with SetMetadata.
GetMetadata(ctx context.Context, key string) ([]byte, error)
}
type Store ¶
type Store interface {
Rollback
Reader
// SetMetadata saves arbitrary value in the store.
//
// This method enables evolve to safely persist any information.
SetMetadata(ctx context.Context, key string, value []byte) error
// Close safely closes underlying data storage, to ensure that data is actually saved.
Close() error
// NewBatch creates a new batch for atomic operations.
NewBatch(ctx context.Context) (Batch, error)
}
Store is minimal interface for storing and retrieving blocks, commits and state.