Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b673159
wip: perf: move trie updates to background
Oppen Oct 21, 2025
624959c
almost building
Oppen Oct 21, 2025
fd10649
fixes
edg-l Oct 22, 2025
be1cbd1
Send continue message after db write
jrchatruc Oct 22, 2025
bf8dc61
revert btreemap
Oppen Oct 22, 2025
e518452
unconditionally notify about new diff layer
jrchatruc Oct 22, 2025
ef7a108
change trie update channel to have bound 0 instead of 1
jrchatruc Oct 22, 2025
0b5d535
Test sending ok afterwards
jrchatruc Oct 22, 2025
3e68692
fix
jrchatruc Oct 22, 2025
29bf987
fix id increment + disallow modify
Oppen Oct 22, 2025
e41963b
actually update last_id
Oppen Oct 22, 2025
6b3c8b9
Revert "fix"
Oppen Oct 22, 2025
49e47ee
Revert "Test sending ok afterwards"
Oppen Oct 22, 2025
d85c9fe
Merge branch 'main' into perf/bg_trie_update-edgar-v2
jrchatruc Oct 23, 2025
ab7c5a8
Update changelog
jrchatruc Oct 23, 2025
c905574
Update prover cargo lock files
jrchatruc Oct 23, 2025
693c94d
Remove unneeded spawned concurrency dependency
jrchatruc Oct 23, 2025
65cd9a7
Revert "Update prover cargo lock files"
jrchatruc Oct 23, 2025
ca26b76
Merge branch 'main' into perf/bg_trie_update-edgar-v2
jrchatruc Oct 23, 2025
b27b2aa
Fix tests
jrchatruc Oct 23, 2025
ff93aa9
clippy
jrchatruc Oct 23, 2025
3a89d6a
Merge branch 'main' into perf/bg_trie_update-edgar-v2
jrchatruc Oct 23, 2025
b080ea2
Add documentation for the background thread
jrchatruc Oct 23, 2025
28369f1
cargo fmt
jrchatruc Oct 23, 2025
d714943
remove needless scope
edg-l Oct 27, 2025
48f5b3a
add warnings, use collect
edg-l Oct 27, 2025
0122787
typo
edg-l Oct 27, 2025
32b6de2
use destructure
edg-l Oct 27, 2025
12c9621
typo
edg-l Oct 27, 2025
68e32a9
avoid lock
edg-l Oct 27, 2025
39dc217
merge conflicts
edg-l Oct 27, 2025
4441238
Make change in L2 to trigger CI L2 tests
jrchatruc Oct 27, 2025
5d39705
Revert "Make change in L2 to trigger CI L2 tests"
jrchatruc Oct 27, 2025
56db24c
Merge branch 'main' into perf/bg_trie_update-edgar-v2
jrchatruc Oct 27, 2025
f1d50bd
Merge branch 'main' into perf/bg_trie_update-edgar-v2
jrchatruc Oct 27, 2025
d4f74f2
Test l2 ci
jrchatruc Oct 27, 2025
a05a039
Revert "Test l2 ci"
jrchatruc Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Perf

### 2025-10-23

