Skip to content

fix(l1): validate received blocks from peers#2658

Merged
rodrigo-o merged 53 commits into
mainfrom
fix/validate-received-blocks-from-peers
May 27, 2025
Merged

fix(l1): validate received blocks from peers#2658
rodrigo-o merged 53 commits into
mainfrom
fix/validate-received-blocks-from-peers

Conversation

@JulianVentura

@JulianVentura JulianVentura commented Apr 30, 2025

Copy link
Copy Markdown
Contributor

Motivation

While syncing on Holesky, we noticed that some peers were providing us with empty block bodies. This made the syncing loop fail in different occasions, which ultimately lead to a stop in the syncing process. Instead of failing, we want to validate the received headers and bodies and discard the peer and retry if they are not valid.

Description

This PR makes the following changes:

  • Add a new validation validate_block_body to check if a body is valid, agains the corresponding header
  • Add a simple header validation to the peer handler request headers, to make sure that the received headers conform a chain from the current head
  • Call the validate_block_body function from the peer handle validat and request block bodies, to check that the received block bodies are valid.
  • Modify the PeerChannel API to return the peer_id on the request_block_headers and request_block_bodies functions.
  • Modify the PeerChannel API to add a function remove_peer to remove a peer by its peer_id.
  • Remove the peer that provided us with the headers or bodies on the syncing loop if they are invalid

Closes #2766

@JulianVentura JulianVentura self-assigned this Apr 30, 2025
@github-actions

github-actions Bot commented Apr 30, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 107
Total lines removed: 4
Total lines changed: 111

Detailed view
+----------------------------------------------+-------+------+
| File                                         | Lines | Diff |
+----------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs       | 493   | +2   |
+----------------------------------------------+-------+------+
| ethrex/crates/blockchain/error.rs            | 105   | +4   |
+----------------------------------------------+-------+------+
| ethrex/crates/common/types/block.rs          | 747   | +29  |
+----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/kademlia.rs     | 501   | +3   |
+----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/peer_handler.rs | 647   | +69  |
+----------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync.rs         | 566   | -4   |
+----------------------------------------------+-------+------+

@JulianVentura JulianVentura marked this pull request as ready for review April 30, 2025 22:08
@JulianVentura JulianVentura requested a review from a team as a code owner April 30, 2025 22:08
Comment thread crates/blockchain/error.rs Outdated
Comment thread crates/networking/p2p/sync.rs Outdated
Comment thread crates/networking/p2p/sync.rs Outdated
@mpaulucci mpaulucci assigned rodrigo-o and unassigned JulianVentura May 7, 2025
@mpaulucci mpaulucci marked this pull request as draft May 13, 2025 15:12
@rodrigo-o rodrigo-o requested a review from fmoletta May 27, 2025 13:15
@rodrigo-o rodrigo-o enabled auto-merge May 27, 2025 14:31
@rodrigo-o rodrigo-o disabled auto-merge May 27, 2025 14:42
@rodrigo-o rodrigo-o enabled auto-merge May 27, 2025 20:24
@rodrigo-o rodrigo-o added this pull request to the merge queue May 27, 2025
Merged via the queue into main with commit 84509b6 May 27, 2025
20 checks passed
@rodrigo-o rodrigo-o deleted the fix/validate-received-blocks-from-peers branch May 27, 2025 20:56
rodrigo-o added a commit that referenced this pull request May 28, 2025
github-merge-queue Bot pushed a commit that referenced this pull request May 29, 2025
…mpute_block_hash` (#2959)

**Motivation**

After #2845 we were still calculating the hash of headers every time
instead of using the `get_or_init` version.

**Description**

This PR does a couple of thing
- Make `hash` function public and `compute_block_hash` private in the
BlockHeader
- Replace all header `compute_block_hash` calls with `hash`
- On blocks, replace all `block.header.hash()` for `block.hash()`
instead given that it already delegates internally.
- Fixed an [outstanding
comment](#2658 (comment))
from #2658
- Increased the size of the DB (it was limiting Holesky syncing)

Closes Status: Open.
#2926
github-merge-queue Bot pushed a commit that referenced this pull request May 30, 2025
…ed outside of syncing (#2970)

**Motivation**

This removes an additional validation done on the pre-execution of
blocks as part of [this
PR](#2658)

**Description**

Remove the call to the `validate_block_body` in `validate_block`

Closes #2973
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

While syncing on Holesky, we noticed that some peers were providing us
with empty block bodies. This made the syncing loop fail in different
occasions, which ultimately lead to a stop in the syncing process.
Instead of failing, we want to validate the received headers and bodies
and discard the peer and retry if they are not valid.

**Description**

This PR makes the following changes:

* Add a new validation `validate_block_body` to check if a body is
valid, agains the corresponding header
* Add a simple header validation to the peer handler request headers, to
make sure that the received headers conform a chain from the current
head
* Call the `validate_block_body` function from the peer handle validat
and request block bodies, to check that the received block bodies are
valid.
* Modify the `PeerChannel` API to return the `peer_id` on the
`request_block_headers` and `request_block_bodies` functions.
* Modify the `PeerChannel` API to add a function `remove_peer` to remove
a peer by its `peer_id`.
* Remove the peer that provided us with the headers or bodies on the
syncing loop if they are invalid

Closes lambdaclass#2766

---------

Co-authored-by: Julian Ventura <julian.ventura@lambdaclass.com>
Co-authored-by: Rodrigo Oliveri <rodrigooliveri10@gmail.com>
Co-authored-by: SDartayet <sofiadartayet@gmail.com>
Co-authored-by: SDartayet <44068466+SDartayet@users.noreply.github.com>
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…mpute_block_hash` (lambdaclass#2959)

**Motivation**

After lambdaclass#2845 we were still calculating the hash of headers every time
instead of using the `get_or_init` version.

**Description**

This PR does a couple of thing
- Make `hash` function public and `compute_block_hash` private in the
BlockHeader
- Replace all header `compute_block_hash` calls with `hash`
- On blocks, replace all `block.header.hash()` for `block.hash()`
instead given that it already delegates internally.
- Fixed an [outstanding
comment](lambdaclass#2658 (comment))
from lambdaclass#2658
- Increased the size of the DB (it was limiting Holesky syncing)

Closes Status: Open.
lambdaclass#2926
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…ed outside of syncing (lambdaclass#2970)

**Motivation**

This removes an additional validation done on the pre-execution of
blocks as part of [this
PR](lambdaclass#2658)

**Description**

Remove the call to the `validate_block_body` in `validate_block`

Closes lambdaclass#2973
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate received blocks from peers

5 participants