ledger

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2020 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const CacheSize = 1000
View Source
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) 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) GetRegisters

func (f *MTrieStorage) GetRegisters(
	registerIDs []flow.LegacyRegisterID,
	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.LegacyRegisterID,
	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.LegacyRegisterID,
	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.LegacyRegisterID,
	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.LegacyRegisterID,
	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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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