Documentation ¶
Index ¶
- Variables
- type Config
- type Database
- func (db *Database) AccountHistory(address common.Address, start, end uint64) (*pathdb.HistoryStats, error)
- func (db *Database) Cap(limit common.StorageSize) error
- func (db *Database) Close() error
- func (db *Database) Commit(root common.Hash, report bool) error
- func (db *Database) Dereference(root common.Hash) error
- func (db *Database) Disable() error
- func (db *Database) Disk() ethdb.Database
- func (db *Database) Enable(root common.Hash) error
- func (db *Database) HistoryRange() (uint64, uint64, error)
- func (db *Database) Initialized(genesisRoot common.Hash) bool
- func (db *Database) InsertPreimage(preimages map[common.Hash][]byte)
- func (db *Database) IsVerkle() bool
- func (db *Database) Journal(root common.Hash) error
- func (db *Database) NodeReader(blockRoot common.Hash) (database.NodeReader, error)
- func (db *Database) Preimage(hash common.Hash) []byte
- func (db *Database) Recover(target common.Hash) error
- func (db *Database) Recoverable(root common.Hash) (bool, error)
- func (db *Database) Reference(root common.Hash, parent common.Hash) error
- func (db *Database) Scheme() string
- func (db *Database) Size() (common.StorageSize, common.StorageSize, common.StorageSize)
- func (db *Database) StorageHistory(address common.Address, slot common.Hash, start uint64, end uint64) (*pathdb.HistoryStats, error)
- func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, ...) error
- func (db *Database) WritePreimages()
- type StateSet
Constants ¶
This section is empty.
Variables ¶
var HashDefaults = &Config{ Preimages: false, IsVerkle: false, HashDB: hashdb.Defaults, }
HashDefaults represents a config for using hash-based scheme with default settings.
var VerkleDefaults = &Config{ Preimages: false, IsVerkle: true, PathDB: pathdb.Defaults, }
VerkleDefaults represents a config for holding verkle trie data using path-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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Enable activates database and resets the state tree with the provided persistent state root once the state sync is finished.
func (*Database) HistoryRange ¶
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 ¶
Initialized returns an indicator if the state data is already initialized according to the state scheme.
func (*Database) InsertPreimage ¶
InsertPreimage writes pre-images of trie node to the preimage store.
func (*Database) IsVerkle ¶
IsVerkle returns the indicator if the database is holding a verkle tree.
func (*Database) Journal ¶
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) NodeReader ¶
NodeReader returns a reader for accessing trie nodes within the specified state. An error will be returned if the specified state is not available.
func (*Database) Recover ¶
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 ¶
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 ¶
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) Size ¶
func (db *Database) Size() (common.StorageSize, common.StorageSize, common.StorageSize)
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 *StateSet) 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.
type StateSet ¶
type StateSet struct { Destructs map[common.Hash]struct{} // Destructed accounts Accounts map[common.Hash][]byte // Mutated accounts in 'slim RLP' encoding AccountsOrigin map[common.Address][]byte // Original values of mutated accounts in 'slim RLP' encoding Storages map[common.Hash]map[common.Hash][]byte // Mutated storage slots in 'prefix-zero-trimmed' RLP format StoragesOrigin map[common.Address]map[common.Hash][]byte // Original values of mutated storage slots in 'prefix-zero-trimmed' RLP format }
StateSet represents a collection of mutated states during a state transition.