Reduce CPU overhead of gossip (#10859)

This commit is contained in:
Koute
2022-02-16 13:14:00 +09:00
committed by GitHub
parent 9a78839696
commit ee6223327c
5 changed files with 28 additions and 29 deletions
@@ -18,19 +18,13 @@
use crate::{MessageIntent, Network, ValidationResult, Validator, ValidatorContext};
use ahash::AHashSet;
use libp2p::PeerId;
use lru::LruCache;
use prometheus_endpoint::{register, Counter, PrometheusError, Registry, U64};
use sc_network::ObservedRole;
use sp_runtime::traits::{Block as BlockT, Hash, HashFor};
use std::{
borrow::Cow,
collections::{HashMap, HashSet},
iter,
sync::Arc,
time,
time::Instant,
};
use std::{borrow::Cow, collections::HashMap, iter, sync::Arc, time, time::Instant};
// FIXME: Add additional spam/DoS attack protection: https://github.com/paritytech/substrate/issues/1115
// NOTE: The current value is adjusted based on largest production network deployment (Kusama) and
@@ -56,7 +50,7 @@ mod rep {
}
struct PeerConsensus<H> {
known_messages: HashSet<H>,
known_messages: AHashSet<H>,
}
/// Topic stream message with sender.
@@ -204,7 +198,8 @@ impl<B: BlockT> ConsensusGossip<B> {
?role,
"Registering peer",
);
self.peers.insert(who.clone(), PeerConsensus { known_messages: HashSet::new() });
self.peers
.insert(who.clone(), PeerConsensus { known_messages: Default::default() });
let validator = self.validator.clone();
let mut context = NetworkContext { gossip: self, network };