Skip to content

Conversation

@MegaRedHand
Copy link
Collaborator

@MegaRedHand MegaRedHand commented Nov 19, 2025

This PR adds handling for a specific edge case in the parallel merkleization implementation added in #5377

Closes #5387

@github-actions
Copy link

github-actions bot commented Nov 19, 2025

Lines of code report

Total lines added: 62
Total lines removed: 0
Total lines changed: 62

Detailed view
+----------------------------------------+-------+------+
| File                                   | Lines | Diff |
+----------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs | 1578  | +62  |
+----------------------------------------+-------+------+

@github-actions
Copy link

Benchmark for 1c64f8b

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.5±2.95ms 31.1±2.34ms +1.97%
Trie/cita-trie insert 1k 2.8±0.09ms 2.9±0.17ms +3.57%
Trie/ethrex-trie insert 10k 25.9±1.23ms 28.0±1.11ms +8.11%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.01ms 0.00%

Base automatically changed from perf/parallel_merkleization_topdown to main November 19, 2025 20:23
@MegaRedHand MegaRedHand force-pushed the handle-parallelization-edge-case branch from 80c8ae9 to 537f761 Compare November 19, 2025 20:30
@github-actions
Copy link

Benchmark for 2793c76

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.6±0.89ms 28.1±1.23ms +1.81%
Trie/cita-trie insert 1k 2.8±0.03ms 2.9±0.15ms +3.57%
Trie/ethrex-trie insert 10k 24.6±0.55ms 25.1±0.94ms +2.03%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.01ms 0.00%

@MegaRedHand MegaRedHand marked this pull request as ready for review November 19, 2025 20:58
@MegaRedHand MegaRedHand requested a review from a team as a code owner November 19, 2025 20:58
Copilot AI review requested due to automatic review settings November 19, 2025 20:58
@ethrex-project-sync ethrex-project-sync bot moved this to In Review in ethrex_l1 Nov 19, 2025
@MegaRedHand MegaRedHand marked this pull request as draft November 19, 2025 20:59
@ethrex-project-sync ethrex-project-sync bot moved this from In Review to In Progress in ethrex_l1 Nov 19, 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 handles an edge case in parallel merkleization where the state trie root becomes a branch node with fewer than 2 children after merkleization. Previously, this scenario was not supported (marked as TODO). The PR refactors the branch collapsing logic into a reusable function and implements proper handling for branch nodes with 0 or 1 children.

Key changes:

  • Extracted branch collapse logic into a new public collapse_branch function
  • Added handling for edge cases where the root branch has 0 or 1 children after parallel merkleization
  • Properly handles empty trie state when no children remain

Reviewed Changes

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

File Description
crates/common/trie/node/branch.rs Refactored branch collapse logic into a reusable collapse_branch function
crates/common/trie/node.rs Exported the new collapse_branch function from the branch module
crates/blockchain/blockchain.rs Implemented edge case handling for root branches with 0 or 1 children in parallel merkleization

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

@MegaRedHand MegaRedHand marked this pull request as ready for review November 19, 2025 21:40
@ethrex-project-sync ethrex-project-sync bot moved this from In Progress to In Review in ethrex_l1 Nov 19, 2025
@github-actions
Copy link

Benchmark for cb1eadf

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.3±2.10ms 31.1±1.96ms +2.64%
Trie/cita-trie insert 1k 2.8±0.01ms 2.9±0.21ms +3.57%
Trie/ethrex-trie insert 10k 26.2±1.27ms 27.2±1.37ms +3.82%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.02ms 0.00%

@github-actions
Copy link

Benchmark for 58a51e3

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.7±1.09ms 28.3±0.75ms -1.39%
Trie/cita-trie insert 1k 2.8±0.03ms 2.8±0.26ms 0.00%
Trie/ethrex-trie insert 10k 25.4±0.94ms 25.1±0.54ms -1.18%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.04ms 0.00%

