Skip to content

Commit aacc6ca

Browse files
authored
sc-network: Improve invalid boot node reporting (paritytech#14455)
This improves the reporting of invalid boot nodes. First, it will only report each boot node once as invalid and not every time we try to connect to the node. Second, the node will only report for addresses that we added as startup and not for addresses of the boot node that the node learned from other nodes. Closes: paritytech#13584 Closes: paritytech/polkadot#7385
1 parent 9f6fecf commit aacc6ca

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

client/network/src/service.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
3030
use crate::{
3131
behaviour::{self, Behaviour, BehaviourOut},
32-
config::{FullNetworkConfiguration, MultiaddrWithPeerId, Params, TransportConfig},
32+
config::{parse_addr, FullNetworkConfiguration, MultiaddrWithPeerId, Params, TransportConfig},
3333
discovery::DiscoveryConfig,
3434
error::Error,
3535
event::{DhtEvent, Event},
@@ -271,11 +271,14 @@ where
271271
)?;
272272

273273
// List of multiaddresses that we know in the network.
274-
let mut boot_node_ids = HashSet::new();
274+
let mut boot_node_ids = HashMap::<PeerId, Vec<Multiaddr>>::new();
275275

276276
// Process the bootnodes.
277277
for bootnode in network_config.boot_nodes.iter() {
278-
boot_node_ids.insert(bootnode.peer_id);
278+
boot_node_ids
279+
.entry(bootnode.peer_id)
280+
.or_default()
281+
.push(bootnode.multiaddr.clone());
279282
known_addresses.push((bootnode.peer_id, bootnode.multiaddr.clone()));
280283
}
281284

@@ -450,6 +453,7 @@ where
450453
peers_notifications_sinks,
451454
metrics,
452455
boot_node_ids,
456+
reported_invalid_boot_nodes: Default::default(),
453457
_marker: Default::default(),
454458
_block: Default::default(),
455459
})
@@ -1144,8 +1148,10 @@ where
11441148
event_streams: out_events::OutChannels,
11451149
/// Prometheus network metrics.
11461150
metrics: Option<Metrics>,
1147-
/// The `PeerId`'s of all boot nodes.
1148-
boot_node_ids: Arc<HashSet<PeerId>>,
1151+
/// The `PeerId`'s of all boot nodes mapped to the registered addresses.
1152+
boot_node_ids: Arc<HashMap<PeerId, Vec<Multiaddr>>>,
1153+
/// Boot nodes that we already have reported as invalid.
1154+
reported_invalid_boot_nodes: HashSet<PeerId>,
11491155
/// For each peer and protocol combination, an object that allows sending notifications to
11501156
/// that peer. Shared with the [`NetworkService`].
11511157
peers_notifications_sinks: Arc<Mutex<HashMap<(PeerId, ProtocolName), NotificationsSink>>>,
@@ -1603,15 +1609,27 @@ where
16031609
peer_id, error,
16041610
);
16051611

1606-
if self.boot_node_ids.contains(&peer_id) {
1612+
let not_reported = !self.reported_invalid_boot_nodes.contains(&peer_id);
1613+
1614+
if let Some(addresses) =
1615+
not_reported.then(|| self.boot_node_ids.get(&peer_id)).flatten()
1616+
{
16071617
if let DialError::WrongPeerId { obtained, endpoint } = &error {
16081618
if let ConnectedPoint::Dialer { address, role_override: _ } = endpoint {
1609-
warn!(
1610-
"💔 The bootnode you want to connect to at `{}` provided a different peer ID `{}` than the one you expect `{}`.",
1611-
address,
1612-
obtained,
1613-
peer_id,
1614-
);
1619+
let address_without_peer_id = parse_addr(address.clone())
1620+
.map_or_else(|_| address.clone(), |r| r.1);
1621+
1622+
// Only report for address of boot node that was added at startup of
1623+
// the node and not for any address that the node learned of the
1624+
// boot node.
1625+
if addresses.iter().any(|a| address_without_peer_id == *a) {
1626+
warn!(
1627+
"💔 The bootnode you want to connect to at `{address}` provided a \
1628+
different peer ID `{obtained}` than the one you expect `{peer_id}`.",
1629+
);
1630+
1631+
self.reported_invalid_boot_nodes.insert(peer_id);
1632+
}
16151633
}
16161634
}
16171635
}

0 commit comments

Comments
 (0)