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
@@ -20,6 +20,7 @@ futures-timer = "3.0.1"
libp2p = { version = "0.40.0", default-features = false }
log = "0.4.8"
lru = "0.7.0"
ahash = "0.7.6"
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../utils/prometheus" }
sc-network = { version = "0.10.0-dev", path = "../network" }
sp-runtime = { version = "5.0.0", path = "../../primitives/runtime" }
@@ -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 };