gossip: choose a random subset on send instead of limiting connections (#2776)

* gossip: choose random subset on send

* naming bikeshed
This commit is contained in:
Andronik Ordian
2021-03-30 20:59:53 +02:00
committed by GitHub
parent a3115401c3
commit 9ac35d9f2b
10 changed files with 41 additions and 27 deletions
@@ -31,7 +31,10 @@ use polkadot_subsystem::{
RuntimeApiMessage, RuntimeApiRequest, NetworkBridgeEvent,
},
};
use polkadot_node_subsystem_util::metrics::{self, prometheus};
use polkadot_node_subsystem_util::{
metrics::{self, prometheus},
MIN_GOSSIP_PEERS,
};
use polkadot_node_primitives::{SignedFullStatement};
use polkadot_primitives::v1::{
Hash, CompactStatement, ValidatorIndex, ValidatorId, SigningContext, ValidatorSignature, CandidateHash,
@@ -620,13 +623,12 @@ async fn circulate_statement(
) -> Vec<PeerId> {
let fingerprint = stored.fingerprint();
let mut peers_to_send = HashMap::new();
let len_sqrt = (peers.len() as f64).sqrt() as usize;
let cap = std::cmp::max(MIN_GOSSIP_PEERS, len_sqrt);
for (peer, data) in peers.iter_mut() {
if let Some(new_known) = data.send(&relay_parent, &fingerprint) {
peers_to_send.insert(peer.clone(), new_known);
}
}
let peers_to_send: HashMap<PeerId, bool> = peers.iter_mut().filter_map(|(peer, data)| {
data.send(&relay_parent, &fingerprint).map(|new| (peer.clone(), new))
}).take(cap).collect();
// Send all these peers the initial statement.
if !peers_to_send.is_empty() {