Skip to content

Conversation

@JereSalo
Copy link
Contributor

@JereSalo JereSalo commented Nov 5, 2025

Motivation

  • Make necessary changes in order for ethrex-replay to work fine (we make use of these things there)

Description

  • Added a method to InMemoryTrieDB to use it in ethrex-replay

@JereSalo JereSalo self-assigned this Nov 5, 2025
@github-actions github-actions bot added the L1 Ethereum client label Nov 5, 2025
@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Lines of code report

Total lines added: 3
Total lines removed: 0
Total lines changed: 3

Detailed view
+---------------------------------+-------+------+
| File                            | Lines | Diff |
+---------------------------------+-------+------+
| ethrex/crates/common/trie/db.rs | 92    | +3   |
+---------------------------------+-------+------+

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Benchmark for bc435bb

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.9±0.87ms 33.5±0.82ms +8.41%
Trie/cita-trie insert 1k 2.8±0.02ms 2.8±0.07ms 0.00%
Trie/ethrex-trie insert 10k 31.2±1.12ms 31.0±1.47ms -0.64%
Trie/ethrex-trie insert 1k 2.3±0.03ms 2.3±0.03ms 0.00%

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Benchmark for 1b3c4fd

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.4±1.76ms 37.5±1.70ms +0.27%
Trie/cita-trie insert 1k 3.6±0.02ms 3.6±0.20ms 0.00%
Trie/ethrex-trie insert 10k 32.2±0.83ms 32.0±0.86ms -0.62%
Trie/ethrex-trie insert 1k 2.8±0.01ms 2.8±0.01ms 0.00%

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Benchmark for dc5c8e1

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 34.5±0.33ms 34.6±0.18ms +0.29%
Trie/cita-trie insert 1k 3.6±0.01ms 3.6±0.02ms 0.00%
Trie/ethrex-trie insert 10k 30.5±0.31ms 30.5±0.46ms 0.00%
Trie/ethrex-trie insert 1k 2.8±0.05ms 2.9±0.18ms +3.57%

@github-actions
Copy link

github-actions bot commented Nov 5, 2025

Benchmark for ac0e238

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 29.4±2.63ms 37.2±2.25ms +26.53%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.03ms 0.00%
Trie/ethrex-trie insert 10k 31.3±1.32ms 30.7±0.91ms -1.92%
Trie/ethrex-trie insert 1k 2.3±0.05ms 2.3±0.02ms 0.00%

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchmark for 35ca949

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 31.9±2.62ms 29.8±2.04ms -6.58%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.14ms 0.00%
Trie/ethrex-trie insert 10k 27.7±1.72ms 27.7±1.68ms 0.00%
Trie/ethrex-trie insert 1k 2.2±0.05ms 2.3±0.02ms +4.55%

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchmark for 9828dba

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.4±0.18ms 27.5±0.13ms +0.36%
Trie/cita-trie insert 1k 2.8±0.01ms 2.8±0.01ms 0.00%
Trie/ethrex-trie insert 10k 25.2±0.39ms 25.3±1.08ms +0.40%
Trie/ethrex-trie insert 1k 2.2±0.03ms 2.2±0.01ms 0.00%

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchmark for 92f657c

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.5±0.98ms 37.5±1.38ms +2.74%
Trie/cita-trie insert 1k 2.9±0.02ms 3.1±0.15ms +6.90%
Trie/ethrex-trie insert 10k 31.1±2.46ms 30.7±0.78ms -1.29%
Trie/ethrex-trie insert 1k 2.3±0.01ms 2.4±0.02ms +4.35%

@JereSalo JereSalo changed the title fix(l1): fix replay after path-based fix(l1): implement put_batch for TrieWrapper Nov 6, 2025
@JereSalo JereSalo marked this pull request as ready for review November 6, 2025 16:26
@JereSalo JereSalo requested a review from a team as a code owner November 6, 2025 16:26
Copilot AI review requested due to automatic review settings November 6, 2025 16:26
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Nov 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the trie cache synchronization mechanism to use RwLock instead of a Read-Copy-Update (RCU) pattern with Mutex. The key motivation is to improve concurrency by allowing multiple readers while maintaining write safety. Additionally, it implements the previously unimplemented put_batch method in TrieWrapper.

Key changes:

  • Replaced Arc<Mutex<Arc<TrieLayerCache>>> with Arc<RwLock<TrieLayerCache>> to eliminate the double-Arc RCU pattern
  • Implemented put_batch functionality in TrieWrapper with proper state root management
  • Added a new inner() method to InMemoryTrieDB for exposing the internal NodeMap

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/storage/trie_db/layering.rs Wrapped TrieWrapper fields in RwLock and implemented put_batch with state root computation and prefix application
crates/storage/store_db/rocksdb.rs Refactored trie cache from RCU pattern to direct RwLock usage, simplified layer management code
crates/storage/store_db/in_memory.rs Updated in-memory store to use RwLock for trie cache consistency with rocksdb implementation
crates/common/trie/db.rs Added inner() accessor method to InMemoryTrieDB

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JereSalo
Copy link
Contributor Author

JereSalo commented Nov 6, 2025

Maybe we don't want this, so I will address Copilot comments after we decide if we actually want this or not. Otherwise we may have to solve it in a different way.

Edit: yep, I made a mistake, we didn't want this and it wasn't even necessary

@JereSalo JereSalo changed the title fix(l1): implement put_batch for TrieWrapper fix(l1): make function inner for InMemoryTrieDB Nov 6, 2025
@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchmark for d28953e

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.2±0.77ms 28.9±0.55ms +2.48%
Trie/cita-trie insert 1k 2.9±0.06ms 2.9±0.01ms 0.00%
Trie/ethrex-trie insert 10k 25.9±0.80ms 25.8±0.56ms -0.39%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.3±0.03ms +4.55%

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

Benchmark for 4fa4235

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.1±1.45ms 29.2±1.36ms -21.29%
Trie/cita-trie insert 1k 2.8±0.01ms 2.8±0.06ms 0.00%
Trie/ethrex-trie insert 10k 30.3±1.17ms 29.6±1.22ms -2.31%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.03ms 0.00%

Copy link
Contributor

@avilagaston9 avilagaston9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it’s better to clarify in the comments that we need these methods for ethrex-replay

@JereSalo
Copy link
Contributor Author

JereSalo commented Nov 7, 2025

Maybe it’s better to clarify in the comments that we need these methods for ethrex-replay

a20302b

@github-actions
Copy link

github-actions bot commented Nov 7, 2025

Benchmark for 78dfcaf

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.8±0.33ms 27.6±0.27ms -0.72%
Trie/cita-trie insert 1k 2.9±0.04ms 3.0±0.20ms +3.45%
Trie/ethrex-trie insert 10k 25.2±0.33ms 25.5±0.62ms +1.19%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.3±0.06ms +4.55%

@ilitteri ilitteri added this pull request to the merge queue Nov 7, 2025
Merged via the queue into main with commit f0922a0 Nov 7, 2025
39 checks passed
@ilitteri ilitteri deleted the try_fix_replay_path_based branch November 7, 2025 16:51
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Nov 7, 2025
xqft pushed a commit that referenced this pull request Nov 11, 2025
**Motivation**

<!-- Why does this pull request exist? What are its goals? -->
- Make necessary changes in order for ethrex-replay to work fine (we
make use of these things there)

**Description**

- Added a method to `InMemoryTrieDB` to use it in ethrex-replay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants