Skip to content

Commit

Permalink
refactor(l1): cleanup storage crate. (#2049)
Browse files Browse the repository at this point in the history
**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`
  • Loading branch information
mpaulucci authored Feb 21, 2025
1 parent 34fbff9 commit 51b7dcb
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion crates/storage/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ hex-literal.workspace = true
tempdir = "0.3.7"

[lib]
path = "./storage.rs"
path = "./lib.rs"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ethrex_common::types::{
};
use std::{fmt::Debug, panic::RefUnwindSafe};

use crate::{error::StoreError, STATE_TRIE_SEGMENTS};
use crate::{error::StoreError, store::STATE_TRIE_SEGMENTS};
use ethrex_trie::{Nibbles, Trie};

pub trait StoreEngine: Debug + Send + Sync + RefUnwindSafe {
Expand Down
13 changes: 13 additions & 0 deletions crates/storage/store/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod api;

mod rlp;
mod store;
mod store_db;
mod trie_db;
mod utils;

pub mod error;
pub use store::{
hash_address, hash_key, AccountUpdate, EngineType, Store, MAX_SNAPSHOT_READS,
STATE_TRIE_SEGMENTS,
};
18 changes: 7 additions & 11 deletions crates/storage/store/storage.rs → crates/storage/store/store.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use self::engines::in_memory::Store as InMemoryStore;
use crate::api::StoreEngine;
use crate::error::StoreError;
use crate::store_db::in_memory::Store as InMemoryStore;
#[cfg(feature = "libmdbx")]
use self::engines::libmdbx::Store as LibmdbxStore;
use self::error::StoreError;
use bytes::Bytes;
use engines::api::StoreEngine;
use crate::store_db::libmdbx::Store as LibmdbxStore;
#[cfg(feature = "redb")]
use engines::redb::RedBStore;
use crate::store_db::redb::RedBStore;
use bytes::Bytes;

use ethereum_types::{Address, H256, U256};
use ethrex_common::types::{
code_hash, AccountInfo, AccountState, BlobsBundle, Block, BlockBody, BlockHash, BlockHeader,
Expand All @@ -22,11 +23,6 @@ use std::fmt::Debug;
use std::sync::{Arc, Mutex};
use tracing::info;

mod engines;
pub mod error;
mod rlp;
mod trie_db;

/// Number of state trie segments to fetch concurrently during state sync
pub const STATE_TRIE_SEGMENTS: usize = 2;
// Maximum amount of reads from the snapshot in a single transaction to avoid performance hits due to long-living reads
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{error::StoreError, MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
use crate::{
api::StoreEngine,
error::StoreError,
store::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS},
};
use bytes::Bytes;
use ethereum_types::{H256, U256};
use ethrex_common::types::{
Expand All @@ -12,8 +16,6 @@ use std::{
sync::{Arc, Mutex, MutexGuard},
};

use super::api::StoreEngine;

pub type NodeMap = Arc<Mutex<HashMap<Vec<u8>, Vec<u8>>>>;

#[derive(Default, Clone)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::api::StoreEngine;
use super::utils::{ChainDataIndex, SnapStateIndex};
use crate::api::StoreEngine;
use crate::error::StoreError;
use crate::rlp::{
AccountCodeHashRLP, AccountCodeRLP, AccountHashRLP, AccountStateRLP, BlockBodyRLP,
BlockHashRLP, BlockHeaderRLP, BlockRLP, BlockTotalDifficultyRLP, ReceiptRLP, Rlp,
TransactionHashRLP, TupleRLP,
};
use crate::store::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
use crate::trie_db::libmdbx::LibmdbxTrieDB;
use crate::trie_db::libmdbx_dupsort::LibmdbxDupsortTrieDB;
use crate::{MAX_SNAPSHOT_READS, STATE_TRIE_SEGMENTS};
use crate::utils::{ChainDataIndex, SnapStateIndex};
use anyhow::Result;
use bytes::Bytes;
use ethereum_types::{H256, U256};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod api;
pub mod in_memory;
#[cfg(feature = "libmdbx")]
pub mod libmdbx;
#[cfg(feature = "redb")]
pub mod redb;
mod utils;
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
use std::{borrow::Borrow, panic::RefUnwindSafe, sync::Arc};

use ethrex_common::types::{AccountState, BlockBody};
use ethrex_common::{
types::{BlobsBundle, Block, BlockHash, BlockHeader, BlockNumber, ChainConfig, Index, Receipt},
H256, U256,
};
use ethrex_rlp::decode::RLPDecode;
use ethrex_rlp::encode::RLPEncode;
use ethrex_rlp::error::RLPDecodeError;
use ethrex_trie::Nibbles;

use redb::{AccessGuard, Database, Key, MultimapTableDefinition, TableDefinition, TypeName, Value};

use crate::rlp::{
AccountHashRLP, AccountStateRLP, BlockRLP, BlockTotalDifficultyRLP, Rlp, TransactionHashRLP,
};
use crate::MAX_SNAPSHOT_READS;
use crate::store::MAX_SNAPSHOT_READS;
use crate::trie_db::{redb::RedBTrie, redb_multitable::RedBMultiTableTrieDB};
use crate::{
error::StoreError,
rlp::{
AccountCodeHashRLP, AccountCodeRLP, BlockBodyRLP, BlockHashRLP, BlockHeaderRLP, ReceiptRLP,
TupleRLP,
},
};
use crate::{
trie_db::{redb::RedBTrie, redb_multitable::RedBMultiTableTrieDB},
Trie,
use ethrex_common::types::{AccountState, BlockBody};
use ethrex_common::{
types::{BlobsBundle, Block, BlockHash, BlockHeader, BlockNumber, ChainConfig, Index, Receipt},
H256, U256,
};
use ethrex_rlp::decode::RLPDecode;
use ethrex_rlp::encode::RLPEncode;
use ethrex_rlp::error::RLPDecodeError;
use ethrex_trie::{Nibbles, Trie};
use redb::{AccessGuard, Database, Key, MultimapTableDefinition, TableDefinition, TypeName, Value};

use super::utils::SnapStateIndex;
use super::{api::StoreEngine, utils::ChainDataIndex};
use crate::utils::SnapStateIndex;
use crate::{api::StoreEngine, utils::ChainDataIndex};

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

0 comments on commit 51b7dcb

Please sign in to comment.