- Move trie updates post block execution to a background thread. [#4989](https://github.com/lambdaclass/ethrex/pull/4989).

### 2025-10-21

- Instead of lazy computation of blocklist, do greedy computation of allowlist and store the result, fetch it with the DB. [#4961](https://github.com/lambdaclass/ethrex/pull/4961)
Expand Down
3 changes: 2 additions & 1 deletion crates/networking/p2p/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ mod tests {
use ethrex_common::{BigEndianHash, H256, types::AccountState};
use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode};
use ethrex_storage::EngineType;
use ethrex_trie::EMPTY_TRIE_HASH;

use crate::rlpx::snap::AccountStateSlim;

Expand Down Expand Up @@ -996,7 +997,7 @@ mod tests {

// Create a store and load it up with the accounts
let store = Store::new("null", EngineType::InMemory).unwrap();
let mut state_trie = store.new_state_trie_for_test()?;
let mut state_trie = store.open_direct_state_trie(*EMPTY_TRIE_HASH)?;
for (address, account) in accounts {
let hashed_address = H256::from_str(address).unwrap().as_bytes().to_vec();
let account = AccountState::from(AccountStateSlim::decode(&account).unwrap());
Expand Down
6 changes: 3 additions & 3 deletions crates/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ mod tests {
})
.collect();
accounts.sort_by_key(|a| a.0);
let mut trie = store.open_state_trie(*EMPTY_TRIE_HASH).unwrap();
let mut trie = store.open_direct_state_trie(*EMPTY_TRIE_HASH).unwrap();
for (address, state) in &accounts {
trie.insert(address.0.to_vec(), state.encode_to_vec())
.unwrap();
Expand All @@ -1529,13 +1529,13 @@ mod tests {
.collect();
slots.sort_by_key(|a| a.0);
let mut trie = store
.open_storage_trie(address, *EMPTY_TRIE_HASH, *EMPTY_TRIE_HASH)
.open_direct_storage_trie(address, *EMPTY_TRIE_HASH)
.unwrap();
for (slot, value) in &slots {
trie.insert(slot.0.to_vec(), value.encode_to_vec()).unwrap();
}
let storage_root = trie.hash().unwrap();
let mut trie = store.open_state_trie(*EMPTY_TRIE_HASH).unwrap();
let mut trie = store.open_direct_state_trie(*EMPTY_TRIE_HASH).unwrap();
trie.insert(
address.0.to_vec(),
AccountState {
Expand Down
37 changes: 19 additions & 18 deletions crates/storage/store_db/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethrex_trie::{InMemoryTrieDB, Nibbles, Trie, db::NodeMap};
use std::{
collections::HashMap,
fmt::Debug,
sync::{Arc, Mutex, MutexGuard, RwLock},
sync::{Arc, Mutex, MutexGuard},
};

// NOTE: we use a different commit threshold than rocksdb since tests
Expand All @@ -38,7 +38,7 @@ pub struct StoreInner {
// Maps transaction hashes to their blocks (height+hash) and index within the blocks.
transaction_locations: HashMap<H256, Vec<(BlockNumber, BlockHash, Index)>>,
receipts: HashMap<BlockHash, HashMap<Index, Receipt>>,
trie_cache: Arc<RwLock<TrieLayerCache>>,
trie_cache: Arc<TrieLayerCache>,
// Contains account trie nodes
state_trie_nodes: NodeMap,
pending_blocks: HashMap<BlockHash, Block>,
Expand Down Expand Up @@ -91,10 +91,7 @@ impl StoreEngine for Store {

// Store trie updates
{
let mut trie = store
.trie_cache
.write()
.map_err(|_| StoreError::LockError)?;
let mut trie = TrieLayerCache::clone(&store.trie_cache);
let parent = update_batch
.blocks
.first()
Expand All @@ -115,21 +112,24 @@ impl StoreEngine for Store {
.header
.state_root;

let mut state_trie = store
.state_trie_nodes
.lock()
.map_err(|_| StoreError::LockError)?;

if let Some(root) = trie.get_commitable(pre_state_root, COMMIT_THRESHOLD) {
let nodes = trie.commit(root).unwrap_or_default();
for (key, value) in nodes {
if value.is_empty() {
state_trie.remove(&key);
} else {
state_trie.insert(key, value);
{
let mut state_trie = store
.state_trie_nodes
.lock()
.map_err(|_| StoreError::LockError)?;

if let Some(root) = trie.get_commitable(pre_state_root, COMMIT_THRESHOLD) {
let nodes = trie.commit(root).unwrap_or_default();
for (key, value) in nodes {
if value.is_empty() {
state_trie.remove(&key);
} else {
state_trie.insert(key, value);
}
}
}
}

let key_values = update_batch
.storage_updates
.into_iter()
Expand All @@ -141,6 +141,7 @@ impl StoreEngine for Store {
.chain(update_batch.account_updates)
.collect();
trie.put_batch(pre_state_root, last_state_root, key_values);
store.trie_cache = Arc::new(trie);
}

for block in update_batch.blocks {
Expand Down
Loading