@github-actions
Copy link

Benchmark for 7b67329

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.4±0.40ms 27.7±0.52ms +1.09%
Trie/cita-trie insert 1k 2.8±0.02ms 2.9±0.17ms +3.57%
Trie/ethrex-trie insert 10k 24.6±0.45ms 24.8±1.19ms +0.81%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.04ms 0.00%

@github-actions
Copy link

Benchmark for 0859652

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.8±1.41ms 27.2±1.53ms -11.69%
Trie/cita-trie insert 1k 2.7±0.01ms 2.8±0.10ms +3.70%
Trie/ethrex-trie insert 10k 27.9±0.65ms 27.9±1.08ms 0.00%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.04ms 0.00%

@github-actions
Copy link

Benchmark for 5a7e7b0

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.5±0.45ms 27.9±1.08ms +1.45%
Trie/cita-trie insert 1k 2.8±0.01ms 2.8±0.09ms 0.00%
Trie/ethrex-trie insert 10k 24.5±0.41ms 24.6±0.36ms +0.41%
Trie/ethrex-trie insert 1k 2.2±0.06ms 2.2±0.01ms 0.00%

@github-actions
Copy link

Benchmark for 15815b9

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.6±2.45ms 28.8±1.45ms -5.88%
Trie/cita-trie insert 1k 2.9±0.03ms 2.9±0.20ms 0.00%
Trie/ethrex-trie insert 10k 25.7±1.23ms 26.3±1.27ms +2.33%
Trie/ethrex-trie insert 1k 2.2±0.04ms 2.2±0.03ms 0.00%

@github-actions
Copy link

Benchmark for c9f4b34

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.2±1.63ms 30.9±1.96ms +2.32%
Trie/cita-trie insert 1k 2.9±0.06ms 2.9±0.16ms 0.00%
Trie/ethrex-trie insert 10k 26.0±1.06ms 26.1±1.18ms +0.38%
Trie/ethrex-trie insert 1k 2.2±0.03ms 2.2±0.02ms 0.00%

@github-actions
Copy link

Benchmark for 8980a3b

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 31.7±2.57ms 35.5±1.33ms +11.99%
Trie/cita-trie insert 1k 2.8±0.02ms 2.9±0.07ms +3.57%
Trie/ethrex-trie insert 10k 25.9±1.11ms 28.9±0.59ms +11.58%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.04ms 0.00%

@github-actions
Copy link

Benchmark for cdb5468

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 29.9±1.51ms 33.1±2.30ms +10.70%
Trie/cita-trie insert 1k 2.8±0.02ms 2.8±0.10ms 0.00%
Trie/ethrex-trie insert 10k 25.1±0.80ms 26.2±1.12ms +4.38%
Trie/ethrex-trie insert 1k 2.2±0.02ms 2.1±0.01ms -4.55%

@github-actions
Copy link

Benchmark for 7b48096

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.0±1.80ms 34.0±1.95ms -8.11%
Trie/cita-trie insert 1k 2.7±0.06ms 2.8±0.16ms +3.70%
Trie/ethrex-trie insert 10k 29.0±0.92ms 28.4±0.73ms -2.07%
Trie/ethrex-trie insert 1k 2.1±0.01ms 2.2±0.01ms +4.76%

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


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

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Benchmark for b272ca8

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 27.8±0.57ms 27.6±0.50ms -0.72%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.10ms 0.00%
Trie/ethrex-trie insert 10k 24.4±0.58ms 24.4±0.37ms 0.00%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.02ms 0.00%

@iovoid iovoid added this pull request to the merge queue Dec 2, 2025
Merged via the queue into main with commit 57c98c8 Dec 2, 2025
45 checks passed
@iovoid iovoid deleted the handle-parallelization-edge-case branch December 2, 2025 14:17
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Dec 2, 2025
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.

Support branch -> leaf/extension edge-case in parallel merkleization

5 participants