reth’s database abstraction layer with concrete implementations.
The database abstraction assumes that the underlying store is a KV store subdivided into tables.
One or more changes are tied to a transaction that is atomically committed to the data store at the same time. Strong consistency in what data is written and when is important for reth, so it is not possible to write data to the database outside of using a transaction.
Good starting points for this crate are:
Databasefor the main database abstraction
DbTxMut(RW) for the transaction abstractions.
DbCursorRW(RW) for the cursor abstractions (see below).
The abstraction also defines a couple of helpful abstractions for iterating and writing data:
- Cursors (
DbCursorRW) for iterating data in a table. Cursors are assumed to resolve data in a sorted manner when iterating from start to finish, and it is safe to assume that they are efficient at doing so.
- Walkers (
ReverseWalker) use cursors to walk the entries in a table, either fully from a specific point, or over a range.
Dup tables (see below) also have corresponding cursors and walkers (e.g.
These should be preferred when working with dup tables, as they provide additional methods
that are optimized for dup tables.
reth has two types of tables: simple KV stores (one key, one value) and dup tables (one key, many values). Dup tables can be efficient for certain types of data.
Tables implement the
An overview of the current data model of reth can be found in the
- Traits defining the database abstractions, such as cursors and transactions.
mdbxBindings for MDBX.
- reth’s snapshot database table import and access
- Tables and data models.
test-utilsCollection of database test utilities
- Database version utils.
- Add mask to select
Ncolumn values from a specific snapshot segment row.
(key, value)from the database and decodes it appropriately.
- Macro to declare duplicate key value table.
- Implements the
Arbitrarytrait for types with fixed array types.
- Macro to declare key value table.
- Database error type.
- Database write operation type.
- Opens up an existing database or creates a new one at the specified path. Creates tables if necessary. Read/Write mode.
- 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.
- Opens up an existing database. Read/Write mode with WriteMap enabled. It doesn’t create it or create tables if missing.
- Opens up an existing database. Read only mode. It doesn’t create it or create tables if missing.