From e4edd502bf6df9af4f7f252e0db9433840c29bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 12 May 2020 23:08:24 +0200 Subject: [PATCH] Only send last finalized block to telemetry (#6003) Instead of informing the telemetry about each block that is finalized, we only need to send the last finalized block. This removes log spam on initial sync. --- substrate/client/service/src/client/client.rs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/substrate/client/service/src/client/client.rs b/substrate/client/service/src/client/client.rs index bc992291bd..df64622d64 100644 --- a/substrate/client/service/src/client/client.rs +++ b/substrate/client/service/src/client/client.rs @@ -87,6 +87,7 @@ use super::{ block_rules::{BlockRules, LookupResult as BlockLookupResult}, }; use futures::channel::mpsc; +use rand::Rng; #[cfg(feature="test-helpers")] use { @@ -661,8 +662,6 @@ impl Client where if let Ok(ImportResult::Imported(ref aux)) = result { if aux.is_new_best { - use rand::Rng; - // don't send telemetry block import events during initial sync for every // block to avoid spamming the telemetry server, these events will be randomly // sent at a rate of 1/10. @@ -954,7 +953,7 @@ impl Client where // we'll send notifications spuriously in that case. const MAX_TO_NOTIFY: usize = 256; let enacted = route_from_finalized.enacted(); - let start = enacted.len() - ::std::cmp::min(enacted.len(), MAX_TO_NOTIFY); + let start = enacted.len() - std::cmp::min(enacted.len(), MAX_TO_NOTIFY); for finalized in &enacted[start..] { operation.notify_finalized.push(finalized.hash); } @@ -978,14 +977,27 @@ impl Client where return Ok(()); } - for finalized_hash in notify_finalized { - let header = self.header(&BlockId::Hash(finalized_hash))? - .expect("header already known to exist in DB because it is indicated in the tree route; qed"); + // We assume the list is sorted and only want to inform the + // telemetry once about the finalized block. + if let Some(last) = notify_finalized.last() { + let header = self.header(&BlockId::Hash(*last))? + .expect( + "Header already known to exist in DB because it is \ + indicated in the tree route; qed" + ); telemetry!(SUBSTRATE_INFO; "notify.finalized"; "height" => format!("{}", header.number()), - "best" => ?finalized_hash, + "best" => ?last, ); + } + + for finalized_hash in notify_finalized { + let header = self.header(&BlockId::Hash(finalized_hash))? + .expect( + "Header already known to exist in DB because it is \ + indicated in the tree route; qed" + ); let notification = FinalityNotification { header,