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/// Execution witnesses column family: [`Vec<u8>`] => [`Vec<u8>`]
104/// - [`Vec<u8>`] = Composite key
105///    ```rust,no_run
106///     // let mut composite_key = Vec::with_capacity(8 + 32);
107///     // composite_key.extend_from_slice(&block_number.to_be_bytes());
108///     // composite_key.extend_from_slice(block_hash.as_bytes());
109///    ```
110/// - [`Vec<u8>`] = `serde_json::to_vec(&witness)`
111pub const EXECUTION_WITNESSES: &str = "execution_witnesses";
112
113/// Block access lists column family: [`Vec<u8>`] => [`Vec<u8>`]
114/// - [`Vec<u8>`] = `block_hash.as_bytes().to_vec()`
115/// - [`Vec<u8>`] = RLP-encoded `BlockAccessList`
116pub const BLOCK_ACCESS_LISTS: &str = "block_access_lists";
117
118/// Bad blocks column family: single-keyed list of the most recent bad blocks
119/// seen by the client, served by `debug_getBadBlocks`.
120/// - [`Vec<u8>`] = [`BAD_BLOCKS_KEY`]
121/// - [`Vec<u8>`] = RLP-encoded `Vec<Block>` (sorted by descending block number)
122pub const BAD_BLOCKS: &str = "bad_blocks";
123
124pub const TABLES: [&str; 21] = [
125    CHAIN_DATA,
126    ACCOUNT_CODES,
127    ACCOUNT_CODE_METADATA,
128    BODIES,
129    BLOCK_NUMBERS,
130    CANONICAL_BLOCK_HASHES,
131    HEADERS,
132    PENDING_BLOCKS,
133    TRANSACTION_LOCATIONS,
134    RECEIPTS_V2,
135    SNAP_STATE,
136    INVALID_CHAINS,
137    ACCOUNT_TRIE_NODES,
138    STORAGE_TRIE_NODES,
139    FULLSYNC_HEADERS,
140    ACCOUNT_FLATKEYVALUE,
141    STORAGE_FLATKEYVALUE,
142    MISC_VALUES,
143    EXECUTION_WITNESSES,
144    BLOCK_ACCESS_LISTS,
145    BAD_BLOCKS,
146];