1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! # 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
//!
//! ```text
//! ┌─────────────────────────────────────────────────┐
//! │ 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 `rocksdb` feature)
//!
//! ## Usage
//!
//! ```ignore
//! 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.
pub use apply_prefix;
pub use ;
/// Store Schema Version, must be updated on any breaking change.
///
/// When bumping this version, add a corresponding migration function to
/// `migrations::MIGRATIONS`. The migration framework will automatically
/// upgrade existing databases instead of requiring a full resync.
pub const STORE_SCHEMA_VERSION: u64 = 3;
/// Name of the file storing the metadata about the database.
///
/// This file contains version information and is used to detect
/// incompatible database formats on startup.
pub const STORE_METADATA_FILENAME: &str = "metadata.json";