mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
improved gossip topology (#3270)
* gossip-support: gossip topology * some fixes * handle view update for newly added gossip peers * fix neighbors calculation * fix test * resolve TODOs * typo * guide updates * spaces in the guide * sneaky spaces * hash randomness * address some review nits * use unbounded in bridge for subsystem msg
This commit is contained in:
@@ -48,7 +48,7 @@ use polkadot_node_subsystem_util::metrics::{self, prometheus};
|
||||
/// To be added to [`NetworkConfiguration::extra_sets`].
|
||||
pub use polkadot_node_network_protocol::peer_set::{peer_sets_info, IsAuthority};
|
||||
|
||||
use std::collections::{HashMap, hash_map};
|
||||
use std::collections::{HashMap, hash_map, HashSet};
|
||||
use std::iter::ExactSizeIterator;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -58,7 +58,7 @@ mod validator_discovery;
|
||||
///
|
||||
/// Defines the `Network` trait with an implementation for an `Arc<NetworkService>`.
|
||||
mod network;
|
||||
use network::{Network, send_message};
|
||||
use network::{Network, send_message, get_peer_id_by_authority_id};
|
||||
|
||||
/// Request multiplexer for combining the multiple request sources into a single `Stream` of `AllMessages`.
|
||||
mod multiplexer;
|
||||
@@ -557,6 +557,34 @@ where
|
||||
network_service = ns;
|
||||
authority_discovery_service = ads;
|
||||
}
|
||||
NetworkBridgeMessage::NewGossipTopology {
|
||||
our_neighbors,
|
||||
} => {
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
action = "NewGossipTopology",
|
||||
neighbors = our_neighbors.len(),
|
||||
"Gossip topology has changed",
|
||||
);
|
||||
|
||||
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(
|
||||
ads,
|
||||
authority.clone(),
|
||||
).await;
|
||||
|
||||
if let Some(peer_id) = addr {
|
||||
gossip_peers.insert(peer_id);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_validation_event_to_all_unbounded(
|
||||
NetworkBridgeEvent::NewGossipTopology(gossip_peers),
|
||||
ctx.sender(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ use polkadot_node_network_protocol::{
|
||||
request_response::{OutgoingRequest, Requests, Recipient},
|
||||
PeerId, UnifiedReputationChange as Rep,
|
||||
};
|
||||
use polkadot_primitives::v1::{Block, Hash};
|
||||
use polkadot_primitives::v1::{AuthorityDiscoveryId, Block, Hash};
|
||||
use polkadot_subsystem::{SubsystemError, SubsystemResult};
|
||||
|
||||
use crate::validator_discovery::AuthorityDiscovery;
|
||||
@@ -303,3 +303,17 @@ 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>(
|
||||
authority_discovery: &mut AD,
|
||||
authority: AuthorityDiscoveryId,
|
||||
) -> Option<PeerId> {
|
||||
// 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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user