Expand description
§ethrex Storage
This crate provides persistent storage for the ethrex Ethereum client.
§Overview
The storage layer handles:
- Block storage (headers, bodies, receipts)
- State storage (accounts, code, storage slots)
- Merkle Patricia Trie management
- Transaction indexing
- Chain configuration
§Architecture
┌─────────────────────────────────────────────────┐
│ Store │
│ (High-level API for blockchain operations) │
└─────────────────────────────────────────────────┘
│
┌────────────┴────────────┐
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ InMemoryBackend │ │ RocksDBBackend │
│ (Testing) │ │ (Production) │
└─────────────────┘ └─────────────────┘§Storage Backends
- InMemory: Fast, non-persistent storage for testing
- RocksDB: Production-grade persistent storage (requires
rocksdbfeature)
§Usage
ⓘ
use ethrex_storage::{Store, EngineType};
// Create a new store with RocksDB backend
let store = Store::new("./data", EngineType::RocksDB)?;
// Or from a genesis file
let store = Store::new_from_genesis(
Path::new("./data"),
EngineType::RocksDB,
"genesis.json"
).await?;
// Add a block
store.add_block(block).await?;
// Query state
let balance = store.get_account_info(block_number, address)?.map(|a| a.balance);§State Management
State is stored using Merkle Patricia Tries for efficient verification:
- State Trie: Maps account addresses to account data
- Storage Tries: Maps storage keys to values for each contract
- Code Storage: Separate storage for contract bytecode
The store maintains a cache layer (TrieLayerCache) for efficient state access
without requiring full trie traversal for recent blocks.
Re-exports§
pub use store::AccountUpdatesList;pub use store::DEFAULT_ROCKSDB_BLOCK_CACHE_SIZE_BYTES;pub use store::EngineType;pub use store::Store;pub use store::StoreConfig;pub use store::UpdateBatch;pub use store::has_valid_db;pub use store::hash_address;pub use store::hash_key;pub use store::read_chain_id_from_db;
Modules§
- api
- Storage Backend API
- backend
- This module contains the implementations of the
StorageBackendtrait for our different databases. - error
- migrations
- rlp
- store
- trie
- utils
Constants§
- STORE_
METADATA_ FILENAME - Name of the file storing the metadata about the database.
- STORE_
SCHEMA_ VERSION - Store Schema Version, must be updated on any breaking change.
Functions§
- apply_
prefix - Prepends an account address prefix (with an invalid nibble
17as separator) to a trie path, distinguishing storage trie entries from state trie entries in the flat key-value namespace. Returns the path unchanged ifprefixisNone(state trie).