babe, grandpa: restrict info logging during initial sync (#5564)

* babe: restrict info logging during initial sync

* grandpa: restrict info logging during initial sync

* grandpa: fix test compilation

* grandpa: remove afg_log macro mod
This commit is contained in:
André Silva
2020-04-07 21:11:22 +01:00
committed by GitHub
parent 6a87e1d1af
commit 1a9c0fee30
6 changed files with 147 additions and 53 deletions
@@ -16,7 +16,7 @@
use std::{sync::Arc, collections::HashMap};
use log::{debug, trace, info};
use log::{debug, trace};
use parity_scale_codec::Encode;
use parking_lot::RwLockWriteGuard;
@@ -27,7 +27,7 @@ use sp_api::{TransactionFor};
use sp_consensus::{
BlockImport, Error as ConsensusError,
BlockCheckParams, BlockImportParams, ImportResult, JustificationImport,
BlockCheckParams, BlockImportParams, BlockOrigin, ImportResult, JustificationImport,
SelectChain,
};
use sp_finality_grandpa::{ConsensusLog, ScheduledChange, SetId, GRANDPA_ENGINE_ID};
@@ -128,7 +128,12 @@ impl<BE, Block: BlockT, Client, SC> JustificationImport<Block>
number: NumberFor<Block>,
justification: Justification,
) -> Result<(), Self::Error> {
GrandpaBlockImport::import_justification(self, hash, number, justification, false)
// this justification was requested by the sync service, therefore we
// are not sure if it should enact a change or not. it could have been a
// request made as part of initial sync but that means the justification
// wasn't part of the block and was requested asynchronously, probably
// makes sense to log in that case.
GrandpaBlockImport::import_justification(self, hash, number, justification, false, false)
}
}
@@ -250,6 +255,7 @@ where
&self,
block: &mut BlockImportParams<Block, TransactionFor<Client, Block>>,
hash: Block::Hash,
initial_sync: bool,
) -> Result<PendingSetChanges<Block>, ConsensusError> {
// when we update the authorities, we need to hold the lock
// until the block is written to prevent a race if we need to restore
@@ -324,7 +330,9 @@ where
}
let applied_changes = {
let forced_change_set = guard.as_mut().apply_forced_changes(hash, number, &is_descendent_of)
let forced_change_set = guard
.as_mut()
.apply_forced_changes(hash, number, &is_descendent_of, initial_sync)
.map_err(|e| ConsensusError::ClientImport(e.to_string()))
.map_err(ConsensusError::from)?;
@@ -419,7 +427,10 @@ impl<BE, Block: BlockT, Client, SC> BlockImport<Block>
Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()),
}
let pending_changes = self.make_authorities_changes(&mut block, hash)?;
// on initial sync we will restrict logging under info to avoid spam.
let initial_sync = block.origin == BlockOrigin::NetworkInitialSync;
let pending_changes = self.make_authorities_changes(&mut block, hash, initial_sync)?;
// we don't want to finalize on `inner.import_block`
let mut justification = block.justification.take();
@@ -492,7 +503,15 @@ impl<BE, Block: BlockT, Client, SC> BlockImport<Block>
match justification {
Some(justification) => {
self.import_justification(hash, number, justification, needs_justification).unwrap_or_else(|err| {
let import_res = self.import_justification(
hash,
number,
justification,
needs_justification,
initial_sync,
);
import_res.unwrap_or_else(|err| {
if needs_justification || enacts_consensus_change {
debug!(target: "afg", "Imported block #{} that enacts authority set change with \
invalid justification: {:?}, requesting justification from peers.", number, err);
@@ -604,6 +623,7 @@ where
number: NumberFor<Block>,
justification: Justification,
enacts_change: bool,
initial_sync: bool,
) -> Result<(), ConsensusError> {
let justification = GrandpaJustification::decode_and_verify_finalizes(
&justification,
@@ -625,12 +645,17 @@ where
hash,
number,
justification.into(),
initial_sync,
);
match result {
Err(CommandOrError::VoterCommand(command)) => {
info!(target: "afg", "👴 Imported justification for block #{} that triggers \
command {}, signaling voter.", number, command);
afg_log!(initial_sync,
"👴 Imported justification for block #{} that triggers \
command {}, signaling voter.",
number,
command,
);
// send the command to the voter
let _ = self.send_voter_commands.unbounded_send(command);