pathdb

package
v0.6.11 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: GPL-3.0, LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultBufferSize is the default memory allowance of node buffer
	// that aggregates the writes from above until it's flushed into the
	// disk. It's meant to be used once the initial sync is finished.
	// Do not increase the buffer size arbitrarily, otherwise the system
	// pause time will increase when the database writes happen.
	DefaultBufferSize = 64 * 1024 * 1024
)

Variables

View Source
var Defaults = &Config{
	StateHistory:   params.FullImmutabilityThreshold,
	CleanCacheSize: defaultCleanSize,
	DirtyCacheSize: DefaultBufferSize,
}

Defaults contains default settings for Ethereum mainnet.

View Source
var ReadOnly = &Config{ReadOnly: true}

ReadOnly is the config in order to open database in read only mode.

Functions

This section is empty.

Types

type Config

type Config struct {
	StateHistory   uint64 // Number of recent blocks to maintain state history for
	CleanCacheSize int    // Maximum memory allowance (in bytes) for caching clean nodes
	DirtyCacheSize int    // Maximum memory allowance (in bytes) for caching dirty nodes
	ReadOnly       bool   // Flag whether the database is opened in read only mode.
}

Config contains the settings for database.

type Database

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

Database is a multiple-layered structure for maintaining in-memory trie nodes. It consists of one persistent base layer backed by a key-value store, on top of which arbitrarily many in-memory diff layers are stacked. The memory diffs can form a tree with branching, but the disk layer is singleton and common to all. If a reorg goes deeper than the disk layer, a batch of reverse diffs can be applied to rollback. The deepest reorg that can be handled depends on the amount of state histories tracked in the disk.

At most one readable and writable database can be opened at the same time in the whole system which ensures that only one database writer can operate disk state. Unexpected open operations can cause the system to panic.

func New

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

New attempts to load an already existing layer from a persistent key-value store (with a number of memory layers from a journal). If the journal is not matched with the base persistent layer, all the recorded diff layers are discarded.

func (*Database) Close

func (db *Database) Close() error

Close closes the trie database and the held freezer.

func (*Database) Commit

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

Commit traverses downwards the layer tree from a specified layer with the provided state root and all the layers below are flattened downwards. It can be used alone and mostly for test purposes.

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.

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

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

Initialized returns an indicator if the state data is already initialized in path-based scheme.

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 layer without flattening everything down (bad for reorgs). And this function will mark the database as read-only to prevent all following mutation to disk.

func (*Database) Reader

func (db *Database) Reader(root common.Hash) (layer, error)

Reader retrieves a layer belonging to the given state root.

func (*Database) Recover

func (db *Database) Recover(root common.Hash, loader triestate.TrieLoader) 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.

func (*Database) Recoverable

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

Recoverable returns the indicator if the specified state is recoverable.

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

func (*Database) Size

func (db *Database) Size() (diffs common.StorageSize, nodes 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, parentRoot common.Hash, block uint64, nodes *trienode.MergedNodeSet, states *triestate.Set) error

Update adds a new layer into the tree, if that can be linked to an existing old parent. It is disallowed to insert a disk layer (the origin of all). Apart from that this function will flatten the extra diff layers at bottom into disk to only keep 128 diff layers in memory by default.

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

Jump to

Keyboard shortcuts

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