Skip to content

Conversation

@iovoid
Copy link
Contributor

@iovoid iovoid commented Oct 22, 2025

Warning

This changes the format of nodes in the DB. You will need to re-sync your node.

Motivation

Currently, we have two ways of encoding a node: by specifying the node type (encode_to_vec, used for storing) and by letting the decoder infer it (encode_raw, used for hashing).

This causes confusion and prevents from making use of the RLP's API ability to decode onto an existing buffer.

Also by unifying the formats used for storing and hashing we can avoid encoding the same node twice.

Description

Unifies RLP encodings used for database and hashing.

Helps with #4956

@github-actions github-actions bot added the L1 Ethereum client label Oct 22, 2025
@github-actions
Copy link

github-actions bot commented Oct 22, 2025

Lines of code report

Total lines added: 2
Total lines removed: 112
Total lines changed: 114

Detailed view
+---------------------------------------------+-------+------+
| File                                        | Lines | Diff |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/node.rs           | 183   | -66  |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/node/branch.rs    | 559   | -15  |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/node/extension.rs | 476   | -6   |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/node/leaf.rs      | 259   | -7   |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/rlp.rs            | 104   | -18  |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/trie.rs           | 955   | +1   |
+---------------------------------------------+-------+------+
| ethrex/crates/common/trie/verify_range.rs   | 564   | +1   |
+---------------------------------------------+-------+------+

@github-actions
Copy link

Benchmark for 92d3498

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.3±1.75ms 37.8±1.39ms +7.08%
Trie/cita-trie insert 1k 3.5±0.02ms 3.6±0.14ms +2.86%
Trie/ethrex-trie insert 10k 70.8±1.76ms 61.1±1.03ms -13.70%
Trie/ethrex-trie insert 1k 8.5±0.06ms 7.1±0.03ms -16.47%

@github-actions
Copy link

Benchmark for 496cefb

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.3±1.50ms 36.6±1.40ms +0.83%
Trie/cita-trie insert 1k 3.6±0.01ms 3.6±0.21ms 0.00%
Trie/ethrex-trie insert 10k 67.5±1.18ms 58.1±1.08ms -13.93%
Trie/ethrex-trie insert 1k 8.5±0.03ms 7.1±0.03ms -16.47%

@iovoid iovoid changed the title refactor(l1): unify trie node encoding refactor(l1)!: unify trie node encoding Oct 23, 2025
@iovoid iovoid marked this pull request as ready for review October 23, 2025 14:30
@iovoid iovoid requested a review from a team as a code owner October 23, 2025 14:30
@github-actions github-actions bot removed the L1 Ethereum client label Oct 23, 2025
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Oct 23, 2025
@github-actions
Copy link

Benchmark for 400bea5

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 33.4±2.81ms 36.1±3.10ms +8.08%
Trie/cita-trie insert 1k 3.6±0.04ms 3.7±0.30ms +2.78%
Trie/ethrex-trie insert 10k 71.8±1.84ms 51.3±2.86ms -28.55%
Trie/ethrex-trie insert 1k 8.6±0.12ms 6.4±0.04ms -25.58%

Copy link
Collaborator

@MegaRedHand MegaRedHand left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link

Benchmark for 6c048b7

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.4±1.37ms 35.3±2.85ms -0.28%
Trie/cita-trie insert 1k 3.6±0.03ms 3.6±0.17ms 0.00%
Trie/ethrex-trie insert 10k 66.1±0.47ms 48.2±0.58ms -27.08%
Trie/ethrex-trie insert 1k 8.4±0.05ms 6.3±0.03ms -25.00%

@github-actions
Copy link

Benchmark for 315eb52

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.7±3.04ms 34.7±2.72ms -5.45%
Trie/cita-trie insert 1k 3.5±0.02ms 3.7±0.22ms +5.71%
Trie/ethrex-trie insert 10k 68.8±2.72ms 58.0±4.17ms -15.70%
Trie/ethrex-trie insert 1k 8.5±0.16ms 6.3±0.03ms -25.88%

@jrchatruc jrchatruc enabled auto-merge October 23, 2025 18:42
@jrchatruc jrchatruc disabled auto-merge October 23, 2025 18:43
@jrchatruc jrchatruc enabled auto-merge October 23, 2025 18:47
@jrchatruc jrchatruc added this pull request to the merge queue Oct 23, 2025
Merged via the queue into main with commit 3e9705b Oct 23, 2025
29 checks passed
@jrchatruc jrchatruc deleted the rlp_unify branch October 23, 2025 19:20
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants