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_to_vec()`
43pub const RECEIPTS_V2: &str = "receipts_v2";
44
45/// Transaction locations column family: [`Vec<u8>`] => [`Vec<u8>`]
46/// - Key: `transaction_hash.as_bytes()` (32 bytes)
47/// - Value: `Vec<(block_number, block_hash, index)>.encode_to_vec()`
48///
49/// The value is a list because, in the rare case of a reorg, the same
50/// transaction may appear in multiple blocks. Readers must filter by the
51/// canonical chain to pick the right `(block_number, block_hash, index)`.
52pub const TRANSACTION_LOCATIONS: &str = "transaction_locations";
53
54/// Chain data column family: [`Vec<u8>`] => [`Vec<u8>`]
55/// - [`Vec<u8>`] = `chain_data_key(ChainDataIndex::ChainConfig)`
56/// - [`Vec<u8>`] = `serde_json::to_string(chain_config)`
57pub const CHAIN_DATA: &str = "chain_data";
58
59/// Snap state column family: [`Vec<u8>`] => [`Vec<u8>`]
60/// - [`Vec<u8>`] = `snap_state_key(SnapStateIndex::HeaderDownloadCheckpoint)`
61/// - [`Vec<u8>`] = `block_hash.encode_to_vec()`
62pub const SNAP_STATE: &str = "snap_state";
63
64/// Account State trie nodes column family: [`Nibbles`] => [`Vec<u8>`]
65/// - [`Nibbles`] = `node_hash.as_ref()`
66/// - [`Vec<u8>`] = `node_data`
67pub const ACCOUNT_TRIE_NODES: &str = "account_trie_nodes";
68
69/// Storage trie nodes column family: [`Nibbles`] => [`Vec<u8>`]
70/// - [`Nibbles`] = `node_hash.as_ref()`
71/// - [`Vec<u8>`] = `node_data`
72pub const STORAGE_TRIE_NODES: &str = "storage_trie_nodes";
73
74/// Pending blocks column family: [`Vec<u8>`] => [`Vec<u8>`]
75/// - [`Vec<u8>`] = `BlockHashRLP::from(block.hash()).bytes().clone()`
76/// - [`Vec<u8>`] = `BlockRLP::from(block).bytes().clone()`
77pub const PENDING_BLOCKS: &str = "pending_blocks";
78
79/// Invalid ancestors column family: [`Vec<u8>`] => [`Vec<u8>`]
80/// - [`Vec<u8>`] = `BlockHashRLP::from(bad_block).bytes().clone()`
81/// - [`Vec<u8>`] = `BlockHashRLP::from(latest_valid).bytes().clone()`
82pub const INVALID_CHAINS: &str = "invalid_ancestors";
83
84/// Block headers downloaded during fullsync column family: [`u8;_`] => [`Vec<u8>`]
85/// - [`u8;_`] = `block_number.to_le_bytes()`
86/// - [`Vec<u8>`] = `BlockHeaderRLP::from(block.header.clone()).bytes().clone()`
87pub const FULLSYNC_HEADERS: &str = "fullsync_headers";
88
89/// Account sate flat key-value store: [`Nibbles`] => [`Vec<u8>`]
90/// - [`Nibbles`] = `node_hash.as_ref()`
91/// - [`Vec<u8>`] = `node_data`
92pub const ACCOUNT_FLATKEYVALUE: &str = "account_flatkeyvalue";
93
94/// Storage slots key-value store: [`Nibbles`] => [`Vec<u8>`]
95/// - [`Nibbles`] = `node_hash.as_ref()`
96/// - [`Vec<u8>`] = `node_data`
97pub const STORAGE_FLATKEYVALUE: &str = "storage_flatkeyvalue";
98
99pub const MISC_VALUES: &str = "misc_values";
100
101/// Execution witnesses column family: [`Vec<u8>`] => [`Vec<u8>`]
102/// - [`Vec<u8>`] = Composite key
103///    ```rust,no_run
104///     // let mut composite_key = Vec::with_capacity(8 + 32);
105///     // composite_key.extend_from_slice(&block_number.to_be_bytes());
106///     // composite_key.extend_from_slice(block_hash.as_bytes());
107///    ```
108/// - [`Vec<u8>`] = `serde_json::to_vec(&witness)`
109pub const EXECUTION_WITNESSES: &str = "execution_witnesses";
110
111/// Block access lists column family: [`Vec<u8>`] => [`Vec<u8>`]
112/// - [`Vec<u8>`] = `block_hash.as_bytes().to_vec()`
113/// - [`Vec<u8>`] = RLP-encoded `BlockAccessList`
114pub const BLOCK_ACCESS_LISTS: &str = "block_access_lists";
115
116pub const TABLES: [&str; 20] = [
117    CHAIN_DATA,
118    ACCOUNT_CODES,
119    ACCOUNT_CODE_METADATA,
120    BODIES,
121    BLOCK_NUMBERS,
122    CANONICAL_BLOCK_HASHES,
123    HEADERS,
124    PENDING_BLOCKS,
125    TRANSACTION_LOCATIONS,
126    RECEIPTS_V2,
127    SNAP_STATE,
128    INVALID_CHAINS,
129    ACCOUNT_TRIE_NODES,
130    STORAGE_TRIE_NODES,
131    FULLSYNC_HEADERS,
132    ACCOUNT_FLATKEYVALUE,
133    STORAGE_FLATKEYVALUE,
134    MISC_VALUES,
135    EXECUTION_WITNESSES,
136    BLOCK_ACCESS_LISTS,
137];