triedb

package
v0.0.0-...-8588118 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HashDefaults = &Config{
	Preimages: false,
	HashDB:    hashdb.Defaults,
}

HashDefaults represents a config for using hash-based scheme with default settings.

Functions

This section is empty.

Types

type Config

type Config struct {
	Preimages bool           // Flag whether the preimage of node key is recorded
	IsVerkle  bool           // Flag whether the db is holding a verkle tree
	HashDB    *hashdb.Config // Configs for hash-based scheme
	PathDB    *pathdb.Config // Configs for experimental path-based scheme
}

Config defines all necessary options for database.

type Database

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

Database is the wrapper of the underlying backend which is shared by different types of node backend as an entrypoint. It's responsible for all interactions relevant with trie nodes and node preimages.

func NewDatabase

func NewDatabase(diskdb ethdb.Database, config *Config) *Database

NewDatabase initializes the trie database with default settings, note the legacy hash-based scheme is used by default.

func (*Database) AccountHistory

func (db *Database) AccountHistory(address common.Address, start, end uint64) (*pathdb.HistoryStats, error)

AccountHistory inspects the account history within the specified range.

Start: State ID of the first history object for the query. 0 implies the first available object is selected as the starting point.

End: State ID of the last history for the query. 0 implies the last available object is selected as the starting point. Note end is included for query.

This function is only supported by path mode 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. The held pre-images accumulated up to this point will be flushed in case the size exceeds the threshold.

It's only supported by hash-based database and will return an error for others.

func (*Database) Close

func (db *Database) Close() error

Close flushes the dangling preimages to disk and closes the trie database. It is meant to be called when closing the blockchain object, so that all resources held can be released correctly.

func (*Database) Commit

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

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

func (*Database) Dereference

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

Dereference removes an existing reference from a root node. It's only supported by hash-based database and will return an error for others.

func (*Database) Disable

func (db *Database) Disable() error

Disable deactivates the database and invalidates all available state layers as stale to prevent access to the persistent state, which is in the syncing stage.

It's only supported by path-based database and will return an error for others.

func (*Database) Enable

func (db *Database) Enable(root common.Hash) error

Enable activates database and resets the state tree with the provided persistent state root once the state sync is finished.

func (*Database) HistoryRange

func (db *Database) HistoryRange() (uint64, uint64, error)

HistoryRange returns the block numbers associated with earliest and latest state history in the local store.

This function is only supported by path mode database.

func (*Database) Initialized

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

Initialized returns an indicator if the state data is already initialized according to the state scheme.

func (*Database) InsertPreimage

func (db *Database) InsertPreimage(preimages map[common.Hash][]byte)

InsertPreimage writes pre-images of trie node to the preimage store.

func (*Database) IsVerkle

func (db *Database) IsVerkle() bool

IsVerkle returns the indicator if the database is holding a verkle tree.

func (*Database) Journal

func (db *Database) Journal(root common.Hash) error

Journal commits an entire diff hierarchy to disk into a single journal entry. This is meant to be used during shutdown to persist the snapshot without flattening everything down (bad for reorgs). It's only supported by path-based database and will return an error for others.

func (*Database) Preimage

func (db *Database) Preimage(hash common.Hash) []byte

Preimage retrieves a cached trie node pre-image from preimage store.

func (*Database) Reader

func (db *Database) Reader(blockRoot common.Hash) (database.Reader, error)

Reader returns a reader for accessing all trie nodes with provided state root. An error will be returned if the requested state is not available.

func (*Database) Recover

func (db *Database) Recover(target common.Hash) error

Recover rollbacks the database to a specified historical point. The state is supported as the rollback destination only if it's canonical state and the corresponding trie histories are existent. It's only supported by path-based database and will return an error for others.

func (*Database) Recoverable

func (db *Database) Recoverable(root common.Hash) (bool, error)

Recoverable returns the indicator if the specified state is enabled to be recovered. It's only supported by path-based database and will return an error for others.

func (*Database) Reference

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

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.

It's only supported by hash-based database and will return an error for others.

func (*Database) Scheme

func (db *Database) Scheme() string

Scheme returns the node scheme used in the database.

func (*Database) SetBufferSize

func (db *Database) SetBufferSize(size int) error

SetBufferSize sets the node buffer size to the provided value(in bytes). It's only supported by path-based database and will return an error for others.

func (*Database) Size

Size returns the storage size of diff layer nodes above the persistent disk layer, the dirty nodes buffered within the disk layer, and the size of cached preimages.

func (*Database) StorageHistory

func (db *Database) StorageHistory(address common.Address, slot common.Hash, start uint64, end uint64) (*pathdb.HistoryStats, error)

StorageHistory inspects the storage history within the specified range.

Start: State ID of the first history object for the query. 0 implies the first available object is selected as the starting point.

End: State ID of the last history for the query. 0 implies the last available object is selected as the starting point. Note end is included for query.

Note, slot refers to the hash of the raw slot key.

This function is only supported by path mode database.

func (*Database) Update

func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error

Update performs a state transition by committing dirty nodes contained in the given set in order to update state from the specified parent to the specified root. The held pre-images accumulated up to this point will be flushed in case the size exceeds the threshold.

The passed in maps(nodes, states) will be retained to avoid copying everything. Therefore, these maps must not be changed afterwards.

func (*Database) WritePreimages

func (db *Database) WritePreimages()

WritePreimages flushes all accumulated preimages to disk forcibly.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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