Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
sc-network: Do not return error on peer id only reserved nodes (#11346)
Browse files Browse the repository at this point in the history
When passing reserved nodes only with a peer id it was failing with the `DuplicateBootnode` error.
Besides that there are some clean ups. We for example added the bootnodes twice to the `known_addresses`.
  • Loading branch information
bkchr authored May 4, 2022
1 parent ce4c065 commit 58fd5b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 4 additions & 2 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,15 @@ where
let mut default_sets_reserved = HashSet::new();
for reserved in network_config.default_peers_set.reserved_nodes.iter() {
default_sets_reserved.insert(reserved.peer_id);
known_addresses.push((reserved.peer_id, reserved.multiaddr.clone()));

if !reserved.multiaddr.is_empty() {
known_addresses.push((reserved.peer_id, reserved.multiaddr.clone()));
}
}

let mut bootnodes = Vec::with_capacity(network_config.boot_nodes.len());
for bootnode in network_config.boot_nodes.iter() {
bootnodes.push(bootnode.peer_id);
known_addresses.push((bootnode.peer_id, bootnode.multiaddr.clone()));
}

// Set number 0 is used for block announces.
Expand Down
18 changes: 11 additions & 7 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,29 @@ where
)?;

// List of multiaddresses that we know in the network.
let mut bootnodes = Vec::new();
let mut boot_node_ids = HashSet::new();

// Process the bootnodes.
for bootnode in params.network_config.boot_nodes.iter() {
bootnodes.push(bootnode.peer_id);
boot_node_ids.insert(bootnode.peer_id);
known_addresses.push((bootnode.peer_id, bootnode.multiaddr.clone()));
}

let boot_node_ids = Arc::new(boot_node_ids);

// Check for duplicate bootnodes.
known_addresses.iter().try_for_each(|(peer_id, addr)| {
if let Some(other) = known_addresses.iter().find(|o| o.1 == *addr && o.0 != *peer_id) {
params.network_config.boot_nodes.iter().try_for_each(|bootnode| {
if let Some(other) = params
.network_config
.boot_nodes
.iter()
.filter(|o| o.multiaddr == bootnode.multiaddr)
.find(|o| o.peer_id != bootnode.peer_id)
{
Err(Error::DuplicateBootnode {
address: addr.clone(),
first_id: *peer_id,
second_id: other.0,
address: bootnode.multiaddr.clone(),
first_id: bootnode.peer_id,
second_id: other.peer_id,
})
} else {
Ok(())
Expand Down

0 comments on commit 58fd5b7

Please sign in to comment.