Skip to content

Commit c2ed5f7

Browse files
committed
fix(network): tighten TcpTransport trait impl per review
- broadcast_message: replace the all-three-tier match with explicit unreachable!() for T1/T3. The previous debug_assert + match masked the fact that broadcast is only valid on T2; the unreachable arms document and enforce the trait contract directly. - disconnect_peer: drop the early `return` after the first matching tier. A peer can be connected on multiple tiers simultaneously (e.g. T1 + T2 for a validator); stop the connection on every tier we find it on, otherwise a partial disconnect leaves a stale entry. Addresses VanBarbascu's review on #15575.
1 parent e04072d commit c2ed5f7

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

chain/network/src/peer_manager/tcp_transport.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,25 @@ impl NetworkTransport for TcpTransport {
2828
}
2929

3030
fn broadcast_message(&self, tier: tcp::Tier, msg: Arc<PeerMessage>) {
31-
debug_assert!(tier == tcp::Tier::T2);
31+
// Broadcast is only supported on T2. T1 and T3 are direct
32+
// tiers — the trait contract forbids broadcasting over them.
3233
match tier {
33-
tcp::Tier::T1 => self.state.tier1.broadcast_message(msg),
3434
tcp::Tier::T2 => self.state.tier2.broadcast_message(msg),
35-
tcp::Tier::T3 => self.state.tier3.broadcast_message(msg),
35+
tcp::Tier::T1 | tcp::Tier::T3 => {
36+
unreachable!("broadcast_message called with unsupported tier {:?}", tier);
37+
}
3638
}
3739
}
3840

3941
fn disconnect_peer(&self, peer_id: &PeerId, ban_reason: Option<ReasonForBan>) {
40-
// Search all tiers for the connection.
42+
// A peer may be connected on multiple tiers simultaneously
43+
// (e.g. T1 + T2 for a validator). Stop the connection on every
44+
// tier we find it on — partial disconnect would leave a stale
45+
// entry on the other tier.
4146
for pool in [&self.state.tier1, &self.state.tier2, &self.state.tier3] {
4247
let snapshot = pool.load();
4348
if let Some(conn) = snapshot.ready.get(peer_id) {
4449
conn.stop(ban_reason);
45-
return;
4650
}
4751
}
4852
}

0 commit comments

Comments
 (0)