|
29 | 29 |
|
30 | 30 | use crate::{ |
31 | 31 | behaviour::{self, Behaviour, BehaviourOut}, |
32 | | - config::{FullNetworkConfiguration, MultiaddrWithPeerId, Params, TransportConfig}, |
| 32 | + config::{parse_addr, FullNetworkConfiguration, MultiaddrWithPeerId, Params, TransportConfig}, |
33 | 33 | discovery::DiscoveryConfig, |
34 | 34 | error::Error, |
35 | 35 | event::{DhtEvent, Event}, |
@@ -271,11 +271,14 @@ where |
271 | 271 | )?; |
272 | 272 |
|
273 | 273 | // 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(); |
275 | 275 |
|
276 | 276 | // Process the bootnodes. |
277 | 277 | 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()); |
279 | 282 | known_addresses.push((bootnode.peer_id, bootnode.multiaddr.clone())); |
280 | 283 | } |
281 | 284 |
|
@@ -450,6 +453,7 @@ where |
450 | 453 | peers_notifications_sinks, |
451 | 454 | metrics, |
452 | 455 | boot_node_ids, |
| 456 | + reported_invalid_boot_nodes: Default::default(), |
453 | 457 | _marker: Default::default(), |
454 | 458 | _block: Default::default(), |
455 | 459 | }) |
@@ -1144,8 +1148,10 @@ where |
1144 | 1148 | event_streams: out_events::OutChannels, |
1145 | 1149 | /// Prometheus network metrics. |
1146 | 1150 | 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>, |
1149 | 1155 | /// For each peer and protocol combination, an object that allows sending notifications to |
1150 | 1156 | /// that peer. Shared with the [`NetworkService`]. |
1151 | 1157 | peers_notifications_sinks: Arc<Mutex<HashMap<(PeerId, ProtocolName), NotificationsSink>>>, |
@@ -1603,15 +1609,27 @@ where |
1603 | 1609 | peer_id, error, |
1604 | 1610 | ); |
1605 | 1611 |
|
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 | + { |
1607 | 1617 | if let DialError::WrongPeerId { obtained, endpoint } = &error { |
1608 | 1618 | 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 | + } |
1615 | 1633 | } |
1616 | 1634 | } |
1617 | 1635 | } |
|
0 commit comments