Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions crates/node/p2p/src/gossip/block_validity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, time::SystemTime};
use std::time::SystemTime;

use alloy_consensus::Block;
use alloy_eips::eip7685::EMPTY_REQUESTS_HASH;
Expand Down Expand Up @@ -160,13 +160,6 @@ impl BlockHandler {
block_hash: envelope.payload.block_hash(),
});
}

seen_hashes_at_height.insert(envelope.payload.block_hash());
} else {
self.seen_hashes.insert(
envelope.payload.block_number(),
HashSet::from([envelope.payload.block_hash()]),
);
}

// CHECK: The signature is valid.
Expand All @@ -183,6 +176,11 @@ impl BlockHandler {
return Err(BlockInvalidError::Signer { expected: msg_signer, received: block_signer });
}

self.seen_hashes
.entry(envelope.payload.block_number())
.or_default()
.insert(envelope.payload.block_hash());

// Mark the block as seen.
if self.seen_hashes.len() >= Self::SEEN_HASH_CACHE_SIZE {
self.seen_hashes.pop_first();
Expand Down Expand Up @@ -576,6 +574,7 @@ pub(crate) mod tests {
signature_bytes[0] = !signature_bytes[0];
envelope.signature = Signature::from_raw_array(&signature_bytes).unwrap();

assert!(handler.seen_hashes.is_empty());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice addition to the unit test

assert!(matches!(handler.block_valid(&envelope), Err(BlockInvalidError::Signature)));
}

Expand Down