Documentation ¶
Index ¶
- Constants
- type Ledger
- func (l *Ledger) Checkpointer() (*wal.Checkpointer, error)
- func (l *Ledger) Done() <-chan struct{}
- func (l *Ledger) DumpTrieAsJSON(state ledger.State, outputFilePath string) error
- func (l *Ledger) ExportCheckpointAt(state ledger.State, migrations []ledger.Migration, reporters []ledger.Reporter, ...) (ledger.State, error)
- func (l *Ledger) ForestSize() int
- func (l *Ledger) Get(query *ledger.Query) (values []ledger.Value, err error)
- func (l *Ledger) InitialState() ledger.State
- func (l *Ledger) MemSize() (int64, error)
- func (l *Ledger) Prove(query *ledger.Query) (proof ledger.Proof, err error)
- func (l *Ledger) Ready() <-chan struct{}
- func (l *Ledger) Set(update *ledger.Update) (newState ledger.State, err error)
Constants ¶
const DefaultCacheSize = 1000
const DefaultPathFinderVersion = 1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger (complete) is a fast memory-efficient fork-aware thread-safe trie-based key/value storage. Ledger holds an array of registers (key-value pairs) and keeps tracks of changes over a limited time. Each register is referenced by an ID (key) and holds a value (byte slice). Ledger provides atomic batched updates and read (with or without proofs) operation given a list of keys. Every update to the Ledger creates a new state which captures the state of the storage. Under the hood, it uses binary Merkle tries to generate inclusion and non-inclusion proofs. Ledger is fork-aware which means any update can be applied at any previous state 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 a limited number of tries and purge the old ones (LRU-based); in other words, Ledger is not designed to be used for archival usage but make it possible for other software components to reconstruct very old tries using write-ahead logs.
func NewLedger ¶
func NewLedger( wal wal.LedgerWAL, capacity int, metrics module.LedgerMetrics, log zerolog.Logger, pathFinderVer uint8) (*Ledger, error)
NewLedger creates a new in-memory trie-backed ledger storage with persistence.
func (*Ledger) Checkpointer ¶
func (l *Ledger) Checkpointer() (*wal.Checkpointer, error)
Checkpointer returns a checkpointer instance
func (*Ledger) Done ¶
func (l *Ledger) Done() <-chan struct{}
Done implements interface module.ReadyDoneAware it closes all the open write-ahead log files.
func (*Ledger) DumpTrieAsJSON ¶ added in v0.13.0
DumpTrieAsJSON export trie at specific state as a jsonl file, each line is json encode of a payload
func (*Ledger) ExportCheckpointAt ¶ added in v0.12.0
func (l *Ledger) ExportCheckpointAt(state ledger.State, migrations []ledger.Migration, reporters []ledger.Reporter, targetPathFinderVersion uint8, outputDir, outputFile string) (ledger.State, error)
ExportCheckpointAt exports a checkpoint at specific state commitment after applying migrations and returns the new state (after migration) and any errors
func (*Ledger) ForestSize ¶
ForestSize returns the number of tries stored in the forest
func (*Ledger) Get ¶
Get read the values of the given keys at the given state it returns the values in the same order as given registerIDs and errors (if any)
func (*Ledger) InitialState ¶ added in v0.10.0
InitialState returns the state of an empty ledger
func (*Ledger) MemSize ¶
MemSize return the amount of memory used by ledger TODO implement an approximate MemSize method