Skip to content

Commit e14ec60

Browse files
authored
move flashbots/eth-sparse-mpt to a workspace crate (#248)
## 📝 Summary Move all the code from flashbots/eth-sparse-mpt to this repo to make reth / alloy upgrades easier. <!--- A general summary of your changes --> closes #210 ## 💡 Motivation and Context eth-sparse-mpt heavily depends on reth and alloy and this will make updates of the rbuilder dependencies easier. --- ## ✅ I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [x] Added tests (if applicable)
1 parent 0ced7b0 commit e14ec60

File tree

25 files changed

+81085
-20
lines changed

25 files changed

+81085
-20
lines changed

Cargo.lock

Lines changed: 98 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ members = [
33
"crates/rbuilder",
44
"crates/reth-rbuilder",
55
"crates/rbuilder/src/test_utils",
6-
"crates/rbuilder/src/telemetry/metrics_macros"
6+
"crates/rbuilder/src/telemetry/metrics_macros",
7+
"crates/eth-sparse-mpt",
78
]
89
resolver = "2"
910

@@ -43,6 +44,8 @@ reth-provider = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6", f
4344
reth-chainspec = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
4445
reth-evm = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
4546
reth-evm-ethereum = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
47+
reth-execution-errors = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
48+
reth-trie-db = { git = "https://github.com/paradigmxyz/reth", tag = "v1.0.6" }
4649

4750
# version is copied from reth "v1.0.6" dependencies
4851
revm = { version = "14.0.0", features = [
@@ -80,6 +83,7 @@ alloy-rpc-types-engine = { version = "0.3.0", features = [
8083
] }
8184
alloy-rpc-types-eth = { version = "0.3.0" }
8285
alloy-signer-local = { version = "0.3.0" }
86+
alloy-trie = { version = "0.5.0" }
8387

8488
clap = { version = "4.4.3" }
8589
eyre = { version = "0.6.8" }
@@ -89,3 +93,5 @@ tokio = "1.38.0"
8993
tokio-util = "0.7.11"
9094
tracing = "0.1.37"
9195

96+
97+
eth-sparse-mpt = { path = "crates/eth-sparse-mpt" }

crates/eth-sparse-mpt/Cargo.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[package]
2+
name = "eth-sparse-mpt"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
thiserror = "1.0.61"
8+
serde = { version = "1.0.203", features = ["derive"] }
9+
serde_json = "1.0.117"
10+
serde_with = "3.9.0"
11+
rustc-hash = "2.0.0"
12+
rayon = "1.10.0"
13+
smallvec = "1.13.2"
14+
15+
# reth
16+
reth-db-api.workspace = true
17+
reth-errors.workspace = true
18+
reth-execution-errors.workspace = true
19+
reth-trie.workspace = true
20+
reth-trie-db.workspace = true
21+
reth-provider.workspace = true
22+
23+
# revm
24+
revm.workspace = true
25+
revm-primitives.workspace = true
26+
27+
# alloy
28+
alloy-primitives.workspace = true
29+
alloy-rlp.workspace = true
30+
alloy-trie.workspace = true
31+
32+
# test only dependencies but included here to be accessible from benches/
33+
hash-db = "0.15.2"
34+
triehash = "0.8.4"
35+
36+
[dev-dependencies]
37+
criterion = { version = "0.4", features = ["html_reports"] }
38+
eyre = "0.6.12"
39+
rand = { version = "0.8.5", features = ["small_rng"] }
40+
proptest = "1.5.0"
41+
42+
[[bench]]
43+
name = "trie_insert_bench"
44+
harness = false
45+
46+
[[bench]]
47+
name = "trie_nodes_benches"
48+
harness = false
49+

crates/eth-sparse-mpt/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This library is useful when you need to calculate Ethereum root hash many times on top of the same parent block using reth database.
2+
3+
To use this, for each parent block:
4+
* create `SparseTrieSharedCache`
5+
* call `calculate_root_hash_with_sparse_trie` with the given cache, reth db view and execution outcome.
6+
7+
8+
### Speedup example.
9+
10+
* block 20821340
11+
* machine with 64 cores, Samsung 980Pro SSD
12+
13+
We calculate root hash of some specific blocks in a loop using the same changes.
14+
This implemenation caches only disk access, all storage and main trie hashes are calculated fully on each iteration.
15+
16+
```
17+
reth parallel root hash:
18+
19+
first iteraton : 220 ms
20+
next iterations: 140 ms (median, stable)
21+
22+
eth-sparse-mpt:
23+
24+
first iteraton : 225 ms
25+
next iterations: 5.1 ms (median, stable)
26+
```

0 commit comments

Comments
 (0)