Skip to content

Commit f4e17a7

Browse files
jonastheislispc
andauthored
feat(eth-wire): announce block to all neighbors (#336)
* feat(eth-wire): announce block to all neighbors * fix lint * fix more lint * update openvm * fix openvm building --------- Co-authored-by: Zhang Zhuo <[email protected]>
1 parent af87226 commit f4e17a7

File tree

5 files changed

+322
-331
lines changed

5 files changed

+322
-331
lines changed

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ jobs:
274274
- uses: actions/checkout@v4
275275
- uses: dtolnay/rust-toolchain@master
276276
with:
277-
toolchain: nightly-2025-07-30
277+
toolchain: nightly-2025-08-18
278278
- uses: Swatinem/rust-cache@v2
279279
with:
280280
cache-on-failure: true
281-
- run: cargo install --locked --git https://github.com/openvm-org/openvm.git --tag v1.4.0-rc.2 cargo-openvm
281+
- run: cargo install --locked --git https://github.com/openvm-org/openvm.git --tag v1.4.0 cargo-openvm
282282
- name: verify openvm compatibility
283283
env:
284-
OPENVM_RUST_TOOLCHAIN: nightly-2025-07-30
284+
OPENVM_RUST_TOOLCHAIN: nightly-2025-08-18
285285
run: cargo openvm build --manifest-path crates/scroll/openvm-compat/Cargo.toml
286286

287287
lint-success:

crates/net/network/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ tracing.workspace = true
6767
rustc-hash.workspace = true
6868
thiserror.workspace = true
6969
parking_lot.workspace = true
70-
rand.workspace = true
7170
rand_08.workspace = true
7271
secp256k1 = { workspace = true, features = ["global-context", "std", "recovery"] }
7372
derive_more.workspace = true
@@ -96,6 +95,7 @@ alloy-genesis.workspace = true
9695
tempfile.workspace = true
9796
url.workspace = true
9897
secp256k1 = { workspace = true, features = ["rand"] }
98+
rand.workspace = true
9999

100100
## Benchmarks
101101
criterion = { workspace = true, features = ["async_tokio", "html_reports"] }
@@ -114,7 +114,6 @@ serde = [
114114
"alloy-primitives/serde",
115115
"discv5/serde",
116116
"parking_lot/serde",
117-
"rand/serde",
118117
"smallvec/serde",
119118
"url/serde",
120119
"reth-primitives-traits/serde",
@@ -124,6 +123,7 @@ serde = [
124123
"reth-ethereum-primitives/serde",
125124
"reth-network-api/serde",
126125
"rand_08/serde",
126+
"rand/serde",
127127
"reth-storage-api/serde",
128128
]
129129
test-utils = [

crates/net/network/src/state.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{
1212
};
1313
use alloy_consensus::BlockHeader;
1414
use alloy_primitives::B256;
15-
use rand::seq::SliceRandom;
1615
use reth_eth_wire::{
1716
BlockHashNumber, Capabilities, DisconnectReason, EthNetworkPrimitives, NetworkPrimitives,
1817
NewBlockHashes, NewBlockPayload, UnifiedStatus,
@@ -192,21 +191,13 @@ impl<N: NetworkPrimitives> NetworkState<N> {
192191
///
193192
/// This is supposed to be invoked after the block was validated.
194193
///
195-
/// > It then sends the block to a small fraction of connected peers (usually the square root of
196-
/// > the total number of peers) using the `NewBlock` message.
194+
/// Note: Sends a `NewBlock` message to all of the connected peers. This is okay because this
195+
/// method is only used until we deprecate l2geth clients which don't support scroll-wire.
197196
///
198197
/// See also <https://github.com/ethereum/devp2p/blob/master/caps/eth.md>
199198
pub(crate) fn announce_new_block(&mut self, msg: NewBlockMessage<N::NewBlockPayload>) {
200-
// send a `NewBlock` message to a fraction of the connected peers (square root of the total
201-
// number of peers)
202-
let num_propagate = (self.active_peers.len() as f64).sqrt() as u64 + 1;
203-
204199
let number = msg.block.block().header().number();
205-
let mut count = 0;
206-
207-
// Shuffle to propagate to a random sample of peers on every block announcement
208-
let mut peers: Vec<_> = self.active_peers.iter_mut().collect();
209-
peers.shuffle(&mut rand::rng());
200+
let peers: Vec<_> = self.active_peers.iter_mut().collect();
210201

211202
for (peer_id, peer) in peers {
212203
if peer.blocks.contains(&msg.hash) {
@@ -215,24 +206,16 @@ impl<N: NetworkPrimitives> NetworkState<N> {
215206
}
216207

217208
// Queue a `NewBlock` message for the peer
218-
if count < num_propagate {
219-
self.queued_messages
220-
.push_back(StateAction::NewBlock { peer_id: *peer_id, block: msg.clone() });
221-
222-
// update peer block info
223-
if self.state_fetcher.update_peer_block(peer_id, msg.hash, number) {
224-
peer.best_hash = msg.hash;
225-
}
209+
self.queued_messages
210+
.push_back(StateAction::NewBlock { peer_id: *peer_id, block: msg.clone() });
226211

227-
// mark the block as seen by the peer
228-
peer.blocks.insert(msg.hash);
229-
230-
count += 1;
212+
// update peer block info
213+
if self.state_fetcher.update_peer_block(peer_id, msg.hash, number) {
214+
peer.best_hash = msg.hash;
231215
}
232216

233-
if count >= num_propagate {
234-
break
235-
}
217+
// mark the block as seen by the peer
218+
peer.blocks.insert(msg.hash);
236219
}
237220
}
238221

0 commit comments

Comments
 (0)