Documentation ¶
Index ¶
- Constants
- type MTrieStorage
- func (f *MTrieStorage) Checkpointer() (*wal.Checkpointer, error)
- func (f *MTrieStorage) CloseStorage()
- func (f *MTrieStorage) DiskSize() (int64, error)
- func (f *MTrieStorage) Done() <-chan struct{}
- func (f *MTrieStorage) EmptyStateCommitment() flow.StateCommitment
- func (f *MTrieStorage) ForestSize() int
- func (f *MTrieStorage) GetRegisterTouches(registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment) ([]flow.RegisterTouch, error)
- func (f *MTrieStorage) GetRegisters(registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment) (values []flow.RegisterValue, err error)
- func (f *MTrieStorage) GetRegistersWithProof(registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment) (values []flow.RegisterValue, proofs []flow.StorageProof, err error)
- func (f *MTrieStorage) Ready() <-chan struct{}
- func (f *MTrieStorage) UpdateRegisters(ids []flow.RegisterID, values []flow.RegisterValue, ...) (newStateCommitment flow.StateCommitment, err error)
- func (f *MTrieStorage) UpdateRegistersWithProof(ids []flow.RegisterID, values []flow.RegisterValue, ...) (newStateCommitment flow.StateCommitment, proofs []flow.StorageProof, err error)
- type TrieVerifier
Constants ¶
const CacheSize = 1000
const (
// RegisterKeySize is the size of a Execution register's key [bytes]
RegisterKeySize = 32
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MTrieStorage ¶
type MTrieStorage struct {
// contains filtered or unexported fields
}
MTrieStorage is a fast memory-efficient fork-aware thread-safe trie-based key/value storage. MTrieStorage holds an array of registers (key value pairs) and keep tracks of changes over a limited time. Each register is referenced by an ID (key) and holds a value (byte slice). MTrieStorage provides atomic batched update and read (with or without proofs) operation given a list of keys. Every update to the MTrieStorage creates a new state commitment which captures the state of the storage. Under the hood, it uses binary merkle tries to generate inclusion and noninclusion proofs. MTrieStorage is fork-aware that means any update can applied at any previous statecommitments which forms a tree of tries (forest). The forest is in memory but all changes (e.g. register updates) are captured inside write-ahead-logs for crash recovery reasons. In order to limit the memory usage and maintain the performance storage only keeps limited number of tries and purge the old ones (LRU-based); in other words MTrieStorage is not designed to be used for archival use but make it possible for other software components to reconstruct very old tries using write-ahead logs.
func NewMTrieStorage ¶
func NewMTrieStorage(dbDir string, capacity int, metrics module.LedgerMetrics, reg prometheus.Registerer) (*MTrieStorage, error)
NewMTrieStorage creates a new in-memory trie-backed ledger storage with persistence.
func (*MTrieStorage) Checkpointer ¶
func (f *MTrieStorage) Checkpointer() (*wal.Checkpointer, error)
func (*MTrieStorage) CloseStorage ¶
func (f *MTrieStorage) CloseStorage()
CloseStorage closes the DB
func (*MTrieStorage) DiskSize ¶
func (f *MTrieStorage) DiskSize() (int64, error)
DiskSize returns the amount of disk space used by the storage (in bytes)
func (*MTrieStorage) Done ¶
func (f *MTrieStorage) Done() <-chan struct{}
Done implements interface module.ReadyDoneAware it closes all the open write-ahead log files.
func (*MTrieStorage) EmptyStateCommitment ¶
func (f *MTrieStorage) EmptyStateCommitment() flow.StateCommitment
EmptyStateCommitment returns the state commitment of an empty store (initial state)
func (*MTrieStorage) ForestSize ¶
func (f *MTrieStorage) ForestSize() int
ForestSize returns the number of tries stored in the forest
func (*MTrieStorage) GetRegisterTouches ¶
func (f *MTrieStorage) GetRegisterTouches( registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment, ) ( []flow.RegisterTouch, error, )
GetRegisterTouches reads values and proofs for the given registers and returns an slice of register touches
func (*MTrieStorage) GetRegisters ¶
func (f *MTrieStorage) GetRegisters( registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment, ) ( values []flow.RegisterValue, err error, )
GetRegisters read the values of the given register IDs at the given state commitment it returns the values in the same order as given registerIDs and errors (if any)
func (*MTrieStorage) GetRegistersWithProof ¶
func (f *MTrieStorage) GetRegistersWithProof( registerIDs []flow.RegisterID, stateCommitment flow.StateCommitment, ) ( values []flow.RegisterValue, proofs []flow.StorageProof, err error, )
GetRegistersWithProof read the values at the given registers at the given state commitment it returns values, inclusion proofs and errors (if any)
func (*MTrieStorage) Ready ¶
func (f *MTrieStorage) Ready() <-chan struct{}
Ready implements interface module.ReadyDoneAware it starts the EventLoop's internal processing loop.
func (*MTrieStorage) UpdateRegisters ¶
func (f *MTrieStorage) UpdateRegisters( ids []flow.RegisterID, values []flow.RegisterValue, stateCommitment flow.StateCommitment, ) ( newStateCommitment flow.StateCommitment, err error, )
UpdateRegisters updates the values by register ID given the state commitment it returns a new state commitment (state after update) and errors (if any)
func (*MTrieStorage) UpdateRegistersWithProof ¶
func (f *MTrieStorage) UpdateRegistersWithProof( ids []flow.RegisterID, values []flow.RegisterValue, stateCommitment flow.StateCommitment, ) ( newStateCommitment flow.StateCommitment, proofs []flow.StorageProof, err error, )
UpdateRegistersWithProof updates the values at the given registers and provides proof for those registers after update
type TrieVerifier ¶
type TrieVerifier struct {
// contains filtered or unexported fields
}
func NewTrieVerifier ¶
func NewTrieVerifier(keyByteSize int) *TrieVerifier
NewTrieVerifier creates a new trie-backed ledger verifier.
The verifier is configured with a height and a default hash value for each level.
func (*TrieVerifier) VerifyRegistersProof ¶
func (v *TrieVerifier) VerifyRegistersProof( registerIDs []flow.RegisterID, values []flow.RegisterValue, proof []flow.StorageProof, stateCommitment flow.StateCommitment, ) (verified bool, err error)
VerifyRegistersProof takes in an encoded proof along with registers, state, and values, and verifies if the proofs are correct