Crate db

Available on crate feature provider only.
Expand description

MDBX implementation for reth’s database abstraction layer.

This crate is an implementation of [reth-db-api] for MDBX, as well as a few other common database types.

§Overview

An overview of the current data model of reth can be found in the tables module.

Modules§

common
Common types used throughout the abstraction.
cursor
Cursor database traits.
database
Database traits.
database_metrics
Database metrics trait extensions.
lockfile
Storage lock utils.
mdbxmdbx
Helper functions for initializing and opening a database.
mock
Mock database
models
Implements data structures specific to the database
static_file
reth’s static file database table import and access
table
Table traits
tables
Tables and data models.
test_utilstest-utils
Collection of database test utilities
transaction
Transaction database traits.
version
Database version utils.

Macros§

add_static_file_mask
Add mask to select N column values from a specific static file segment row.
impl_fixed_arbitrary
Implements the Arbitrary trait for types with fixed array types.
tables
Defines all the tables in the database.
tables_to_generic
Maps a run-time Tables enum value to its corresponding compile-time Table type.

Structs§

AccountChangeSets
Stores the state of an account before a certain transaction changed it. Change on state can be: account is created, selfdestructed, touched while empty or changed balance,nonce.
AccountsHistory
Stores pointers to block changeset with changes for each account key.
AccountsTrie
Stores the current state’s Merkle Patricia Tree.
BlockBodyIndices
Stores block indices that contains indexes of transaction and the count of them.
BlockOmmers
Stores the uncles/ommers of the block.
BlockWithdrawals
Stores the block withdrawals.
Bytecodes
Stores all smart contract bytecodes. There will be multiple accounts that have same bytecode So we would need to introduce reference counter. This will be small optimization on state.
CanonicalHeaders
Stores the header hashes belonging to the canonical chain.
ChainState
Stores generic chain state info, like the last finalized block.
ClientVersion
Client version that accessed the database.
DatabaseEnv
Wrapper for the libmdbx environment: Environment
HashedAccounts
Stores the current state of an Account indexed with keccak256Address This table is in preparation for merklization and calculation of state root. We are saving whole account data as it is needed for partial update when part of storage is changed. Benefit for merklization is that hashed addresses are sorted.
HashedStorages
Stores the current storage values indexed with keccak256Address and hash of storage key keccak256key. This table is in preparation for merklization and calculation of state root. Benefit for merklization is that hashed addresses/keys are sorted.
HeaderNumbers
Stores the block number corresponding to a header.
HeaderTerminalDifficulties
Stores the total difficulty from a block header.
Headers
Stores header bodies.
PlainAccountState
Stores the current state of an Account.
PlainStorageState
Stores the current value of a storage key.
PruneCheckpoints
Stores the highest pruned block number and prune mode of each prune segment.
RawDupSort
Raw DupSort table that can be used to access any table and its data in raw mode. This is useful for delayed decoding/encoding of data.
RawKey
Raw table key.
RawTable
Raw table that can be used to access any table and its data in raw mode. This is useful for delayed decoding/encoding of data.
RawValue
Raw table value.
Receipts
Canonical only Stores transaction receipts.
StageCheckpointProgresses
Stores arbitrary data to keep track of a stage first-sync progress.
StageCheckpoints
Stores the highest synced block number and stage-specific checkpoint of each stage.
StorageChangeSets
Stores the state of a storage key before a certain transaction changed it. If StorageEntry::value is zero, this means storage was not existing and needs to be removed.
StoragesHistory
Stores pointers to block number changeset with changes for each storage key.
StoragesTrie
From HashedAddress => NibblesSubKey => Intermediate value
TransactionBlocks
Stores the mapping of transaction number to the blocks number.
TransactionHashNumbers
Stores the mapping of the transaction hash to the transaction number.
TransactionSenders
Stores the transaction sender for each canonical transaction. It is needed to speed up execution stage and allows fetching signer without doing transaction signed recovery
Transactions
Canonical only Stores the transaction body for canonical transactions.
VersionHistory
Stores the history of client versions that have accessed the database with write privileges by unix timestamp in seconds.

Enums§

ChainStateKey
Keys for the ChainState table.
DatabaseEnvKind
Environment used when opening a MDBX environment. RO/RW.
DatabaseError
Database error type.
DatabaseWriteOperation
Database write operation type.
TableType
Enum for the types of tables present in libmdbx.
Tables
A table in the database.

Traits§

Database
Main Database trait that can open read-only and read-write transactions.
DbTxUnwindExt
Extension trait for DbTxMut that provides unwind functionality.
TableSet
General trait for defining the set of tables Used to initialize database
TableViewer
The general purpose of this is to use with a combination of Tables enum, by implementing a TableViewer trait you can operate on db tables in an abstract way.

Functions§

create_db
Creates a new database at the specified path if it doesn’t exist. Does NOT create tables. Check init_db.
init_db
Opens up an existing database or creates a new one at the specified path. Creates tables defined in Tables if necessary. Read/Write mode.
is_database_empty
Check if a db is empty. It does not provide any information on the validity of the data in it. We consider a database as non empty when it’s a non empty directory.
open_db
Opens up an existing database. Read/Write mode with WriteMap enabled. It doesn’t create it or create tables if missing.
open_db_read_only
Opens up an existing database. Read only mode. It doesn’t create it or create tables if missing.

Type Aliases§

BlockNumberList
List with transaction numbers.
StageId
Encoded stage id.
TableRawRow
Tuple with RawKey<T::Key> and RawValue<T::Value>.