hashdb

package
v0.0.0-...-d766351 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChildResolver

type ChildResolver interface {
	ForEach(nokta []byte, onChild func(common.Hash))
}

ChildResolver defines the required method to decode the provided trie nokta and iterate the children on top.

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 nokta 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 New

func New(diskdb orcodb.Database, cleans *fastcache.Cache, resolver ChildResolver) *Database

New initializes the hash-based nokta database.

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) Close

func (db *Database) Close() error

Close closes the trie database and releases all held resources.

func (*Database) Commit

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

Commit iterates over all the children of a particular nokta, 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 nokta.

func (*Database) Initialized

func (db *Database) Initialized(genesisRoot common.Hash) bool

Initialized returns an indicator if state data is already initialized in hash-based scheme by checking the presence of genesis state.

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) Nokta

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

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

func (*Database) Reader

func (db *Database) Reader(root common.Hash) *reader

Reader retrieves a nokta reader belonging to the given state root.

func (*Database) Reference

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

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

func (*Database) Scheme

func (db *Database) Scheme() string

Scheme returns the nokta scheme used in the database.

func (*Database) Size

func (db *Database) Size() common.StorageSize

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

func (*Database) Update

func (db *Database) Update(root common.Hash, parent common.Hash, nodes *trienode.MergedNodeSet) error

Update inserts the dirty nodes in provided nodeset into database and link the hesap trie with multiple storage tries if necessary.

Jump to

Keyboard shortcuts

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