Skip to content

refactor(l1): parallelize request_block_headers function #3650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ricomateo
Copy link
Contributor

@ricomateo ricomateo commented Jul 15, 2025

Motivation
The request_block_headers function is quite slow due to its sequential approach, since it queries block headers from one peer at a time, waiting for a response from one peer (it currently waits up to 15 seconds) before trying the next.
This makes the process very slow since some peers may return invalid data, or they may even not respond.

Description
This PR modifies the request_block_headers function to request the block headers to multiple peers in parallel instead of querying them sequentially. With this approach the node no longer waits for one peer to respond before querying the next one. Instead, all the peers are queried simultaneously, and the first valid response is returned, significantly speeding up the process.

Closes: None

@github-actions github-actions bot added the L1 Ethereum client label Jul 15, 2025
Copy link

github-actions bot commented Jul 15, 2025

Lines of code report

Total lines added: 264
Total lines removed: 40
Total lines changed: 304

Detailed view
+-------------------------------------------------+-------+------+
| File                                            | Lines | Diff |
+-------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/cli.rs                        | 455   | -4   |
+-------------------------------------------------+-------+------+
| ethrex/crates/l2/contracts/bin/deployer/main.rs | 624   | +3   |
+-------------------------------------------------+-------+------+
| ethrex/crates/l2/monitor/app.rs                 | 304   | -8   |
+-------------------------------------------------+-------+------+
| ethrex/crates/l2/sdk/src/sdk.rs                 | 737   | +256 |
+-------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/kademlia.rs        | 625   | +5   |
+-------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/peer_handler.rs    | 718   | -25  |
+-------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/gen_db.rs          | 244   | -3   |
+-------------------------------------------------+-------+------+

@juanbono juanbono marked this pull request as ready for review July 15, 2025 23:17
@juanbono juanbono requested a review from a team as a code owner July 15, 2025 23:17
if are_block_headers_chained(&block_headers, &order) {
return Some(block_headers);
} else {
warn!("[SYNCING] Received invalid headers from peer");
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if:

  • One peer is very slow and times out. All blocks will be discarded?
  • Same question but if a peer returns invalid blocks or blocks from another chain?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L1 Ethereum client
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants