Skip to content

Commit a4cf3cc

Browse files
committed
lint and block import handling
1 parent fb7f42c commit a4cf3cc

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

crates/network/src/manager.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use super::{
44
use alloy_primitives::FixedBytes;
55
use core::task::Poll;
66
use futures::{FutureExt, StreamExt};
7+
use reth_network::Peers;
78
use reth_network::{
89
cache::LruCache, NetworkConfig as RethNetworkConfig, NetworkHandle as RethNetworkHandle,
910
NetworkManager as RethNetworkManager,
@@ -42,6 +43,7 @@ pub struct NetworkManager {
4243
}
4344

4445
impl NetworkManager {
46+
/// Creates a new [`NetworkManager`] instance.
4547
pub async fn new<C: BlockNumReaderT + 'static>(
4648
mut config: RethNetworkConfig<C, reth_network::EthNetworkPrimitives>,
4749
block_import: impl BlockImport + 'static,
@@ -67,13 +69,15 @@ impl NetworkManager {
6769
}
6870
}
6971

72+
/// Returns a new [`NetworkHandle`] instance.
7073
pub fn handle(&self) -> NetworkHandle {
7174
NetworkHandle::new(
7275
self.to_manager_tx.clone(),
7376
self.inner_network_handle.clone(),
7477
)
7578
}
7679

80+
/// Announces a new block to the network.
7781
fn announce_block(&mut self, block: NewBlock) {
7882
let hash = block.block.hash_slow();
7983

@@ -85,16 +89,15 @@ impl NetworkManager {
8589
.filter_map(|(peer_id, blocks)| (!blocks.contains(&hash)).then_some(*peer_id))
8690
.collect();
8791

88-
println!("peers: {:?}", peers);
89-
9092
// Announced to the filtered set of peers
9193
for peer in peers {
9294
println!("Announcing block to peer {:?}", peer);
9395
self.scroll_wire.announce_block(peer, block.clone(), hash);
9496
}
9597
}
9698

97-
pub fn on_scroll_wire_event(&mut self, event: ScrollWireEvent) {
99+
/// Handler for received events from the [`ScrollWireManager`].
100+
fn on_scroll_wire_event(&mut self, event: ScrollWireEvent) {
98101
match event {
99102
ScrollWireEvent::NewBlock {
100103
peer_id,
@@ -124,6 +127,7 @@ impl NetworkManager {
124127
}
125128
}
126129

130+
/// Handler for the result of a block import.
127131
fn on_block_import_result(&mut self, outcome: BlockImportOutcome) {
128132
let BlockImportOutcome { peer, result } = outcome;
129133
match result {
@@ -136,8 +140,19 @@ impl NetworkManager {
136140
.insert(hash);
137141
self.announce_block(msg);
138142
}
139-
Ok(BlockValidation::ValidHeader { new_block: _ }) => {}
140-
_ => {}
143+
Ok(BlockValidation::ValidHeader { new_block: msg }) => {
144+
let hash = msg.block.hash_slow();
145+
self.scroll_wire
146+
.state_mut()
147+
.entry(peer)
148+
.or_insert_with(|| LruCache::new(100))
149+
.insert(hash);
150+
self.announce_block(msg);
151+
}
152+
Err(_) => {
153+
self.inner_network_handle
154+
.reputation_change(peer, reth_network_api::ReputationChangeKind::BadBlock);
155+
}
141156
}
142157
}
143158

0 commit comments

Comments
 (0)