Documentation ¶
Index ¶
- Variables
- type Config
- type Database
- 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) Enable(root common.Hash) 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) Preimage(hash common.Hash) []byte
- func (db *Database) Reader(blockRoot common.Hash) (database.Reader, error)
- 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) SetBufferSize(size int) error
- func (db *Database) Size() (common.StorageSize, common.StorageSize, common.StorageSize)
- func (db *Database) Update(root common.Hash, parent common.Hash, block uint64, ...) error
- func (db *Database) UpdateAndReferenceRoot(root common.Hash, parent common.Hash, block uint64, ...) error
- func (db *Database) WritePreimages()
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewDatabase initializes the trie database with default settings, note the legacy hash-based scheme is used by default.
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) 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) Reader ¶
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 ¶
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) SetBufferSize ¶
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 ¶
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) 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) UpdateAndReferenceRoot ¶
func (*Database) WritePreimages ¶
func (db *Database) WritePreimages()
WritePreimages flushes all accumulated preimages to disk forcibly.