Skip to content

Commit

Permalink
feat(core): switch database to Redb (#1351)
Browse files Browse the repository at this point in the history
**Motivation**

<!-- Why does this pull request exist? What are its goals? -->

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #738
  • Loading branch information
jrchatruc authored Nov 29, 2024
1 parent 120eaab commit 93847ca
Show file tree
Hide file tree
Showing 24 changed files with 902 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ levm_ef_tests_summary_slack.txt
levm_ef_tests_summary_github.txt
levm_ef_tests_summary.txt

loc_report.md
loc_report_slack.txt
loc_report_github.txt
loc_report.json
ethrex.redb
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ethrex-l2 = { path = "./crates/l2" }
ethrex-prover = { path = "./crates/l2/prover" }

tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = "0.3.0"
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }

ethereum-types = { version = "0.14.1", features = ["serialize"] }
serde = { version = "1.0.203", features = ["derive"] }
Expand All @@ -62,6 +62,7 @@ jsonwebtoken = "9.3.0"
rand = "0.8.5"
cfg-if = "1.0.0"
reqwest = { version = "0.12.7", features = ["json"] }
redb = "2.2.0"
snap = "1.1.1"
k256 = { version = "0.13.3", features = ["ecdh"] }
secp256k1 = { version = "0.29", default-features = false, features = [
Expand Down
8 changes: 6 additions & 2 deletions cmd/ethrex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ethrex-blockchain.workspace = true
ethrex-rpc.workspace = true
ethrex-core.workspace = true
ethrex-net.workspace = true
ethrex-storage.workspace = true
ethrex-storage = { workspace = true, optional = true }
ethrex-vm.workspace = true
ethrex-rlp.workspace = true
ethrex-l2.workspace = true
Expand All @@ -28,6 +28,8 @@ anyhow = "1.0.86"
rand = "0.8.5"
local-ip-address = "0.6"
tokio-util.workspace = true
libmdbx = { workspace = true, optional = true }
redb = { workspace = true, optional = true }

cfg-if = "1.0.0"

Expand All @@ -38,7 +40,9 @@ name = "ethrex"
path = "./ethrex.rs"

[features]
default = []
default = ["dep:ethrex-storage", "libmdbx"]
dev = ["dep:ethrex-dev"]
libmdbx = ["dep:libmdbx", "ethrex-storage/libmdbx"]
redb = ["dep:redb", "ethrex-storage/redb"]
l2 = ["ethrex-vm/l2"]
levm = ["ethrex-vm/levm", "ethrex-blockchain/levm"]
10 changes: 9 additions & 1 deletion cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ async fn main() {
info!("snap-sync not available, defaulting to full-sync");
}

let store = Store::new(&data_dir, EngineType::Libmdbx).expect("Failed to create Store");
cfg_if::cfg_if! {
if #[cfg(feature = "redb")] {
let store = Store::new(&data_dir, EngineType::RedB).expect("Failed to create Store");
} else if #[cfg(feature = "libmdbx")] {
let store = Store::new(&data_dir, EngineType::Libmdbx).expect("Failed to create Store");
} else {
let store = Store::new(&data_dir, EngineType::InMemory).expect("Failed to create Store");
}
}

let genesis = read_genesis_file(genesis_file_path);
store
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ hex = "0.4.3"
path = "./blockchain.rs"

[features]
default = ["libmdbx", "c-kzg"]
default = ["c-kzg"]
libmdbx = [
"ethrex-core/libmdbx",
"ethrex-storage/default",
Expand Down
3 changes: 2 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ lazy_static.workspace = true
hex-literal.workspace = true

[features]
default = ["libmdbx", "c-kzg"]
default = ["c-kzg"]
libmdbx = ["ethrex-trie/libmdbx"]
redb = ["ethrex-trie/redb"]
c-kzg = ["dep:c-kzg"]

[lib]
Expand Down
8 changes: 7 additions & 1 deletion crates/storage/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ hex.workspace = true
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
libmdbx = { workspace = true, optional = true }
redb = { workspace = true, optional = true }

[features]
default = ["libmdbx"]
default = []
libmdbx = [
"dep:libmdbx",
"ethrex-trie/libmdbx",
"ethrex-core/libmdbx",
]
redb = [
"dep:redb",
"ethrex-trie/redb",
"ethrex-core/redb"
]

[dev-dependencies]
hex.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/storage/store/engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ pub mod api;
pub mod in_memory;
#[cfg(feature = "libmdbx")]
pub mod libmdbx;
#[cfg(feature = "redb")]
pub mod redb;
mod utils;
14 changes: 1 addition & 13 deletions crates/storage/store/engines/libmdbx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::api::StoreEngine;
use super::utils::ChainDataIndex;
use crate::error::StoreError;
use crate::rlp::{
AccountCodeHashRLP, AccountCodeRLP, BlockBodyRLP, BlockHashRLP, BlockHeaderRLP, BlockRLP,
Expand Down Expand Up @@ -559,19 +560,6 @@ impl From<AccountStorageValueBytes> for U256 {
}
}

/// Represents the key for each unique value of the chain data stored in the db
// (TODO: Remove this comment once full) Will store chain-specific data such as chain id and latest finalized/pending/safe block number
pub enum ChainDataIndex {
ChainConfig = 0,
EarliestBlockNumber = 1,
FinalizedBlockNumber = 2,
SafeBlockNumber = 3,
LatestBlockNumber = 4,
PendingBlockNumber = 5,
// TODO (#307): Remove TotalDifficulty.
LatestTotalDifficulty = 6,
}

impl Encodable for ChainDataIndex {
type Encoded = [u8; 4];

Expand Down
Loading

0 comments on commit 93847ca

Please sign in to comment.