trie

package
v0.0.0-...-3d074b0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Cache     int    // Memory allowance (MB) to use for caching trie nodes in memory
	Journal   string // Journal of clean cache to survive node restarts
	Preimages bool   // Flag whether the preimage of trie key is recorded
}

Config defines all necessary options for database.

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is an intermediate write layer between the trie data structures and the disk database. The aim is to accumulate trie writes in-memory and only periodically flush a couple tries to disk, garbage collecting the remainder.

Note, the trie Database is **not** thread safe in its mutations, but it **is** thread safe in providing individual, independent node access. The rationale behind this split design is to provide read access to RPC handlers and sync servers even while the trie is executing expensive garbage collection.

func NewDatabase

func NewDatabase(diskdb ethdb.KeyValueStore) *Database

NewDatabase creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected. No read cache is created, so all data retrievals will hit the underlying disk database.

func NewDatabaseWithConfig

func NewDatabaseWithConfig(diskdb ethdb.KeyValueStore, config *Config) *Database

NewDatabaseWithConfig creates a new trie database to store ephemeral trie content before its written out to disk or garbage collected. It also acts as a read cache for nodes loaded from disk.

func (*Database) Cap

func (db *Database) Cap(limit common.StorageSize) error

Cap iteratively flushes old but still referenced trie nodes until the total memory usage goes below the given threshold.

Note, this method is a non-synchronized mutator. It is unsafe to call this concurrently with other mutators.

func (*Database) Commit

func (db *Database) Commit(node common.Hash, report bool, callback func(common.Hash)) error

Commit iterates over all the children of a particular node, writes them out to disk, forcefully tearing down all references in both directions. As a side effect, all pre-images accumulated up to this point are also written.

Note, this method is a non-synchronized mutator. It is unsafe to call this concurrently with other mutators.

func (*Database) Dereference

func (db *Database) Dereference(root common.Hash)

Dereference removes an existing reference from a root node.

func (*Database) DiskDB

func (db *Database) DiskDB() ethdb.KeyValueStore

DiskDB retrieves the persistent storage backing the trie database.

func (*Database) Node

func (db *Database) Node(hash common.Hash) ([]byte, error)

Node retrieves an encoded cached trie node from memory. If it cannot be found cached, the method queries the persistent database for the content.

func (*Database) Nodes

func (db *Database) Nodes() []common.Hash

Nodes retrieves the hashes of all the nodes cached within the memory database. This method is extremely expensive and should only be used to validate internal states in test code.

func (*Database) Reference

func (db *Database) Reference(child common.Hash, parent common.Hash)

Reference adds a new reference from a parent node to a child node. This function is used to add reference between internal trie node and external node(e.g. storage trie root), all internal trie nodes are referenced together by database itself.

func (*Database) SaveCache

func (db *Database) SaveCache(dir string) error

SaveCache atomically saves fast cache data to the given dir using all available CPU cores.

func (*Database) SaveCachePeriodically

func (db *Database) SaveCachePeriodically(dir string, interval time.Duration, stopCh <-chan struct{})

SaveCachePeriodically atomically saves fast cache data to the given dir with the specified interval. All dump operation will only use a single CPU core.

func (*Database) Size

Size returns the current storage size of the memory cache in front of the persistent database layer.

Jump to

Keyboard shortcuts

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