Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod validator_discovery;
mod network;
use network::{send_message, Network};

use crate::network::get_peer_id_by_authority_id;
use crate::network::get_addrs_by_authority_id;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -586,12 +586,12 @@ where
let ads = &mut authority_discovery_service;
let mut gossip_peers = HashSet::with_capacity(our_neighbors.len());
for authority in our_neighbors {
let addr = get_peer_id_by_authority_id(
let addrs = get_addrs_by_authority_id(
ads,
authority.clone(),
authority,
).await;

if let Some(peer_id) = addr {
for (peer_id, _) in addrs {
gossip_peers.insert(peer_id);
}
}
Expand Down
21 changes: 6 additions & 15 deletions node/network/bridge/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,9 @@ impl Network for Arc<NetworkService<Block, Hash>> {
let mut found_peer_id = None;
// Note: `get_addresses_by_authority_id` searched in a cache, and it thus expected
// to be very quick.
for addr in authority_discovery
.get_addresses_by_authority_id(authority)
.await
.into_iter()
.flat_map(|list| list.into_iter())
{
let (peer_id, addr) = match parse_addr(addr) {
Ok(v) => v,
Err(_) => continue,
};
NetworkService::add_known_address(&*self, peer_id.clone(), addr);
let addrs = get_addrs_by_authority_id(authority_discovery, authority).await;
for (peer_id, multiaddr) in addrs {
NetworkService::add_known_address(&*self, peer_id.clone(), multiaddr);
found_peer_id = Some(peer_id);
}
found_peer_id
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, looking at this code again, req/resp still assumes one peer_id per authorityid?

Expand Down Expand Up @@ -202,17 +194,16 @@ impl Network for Arc<NetworkService<Block, Hash>> {
}
}

/// We assume one `peer_id` per `authority_id`.
pub async fn get_peer_id_by_authority_id<AD: AuthorityDiscovery>(
pub async fn get_addrs_by_authority_id<AD: AuthorityDiscovery>(
authority_discovery: &mut AD,
authority: AuthorityDiscoveryId,
) -> Option<PeerId> {
) -> impl Iterator<Item = (PeerId, Multiaddr)> {
// Note: `get_addresses_by_authority_id` searched in a cache, and it thus expected
// to be very quick.
authority_discovery
.get_addresses_by_authority_id(authority)
.await
.into_iter()
.flat_map(|list| list.into_iter())
.find_map(|addr| parse_addr(addr).ok().map(|(p, _)| p))
.flat_map(|addr| parse_addr(addr).ok())
}