Skip to content

Commit fbc1fea

Browse files
mpauluccifkrause98
authored andcommitted
refactor(l1): cleanup storage crate. (#2049)
**Motivation** Prepare the ground to divide the store into multiple stores (state, history, etc) **Description** - Created `lib.rs` file that exposed the modules to the outside world. - Renamed `engines` to `store_db` to be more aligned with `trie_db` - Renamed `storage.rs` to `store.rs`
1 parent b0efb8d commit fbc1fea

File tree

9 files changed

+43
-39
lines changed

9 files changed

+43
-39
lines changed

crates/storage/store/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ hex-literal.workspace = true
3333
tempdir = "0.3.7"
3434

3535
[lib]
36-
path = "./storage.rs"
36+
path = "./lib.rs"

crates/storage/store/engines/api.rs renamed to crates/storage/store/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ethrex_common::types::{
66
};
77
use std::{fmt::Debug, panic::RefUnwindSafe};
88

9-
use crate::{error::StoreError, STATE_TRIE_SEGMENTS};
9+
use crate::{error::StoreError, store::STATE_TRIE_SEGMENTS};
1010
use ethrex_trie::{Nibbles, Trie};
1111

1212
pub trait StoreEngine: Debug + Send + Sync + RefUnwindSafe {

crates/storage/store/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mod api;
2+
3+
mod rlp;
4+
mod store;
5+
mod store_db;
6+
mod trie_db;
7+
mod utils;
8+
9+
pub mod error;
10+
pub use store::{
11+
hash_address, hash_key, AccountUpdate, EngineType, Store, MAX_SNAPSHOT_READS,
12+
STATE_TRIE_SEGMENTS,
13+
};

crates/storage/store/storage.rs renamed to crates/storage/store/store.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use self::engines::in_memory::Store as InMemoryStore;
1+
use crate::api::StoreEngine;
2+
use crate::error::StoreError;
3+
use crate::store_db::in_memory::Store as InMemoryStore;
24
#[cfg(feature = "libmdbx")]
3-
use self::engines::libmdbx::Store as LibmdbxStore;
4-
use self::error::StoreError;
5-
use bytes::Bytes;
6-
use engines::api::StoreEngine;
5+
use crate::store_db::libmdbx::Store as LibmdbxStore;
76
#[cfg(feature = "redb")]
8-
use engines::redb::RedBStore;
7+
use crate::store_db::redb::RedBStore;
8+
use bytes::Bytes;
9+
910
use ethereum_types::{Address, H256, U256};
1011
use ethrex_common::types::{
1112
code_hash, AccountInfo, AccountState, BlobsBundle, Block, BlockBody, BlockHash, BlockHeader,
@@ -22,11 +23,6 @@ use std::fmt::Debug;
2223
use std::sync::{Arc, Mutex};
2324
use tracing::info;
2425

25-
mod engines;
26-
pub mod error;
27-
mod rlp;
28-
mod trie_db;
29-
3026
/// Number of state trie segments to fetch concurrently during state sync
3127
pub const STATE_TRIE_SEGMENTS: usize = 2;
3228
// Maximum amount of reads from the snapshot in a single transaction to avoid performance hits due to long-living reads

crates/storage/store/engines/in_memory.rs renamed to crates/storage/store/store_db/in_memory.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use crate::{error::StoreError, MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
1+
use crate::{
2+
api::StoreEngine,
3+
error::StoreError,
4+
store::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS},
5+
};
26
use bytes::Bytes;
37
use ethereum_types::{H256, U256};
48
use ethrex_common::types::{
@@ -12,8 +16,6 @@ use std::{
1216
sync::{Arc, Mutex, MutexGuard},
1317
};
1418

15-
use super::api::StoreEngine;
16-
1719
pub type NodeMap = Arc<Mutex<HashMap<Vec<u8>, Vec<u8>>>>;
1820

1921
#[derive(Default, Clone)]

crates/storage/store/engines/libmdbx.rs renamed to crates/storage/store/store_db/libmdbx.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use super::api::StoreEngine;
2-
use super::utils::{ChainDataIndex, SnapStateIndex};
1+
use crate::api::StoreEngine;
32
use crate::error::StoreError;
43
use crate::rlp::{
54
AccountCodeHashRLP, AccountCodeRLP, AccountHashRLP, AccountStateRLP, BlockBodyRLP,
65
BlockHashRLP, BlockHeaderRLP, BlockRLP, BlockTotalDifficultyRLP, ReceiptRLP, Rlp,
76
TransactionHashRLP, TupleRLP,
87
};
8+
use crate::store::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
99
use crate::trie_db::libmdbx::LibmdbxTrieDB;
1010
use crate::trie_db::libmdbx_dupsort::LibmdbxDupsortTrieDB;
11-
use crate::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
11+
use crate::utils::{ChainDataIndex, SnapStateIndex};
1212
use anyhow::Result;
1313
use bytes::Bytes;
1414
use ethereum_types::{H256, U256};
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
pub mod api;
21
pub mod in_memory;
32
#[cfg(feature = "libmdbx")]
43
pub mod libmdbx;
54
#[cfg(feature = "redb")]
65
pub mod redb;
7-
mod utils;

crates/storage/store/engines/redb.rs renamed to crates/storage/store/store_db/redb.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
use std::{borrow::Borrow, panic::RefUnwindSafe, sync::Arc};
22

3-
use ethrex_common::types::{AccountState, BlockBody};
4-
use ethrex_common::{
5-
types::{BlobsBundle, Block, BlockHash, BlockHeader, BlockNumber, ChainConfig, Index, Receipt},
6-
H256, U256,
7-
};
8-
use ethrex_rlp::decode::RLPDecode;
9-
use ethrex_rlp::encode::RLPEncode;
10-
use ethrex_rlp::error::RLPDecodeError;
11-
use ethrex_trie::Nibbles;
12-
13-
use redb::{AccessGuard, Database, Key, MultimapTableDefinition, TableDefinition, TypeName, Value};
14-
153
use crate::rlp::{
164
AccountHashRLP, AccountStateRLP, BlockRLP, BlockTotalDifficultyRLP, Rlp, TransactionHashRLP,
175
};
18-
use crate::MAX_SNAPSHOT_READS;
6+
use crate::store::MAX_SNAPSHOT_READS;
7+
use crate::trie_db::{redb::RedBTrie, redb_multitable::RedBMultiTableTrieDB};
198
use crate::{
209
error::StoreError,
2110
rlp::{
2211
AccountCodeHashRLP, AccountCodeRLP, BlockBodyRLP, BlockHashRLP, BlockHeaderRLP, ReceiptRLP,
2312
TupleRLP,
2413
},
2514
};
26-
use crate::{
27-
trie_db::{redb::RedBTrie, redb_multitable::RedBMultiTableTrieDB},
28-
Trie,
15+
use ethrex_common::types::{AccountState, BlockBody};
16+
use ethrex_common::{
17+
types::{BlobsBundle, Block, BlockHash, BlockHeader, BlockNumber, ChainConfig, Index, Receipt},
18+
H256, U256,
2919
};
20+
use ethrex_rlp::decode::RLPDecode;
21+
use ethrex_rlp::encode::RLPEncode;
22+
use ethrex_rlp::error::RLPDecodeError;
23+
use ethrex_trie::{Nibbles, Trie};
24+
use redb::{AccessGuard, Database, Key, MultimapTableDefinition, TableDefinition, TypeName, Value};
3025

31-
use super::utils::SnapStateIndex;
32-
use super::{api::StoreEngine, utils::ChainDataIndex};
26+
use crate::utils::SnapStateIndex;
27+
use crate::{api::StoreEngine, utils::ChainDataIndex};
3328

3429
const STATE_TRIE_NODES_TABLE: TableDefinition<&[u8], &[u8]> =
3530
TableDefinition::new("StateTrieNodes");
File renamed without changes.

0 commit comments

Comments
 (0)