network-gossip: add metric for number of local messages (#7871)

* network-gossip: add metric for number of local messages

* grandpa: fix GossipEngine missing metrics registry parameter

* network-gossip: increase known messages cache size

* network-gossip: fix tests

* grandpa: remove unnecessary clone

Co-authored-by: Max Inden <mail@max-inden.de>

* network-gossip: count registered and expired messages separately

* network-gossip: add comment on known messages cache size

* network-gossip: extend comment with cache size in memory

Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
André Silva
2021-01-12 15:04:48 +00:00
committed by GitHub
parent da9c73125f
commit 2d1b9a8d38
5 changed files with 101 additions and 34 deletions
+13 -6
View File
@@ -25,6 +25,7 @@ use futures::prelude::*;
use futures::channel::mpsc::{channel, Sender, Receiver};
use libp2p::PeerId;
use log::trace;
use prometheus_endpoint::Registry;
use sp_runtime::traits::Block as BlockT;
use std::{
borrow::Cow,
@@ -72,12 +73,13 @@ impl<B: BlockT> GossipEngine<B> {
network: N,
protocol: impl Into<Cow<'static, str>>,
validator: Arc<dyn Validator<B>>,
metrics_registry: Option<&Registry>,
) -> Self where B: 'static {
let protocol = protocol.into();
let network_event_stream = network.event_stream();
GossipEngine {
state_machine: ConsensusGossip::new(validator, protocol.clone()),
state_machine: ConsensusGossip::new(validator, protocol.clone(), metrics_registry),
network: Box::new(network),
periodic_maintenance_interval: futures_timer::Delay::new(PERIODIC_MAINTENANCE_INTERVAL),
protocol,
@@ -372,7 +374,8 @@ mod tests {
let mut gossip_engine = GossipEngine::<Block>::new(
network.clone(),
"/my_protocol",
Arc::new(AllowAll{}),
Arc::new(AllowAll {}),
None,
);
// Drop network event stream sender side.
@@ -399,7 +402,8 @@ mod tests {
let mut gossip_engine = GossipEngine::<Block>::new(
network.clone(),
protocol.clone(),
Arc::new(AllowAll{}),
Arc::new(AllowAll {}),
None,
);
let mut event_sender = network.inner.lock()
@@ -533,7 +537,8 @@ mod tests {
let mut gossip_engine = GossipEngine::<Block>::new(
network.clone(),
protocol.clone(),
Arc::new(TestValidator{}),
Arc::new(TestValidator {}),
None,
);
// Create channels.
@@ -549,8 +554,10 @@ mod tests {
// Insert sender sides into `gossip_engine`.
for (topic, tx) in txs {
match gossip_engine.message_sinks.get_mut(&topic) {
Some(entry) => entry.push(tx),
None => {gossip_engine.message_sinks.insert(topic, vec![tx]);},
Some(entry) => entry.push(tx),
None => {
gossip_engine.message_sinks.insert(topic, vec![tx]);
}
}
}