Use LOG_TARGET in consensus related crates (#12875)

* Use shared LOG_TARGET in consensus related crates
* Rename target from "afg" to "grandpa"
This commit is contained in:
Davide Galassi
2022-12-14 14:56:17 +01:00
committed by GitHub
parent 3e0a1904b7
commit 391adaf443
31 changed files with 343 additions and 247 deletions
@@ -99,7 +99,7 @@ use sp_finality_grandpa::AuthorityId;
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero};
use super::{benefit, cost, Round, SetId, NEIGHBOR_REBROADCAST_PERIOD};
use crate::{environment, CatchUp, CompactCommit, SignedMessage};
use crate::{environment, CatchUp, CompactCommit, SignedMessage, LOG_TARGET};
use std::{
collections::{HashSet, VecDeque},
@@ -578,8 +578,13 @@ impl<N: Ord> Peers<N> {
last_update: Some(now),
};
trace!(target: "afg", "Peer {} updated view. Now at {:?}, {:?}",
who, peer.view.round, peer.view.set_id);
trace!(
target: LOG_TARGET,
"Peer {} updated view. Now at {:?}, {:?}",
who,
peer.view.round,
peer.view.set_id
);
Ok(Some(&peer.view))
}
@@ -801,8 +806,12 @@ impl<Block: BlockT> Inner<Block> {
let set_id = local_view.set_id;
debug!(target: "afg", "Voter {} noting beginning of round {:?} to network.",
self.config.name(), (round, set_id));
debug!(
target: LOG_TARGET,
"Voter {} noting beginning of round {:?} to network.",
self.config.name(),
(round, set_id)
);
local_view.update_round(round);
@@ -824,7 +833,7 @@ impl<Block: BlockT> Inner<Block> {
authorities.iter().collect::<HashSet<_>>();
if diff_authorities {
debug!(target: "afg",
debug!(target: LOG_TARGET,
"Gossip validator noted set {:?} twice with different authorities. \
Was the authority set hard forked?",
set_id,
@@ -912,7 +921,7 @@ impl<Block: BlockT> Inner<Block> {
// ensure authority is part of the set.
if !self.authorities.contains(&full.message.id) {
debug!(target: "afg", "Message from unknown voter: {}", full.message.id);
debug!(target: LOG_TARGET, "Message from unknown voter: {}", full.message.id);
telemetry!(
self.config.telemetry;
CONSENSUS_DEBUG;
@@ -929,7 +938,7 @@ impl<Block: BlockT> Inner<Block> {
full.round.0,
full.set_id.0,
) {
debug!(target: "afg", "Bad message signature {}", full.message.id);
debug!(target: LOG_TARGET, "Bad message signature {}", full.message.id);
telemetry!(
self.config.telemetry;
CONSENSUS_DEBUG;
@@ -964,7 +973,7 @@ impl<Block: BlockT> Inner<Block> {
if full.message.precommits.len() != full.message.auth_data.len() ||
full.message.precommits.is_empty()
{
debug!(target: "afg", "Malformed compact commit");
debug!(target: LOG_TARGET, "Malformed compact commit");
telemetry!(
self.config.telemetry;
CONSENSUS_DEBUG;
@@ -1023,9 +1032,9 @@ impl<Block: BlockT> Inner<Block> {
PendingCatchUp::Processing { .. } => {
self.pending_catch_up = PendingCatchUp::None;
},
state => debug!(target: "afg",
"Noted processed catch up message when state was: {:?}",
state,
state => debug!(
target: LOG_TARGET,
"Noted processed catch up message when state was: {:?}", state,
),
}
}
@@ -1067,7 +1076,9 @@ impl<Block: BlockT> Inner<Block> {
return (None, Action::Discard(Misbehavior::OutOfScopeMessage.cost()))
}
trace!(target: "afg", "Replying to catch-up request for round {} from {} with round {}",
trace!(
target: LOG_TARGET,
"Replying to catch-up request for round {} from {} with round {}",
request.round.0,
who,
last_completed_round.number,
@@ -1141,9 +1152,9 @@ impl<Block: BlockT> Inner<Block> {
let (catch_up_allowed, catch_up_report) = self.note_catch_up_request(who, &request);
if catch_up_allowed {
debug!(target: "afg", "Sending catch-up request for round {} to {}",
round,
who,
debug!(
target: LOG_TARGET,
"Sending catch-up request for round {} to {}", round, who,
);
catch_up = Some(GossipMessage::<Block>::CatchUpRequest(request));
@@ -1347,7 +1358,7 @@ impl<Block: BlockT> GossipValidator<Block> {
let metrics = match prometheus_registry.map(Metrics::register) {
Some(Ok(metrics)) => Some(metrics),
Some(Err(e)) => {
debug!(target: "afg", "Failed to register metrics: {:?}", e);
debug!(target: LOG_TARGET, "Failed to register metrics: {:?}", e);
None
},
None => None,
@@ -1466,7 +1477,7 @@ impl<Block: BlockT> GossipValidator<Block> {
},
Err(e) => {
message_name = None;
debug!(target: "afg", "Error decoding message: {}", e);
debug!(target: LOG_TARGET, "Error decoding message: {}", e);
telemetry!(
self.telemetry;
CONSENSUS_DEBUG;
@@ -54,7 +54,7 @@ use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Numb
use crate::{
environment::HasVoted, CatchUp, Commit, CommunicationIn, CommunicationOutH, CompactCommit,
Error, Message, SignedMessage,
Error, Message, SignedMessage, LOG_TARGET,
};
use gossip::{
FullCatchUpMessage, FullCommitMessage, GossipMessage, GossipValidator, PeerReport, VoteMessage,
@@ -274,7 +274,8 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
gossip_engine.lock().register_gossip_message(topic, message.encode());
}
trace!(target: "afg",
trace!(
target: LOG_TARGET,
"Registered {} messages for topic {:?} (round: {}, set_id: {})",
round.votes.len(),
topic,
@@ -340,13 +341,19 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
match decoded {
Err(ref e) => {
debug!(target: "afg", "Skipping malformed message {:?}: {}", notification, e);
debug!(
target: LOG_TARGET,
"Skipping malformed message {:?}: {}", notification, e
);
future::ready(None)
},
Ok(GossipMessage::Vote(msg)) => {
// check signature.
if !voters.contains(&msg.message.id) {
debug!(target: "afg", "Skipping message from unknown voter {}", msg.message.id);
debug!(
target: LOG_TARGET,
"Skipping message from unknown voter {}", msg.message.id
);
return future::ready(None)
}
@@ -388,7 +395,7 @@ impl<B: BlockT, N: Network<B>> NetworkBridge<B, N> {
future::ready(Some(msg.message))
},
_ => {
debug!(target: "afg", "Skipping unknown message type");
debug!(target: LOG_TARGET, "Skipping unknown message type");
future::ready(None)
},
}
@@ -631,7 +638,12 @@ fn incoming_global<B: BlockT>(
// this could be optimized by decoding piecewise.
let decoded = GossipMessage::<B>::decode(&mut &notification.message[..]);
if let Err(ref e) = decoded {
trace!(target: "afg", "Skipping malformed commit message {:?}: {}", notification, e);
trace!(
target: LOG_TARGET,
"Skipping malformed commit message {:?}: {}",
notification,
e
);
}
future::ready(decoded.map(move |d| (notification, d)).ok())
})
@@ -642,7 +654,7 @@ fn incoming_global<B: BlockT>(
GossipMessage::CatchUp(msg) =>
process_catch_up(msg, notification, &gossip_engine, &gossip_validator, &voters),
_ => {
debug!(target: "afg", "Skipping unknown message type");
debug!(target: LOG_TARGET, "Skipping unknown message type");
None
},
})
@@ -748,7 +760,7 @@ impl<Block: BlockT> Sink<Message<Block::Header>> for OutgoingMessages<Block> {
});
debug!(
target: "afg",
target: LOG_TARGET,
"Announcing block {} to peers which we voted on in round {} in set {}",
target_hash,
self.round,
@@ -813,7 +825,7 @@ fn check_compact_commit<Block: BlockT>(
return Err(cost::MALFORMED_COMMIT)
}
} else {
debug!(target: "afg", "Skipping commit containing unknown voter {}", id);
debug!(target: LOG_TARGET, "Skipping commit containing unknown voter {}", id);
return Err(cost::MALFORMED_COMMIT)
}
}
@@ -838,7 +850,7 @@ fn check_compact_commit<Block: BlockT>(
set_id.0,
&mut buf,
) {
debug!(target: "afg", "Bad commit message signature {}", id);
debug!(target: LOG_TARGET, "Bad commit message signature {}", id);
telemetry!(
telemetry;
CONSENSUS_DEBUG;
@@ -886,7 +898,10 @@ fn check_catch_up<Block: BlockT>(
return Err(cost::MALFORMED_CATCH_UP)
}
} else {
debug!(target: "afg", "Skipping catch up message containing unknown voter {}", id);
debug!(
target: LOG_TARGET,
"Skipping catch up message containing unknown voter {}", id
);
return Err(cost::MALFORMED_CATCH_UP)
}
}
@@ -922,7 +937,7 @@ fn check_catch_up<Block: BlockT>(
if !sp_finality_grandpa::check_message_signature_with_buffer(
&msg, id, sig, round, set_id, buf,
) {
debug!(target: "afg", "Bad catch up message signature {}", id);
debug!(target: LOG_TARGET, "Bad catch up message signature {}", id);
telemetry!(
telemetry;
CONSENSUS_DEBUG;
@@ -21,17 +21,19 @@
use futures::{future::FutureExt as _, prelude::*, ready, stream::Stream};
use futures_timer::Delay;
use log::debug;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use std::{
pin::Pin,
task::{Context, Poll},
time::Duration,
};
use super::gossip::{GossipMessage, NeighborPacket};
use sc_network::PeerId;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedReceiver, TracingUnboundedSender};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use super::gossip::{GossipMessage, NeighborPacket};
use crate::LOG_TARGET;
/// A sender used to send neighbor packets to a background job.
#[derive(Clone)]
pub(super) struct NeighborPacketSender<B: BlockT>(
@@ -46,7 +48,7 @@ impl<B: BlockT> NeighborPacketSender<B> {
neighbor_packet: NeighborPacket<NumberFor<B>>,
) {
if let Err(err) = self.0.unbounded_send((who, neighbor_packet)) {
debug!(target: "afg", "Failed to send neighbor packet: {:?}", err);
debug!(target: LOG_TARGET, "Failed to send neighbor packet: {:?}", err);
}
}
}