Skip to main content

ethrex_storage/api/
tables.rs

1//! Table names used by the storage engine.
2
3/// Canonical block hashes column family: [`u8;_`] => [`Vec<u8>`]
4/// - [`u8;_`] = `block_number.to_le_bytes()`
5/// - [`Vec<u8>`] = `block_hash.encode_to_vec()`
6pub const CANONICAL_BLOCK_HASHES: &str = "canonical_block_hashes";
7
8/// Block numbers column family: [`Vec<u8>`] => [`u8;_`]
9/// - [`Vec<u8>`] = `block_hash.encode_to_vec()`
10/// - [`u8;_`] = `block_number.to_le_bytes()`
11pub const BLOCK_NUMBERS: &str = "block_numbers";
12
13/// Block headers column family: [`Vec<u8>`] => [`Vec<u8>`]
14/// - [`Vec<u8>`] = `block_hash.encode_to_vec()`
15/// - [`Vec<u8>`] = `BlockHeaderRLP::from(block.header.clone()).bytes().clone()`
16pub const HEADERS: &str = "headers";
17
18/// Block bodies column family: [`Vec<u8>`] => [`Vec<u8>`]
19/// - [`Vec<u8>`] = `block_hash.encode_to_vec();`
20/// - [`Vec<u8>`] = `BlockBodyRLP::from(block.body.clone()).bytes().clone()`
21pub const BODIES: &str = "bodies";
22
23/// Account codes column family: [`Vec<u8>`] => [`Vec<u8>`]
24/// - [`Vec<u8>`] = `code_hash.as_bytes().to_vec()`
25/// - [`Vec<u8>`] = `AccountCodeRLP::from(code).bytes().clone()`
26pub const ACCOUNT_CODES: &str = "account_codes";
27
28/// Account code metadata column family: [`Vec<u8>`] => [`u8; 8`]
29/// - [`Vec<u8>`] = `code_hash.as_bytes().to_vec()`
30/// - [`u8; 8`] = `code_length.to_be_bytes()`
31pub const ACCOUNT_CODE_METADATA: &str = "account_code_metadata";
32
33/// Receipts column family (legacy, pre-v2): [`Vec<u8>`] => [`Vec<u8>`]
34/// Used only for migration reads (v1→v2). Not listed in `TABLES`, so
35/// `drop_obsolete_cfs()` removes it right after migration completes
36/// (same startup).
37pub const RECEIPTS: &str = "receipts";
38
39/// Receipts v2 column family: [`Vec<u8>`] => [`Vec<u8>`]
40/// - Key: `block_hash (32B) || index (8B big-endian u64)` — fixed-width raw key
41///   enabling cursor-based prefix iteration by block hash.
42/// - Value: `receipt.encode_storage()` (internal storage codec; NOT the
43///   wire/consensus format — byte-identical to `encode_to_vec()` for
44///   non-frame receipts, full-fidelity layout for frame receipts)
45pub const RECEIPTS_V2: &str = "receipts_v2";
46
47/// Transaction locations column family: [`Vec<u8>`] => [`Vec<u8>`]
48/// - Key: `transaction_hash.as_bytes()` (32 bytes)
49/// - Value: `Vec<(block_number, block_hash, index)>.encode_to_vec()`
50///
51/// The value is a list because, in the rare case of a reorg, the same
52/// transaction may appear in multiple blocks. Readers must filter by the
53/// canonical chain to pick the right `(block_number, block_hash, index)`.
54pub const TRANSACTION_LOCATIONS: &str = "transaction_locations";
55
56/// Chain data column family: [`Vec<u8>`] => [`Vec<u8>`]
57/// - [`Vec<u8>`] = `chain_data_key(ChainDataIndex::ChainConfig)`
58/// - [`Vec<u8>`] = `serde_json::to_string(chain_config)`
59pub const CHAIN_DATA: &str = "chain_data";
60
61/// Snap state column family: [`Vec<u8>`] => [`Vec<u8>`]
62/// - [`Vec<u8>`] = `snap_state_key(SnapStateIndex::HeaderDownloadCheckpoint)`
63/// - [`Vec<u8>`] = `block_hash.encode_to_vec()`
64pub const SNAP_STATE: &str = "snap_state";
65
66/// Account State trie nodes column family: [`Nibbles`] => [`Vec<u8>`]
67/// - [`Nibbles`] = `node_hash.as_ref()`
68/// - [`Vec<u8>`] = `node_data`
69pub const ACCOUNT_TRIE_NODES: &str = "account_trie_nodes";
70
71/// Storage trie nodes column family: [`Nibbles`] => [`Vec<u8>`]
72/// - [`Nibbles`] = `node_hash.as_ref()`
73/// - [`Vec<u8>`] = `node_data`
74pub const STORAGE_TRIE_NODES: &str = "storage_trie_nodes";
75
76/// Pending blocks column family: [`Vec<u8>`] => [`Vec<u8>`]
77/// - [`Vec<u8>`] = `BlockHashRLP::from(block.hash()).bytes().clone()`
78/// - [`Vec<u8>`] = `BlockRLP::from(block).bytes().clone()`
79pub const PENDING_BLOCKS: &str = "pending_blocks";
80
81/// Invalid ancestors column family: [`Vec<u8>`] => [`Vec<u8>`]
82/// - [`Vec<u8>`] = `BlockHashRLP::from(bad_block).bytes().clone()`
83/// - [`Vec<u8>`] = `BlockHashRLP::from(latest_valid).bytes().clone()`
84pub const INVALID_CHAINS: &str = "invalid_ancestors";
85
86/// Block headers downloaded during fullsync column family: [`u8;_`] => [`Vec<u8>`]
87/// - [`u8;_`] = `block_number.to_le_bytes()`
88/// - [`Vec<u8>`] = `BlockHeaderRLP::from(block.header.clone()).bytes().clone()`
89pub const FULLSYNC_HEADERS: &str = "fullsync_headers";
90
91/// Account sate flat key-value store: [`Nibbles`] => [`Vec<u8>`]
92/// - [`Nibbles`] = `node_hash.as_ref()`
93/// - [`Vec<u8>`] = `node_data`
94pub const ACCOUNT_FLATKEYVALUE: &str = "account_flatkeyvalue";
95
96/// Storage slots key-value store: [`Nibbles`] => [`Vec<u8>`]
97/// - [`Nibbles`] = `node_hash.as_ref()`
98/// - [`Vec<u8>`] = `node_data`
99pub const STORAGE_FLATKEYVALUE: &str = "storage_flatkeyvalue";
100
101pub const MISC_VALUES: &str = "misc_values";
102
103/// State-history journal column family: [`u8; 8`] => [`Vec<u8>`]
104/// - [`u8; 8`] = `block_number.to_be_bytes()` (big-endian so lex order == numeric order)
105/// - [`Vec<u8>`] = `JournalEntry::encode()`
106///
107/// Stores one reverse-diff entry per committed block that is not yet final, enabling
108/// reorgs deeper than the in-memory `TrieLayerCache`. Pruned at finality.
109pub const STATE_HISTORY: &str = "state_history";
110
111/// Execution witnesses column family: [`Vec<u8>`] => [`Vec<u8>`]
112/// - [`Vec<u8>`] = Composite key
113///    ```rust,no_run
114///     // let mut composite_key = Vec::with_capacity(8 + 32);
115///     // composite_key.extend_from_slice(&block_number.to_be_bytes());
116///     // composite_key.extend_from_slice(block_hash.as_bytes());
117///    ```
118/// - [`Vec<u8>`] = `serde_json::to_vec(&witness)`
119pub const EXECUTION_WITNESSES: &str = "execution_witnesses";
120
121/// Block access lists column family: [`Vec<u8>`] => [`Vec<u8>`]
122/// - [`Vec<u8>`] = `block_hash.as_bytes().to_vec()`
123/// - [`Vec<u8>`] = RLP-encoded `BlockAccessList`
124pub const BLOCK_ACCESS_LISTS: &str = "block_access_lists";
125
126/// Bad blocks column family: single-keyed list of the most recent bad blocks
127/// seen by the client, served by `debug_getBadBlocks`.
128/// - [`Vec<u8>`] = [`BAD_BLOCKS_KEY`]
129/// - [`Vec<u8>`] = RLP-encoded `Vec<Block>` (sorted by descending block number)
130pub const BAD_BLOCKS: &str = "bad_blocks";
131
132pub const TABLES: [&str; 22] = [
133    CHAIN_DATA,
134    ACCOUNT_CODES,
135    ACCOUNT_CODE_METADATA,
136    BODIES,
137    BLOCK_NUMBERS,
138    CANONICAL_BLOCK_HASHES,
139    HEADERS,
140    PENDING_BLOCKS,
141    TRANSACTION_LOCATIONS,
142    RECEIPTS_V2,
143    SNAP_STATE,
144    INVALID_CHAINS,
145    ACCOUNT_TRIE_NODES,
146    STORAGE_TRIE_NODES,
147    FULLSYNC_HEADERS,
148    ACCOUNT_FLATKEYVALUE,
149    STORAGE_FLATKEYVALUE,
150    MISC_VALUES,
151    EXECUTION_WITNESSES,
152    BLOCK_ACCESS_LISTS,
153    STATE_HISTORY,
154    BAD_BLOCKS,
155];