Add tracing support to node (#1940)

* drop in tracing to replace log

* add structured logging to trace messages

* add structured logging to debug messages

* add structured logging to info messages

* add structured logging to warn messages

* add structured logging to error messages

* normalize spacing and Display vs Debug

* add instrumentation to the various 'fn run'

* use explicit tracing module throughout

* fix availability distribution test

* don't double-print errors

* remove further redundancy from logs

* fix test errors

* fix more test errors

* remove unused kv_log_macro

* fix unused variable

* add tracing spans to collation generation

* add tracing spans to av-store

* add tracing spans to backing

* add tracing spans to bitfield-signing

* add tracing spans to candidate-selection

* add tracing spans to candidate-validation

* add tracing spans to chain-api

* add tracing spans to provisioner

* add tracing spans to runtime-api

* add tracing spans to availability-distribution

* add tracing spans to bitfield-distribution

* add tracing spans to network-bridge

* add tracing spans to collator-protocol

* add tracing spans to pov-distribution

* add tracing spans to statement-distribution

* add tracing spans to overseer

* cleanup
This commit is contained in:
Peter Goodspeed-Niklaus
2020-11-20 12:02:04 +01:00
committed by GitHub
parent 94670d8082
commit e49989971d
53 changed files with 564 additions and 280 deletions
@@ -6,8 +6,9 @@ edition = "2018"
[dependencies]
futures = "0.3.8"
log = "0.4.11"
parity-scale-codec = { version = "1.3.5", features = ["std"] }
tracing = "0.1.21"
tracing-futures = "0.2.4"
parity-scale-codec = { version = "1.3.5", features = ["std"] }
polkadot-primitives = { path = "../../../primitives" }
polkadot-erasure-coding = { path = "../../../erasure-coding" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
@@ -27,3 +28,4 @@ futures-timer = "3.0.2"
env_logger = "0.8.2"
assert_matches = "1.4.0"
smallvec = "1.5.0"
log = "0.4.11"
@@ -30,7 +30,6 @@ use futures::{channel::oneshot, FutureExt, TryFutureExt};
use sp_core::crypto::Public;
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
use log::{trace, warn};
use polkadot_erasure_coding::branch_hash;
use polkadot_node_network_protocol::{
v1 as protocol_v1, NetworkBridgeEvent, PeerId, ReputationChange as Rep, View,
@@ -53,7 +52,7 @@ use std::collections::{HashMap, HashSet};
use std::iter;
use thiserror::Error;
const TARGET: &'static str = "avad";
const LOG_TARGET: &'static str = "AvailabilityDistribution";
#[derive(Debug, Error)]
enum Error {
@@ -197,6 +196,7 @@ struct PerRelayParent {
impl ProtocolState {
/// Collects the relay_parents ancestors including the relay parents themselfes.
#[tracing::instrument(level = "trace", skip(relay_parents), fields(subsystem = LOG_TARGET))]
fn extend_with_ancestors<'a>(
&'a self,
relay_parents: impl IntoIterator<Item = &'a Hash> + 'a,
@@ -218,6 +218,7 @@ impl ProtocolState {
/// Unionize all cached entries for the given relay parents and its ancestors.
/// Ignores all non existent relay parents, so this can be used directly with a peers view.
/// Returns a map from candidate hash -> receipt
#[tracing::instrument(level = "trace", skip(relay_parents), fields(subsystem = LOG_TARGET))]
fn cached_live_candidates_unioned<'a>(
&'a self,
relay_parents: impl IntoIterator<Item = &'a Hash> + 'a,
@@ -232,6 +233,7 @@ impl ProtocolState {
.collect()
}
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn add_relay_parent<Context>(
&mut self,
ctx: &mut Context,
@@ -287,6 +289,7 @@ impl ProtocolState {
Ok(())
}
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn remove_relay_parent(&mut self, relay_parent: &Hash) -> Result<()> {
// we might be ancestor of some other relay_parent
if let Some(ref mut descendants) = self.ancestry.get_mut(relay_parent) {
@@ -327,6 +330,7 @@ impl ProtocolState {
/// Deal with network bridge updates and track what needs to be tracked
/// which depends on the message type received.
#[tracing::instrument(level = "trace", skip(ctx, keystore, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_network_msg<Context>(
ctx: &mut Context,
keystore: &SyncCryptoStorePtr,
@@ -370,6 +374,7 @@ where
}
/// Handle the changes necessary when our view changes.
#[tracing::instrument(level = "trace", skip(ctx, keystore, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_our_view_change<Context>(
ctx: &mut Context,
keystore: &SyncCryptoStorePtr,
@@ -507,6 +512,7 @@ where
.await
}
#[tracing::instrument(level = "trace", skip(ctx, metrics, message_iter), fields(subsystem = LOG_TARGET))]
async fn send_tracked_gossip_messages_to_peers<Context>(
ctx: &mut Context,
per_candidate: &mut PerCandidate,
@@ -556,6 +562,7 @@ where
// Send the difference between two views which were not sent
// to that particular peer.
#[tracing::instrument(level = "trace", skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_peer_view_change<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -633,6 +640,7 @@ async fn obtain_our_validator_index(
}
/// Handle an incoming message from a peer.
#[tracing::instrument(level = "trace", skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn process_incoming_peer_message<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -711,8 +719,8 @@ where
)
.await?
{
warn!(
target: TARGET,
tracing::warn!(
target: LOG_TARGET,
"Failed to store erasure chunk to availability store"
);
}
@@ -771,6 +779,7 @@ impl AvailabilityDistributionSubsystem {
}
/// Start processing work as passed on from the Overseer.
#[tracing::instrument(skip(self, ctx), fields(subsystem = LOG_TARGET))]
async fn run<Context>(self, mut ctx: Context) -> Result<()>
where
Context: SubsystemContext<Message = AvailabilityDistributionMessage>,
@@ -795,9 +804,10 @@ impl AvailabilityDistributionSubsystem {
)
.await
{
warn!(
target: TARGET,
"Failed to handle incoming network messages: {:?}", e
tracing::warn!(
target: LOG_TARGET,
err = ?e,
"Failed to handle incoming network messages",
);
}
}
@@ -834,6 +844,7 @@ where
}
/// Obtain all live candidates based on an iterator of relay heads.
#[tracing::instrument(level = "trace", skip(ctx, relay_parents), fields(subsystem = LOG_TARGET))]
async fn query_live_candidates_without_ancestors<Context>(
ctx: &mut Context,
relay_parents: impl IntoIterator<Item = Hash>,
@@ -859,6 +870,7 @@ where
/// Obtain all live candidates based on an iterator or relay heads including `k` ancestors.
///
/// Relay parent.
#[tracing::instrument(level = "trace", skip(ctx, relay_parents), fields(subsystem = LOG_TARGET))]
async fn query_live_candidates<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -921,6 +933,7 @@ where
}
/// Query all para IDs.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_para_ids<Context>(ctx: &mut Context, relay_parent: Hash) -> Result<Vec<ParaId>>
where
Context: SubsystemContext<Message = AvailabilityDistributionMessage>,
@@ -952,15 +965,16 @@ where
}
/// Modify the reputation of a peer based on its behavior.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn modify_reputation<Context>(ctx: &mut Context, peer: PeerId, rep: Rep) -> Result<()>
where
Context: SubsystemContext<Message = AvailabilityDistributionMessage>,
{
trace!(
target: TARGET,
"Reputation change of {:?} for peer {:?}",
rep,
peer
tracing::trace!(
target: LOG_TARGET,
rep = ?rep,
peer_id = ?peer,
"Reputation change for peer",
);
ctx.send_message(AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(peer, rep),
@@ -970,6 +984,7 @@ where
}
/// Query the proof of validity for a particular candidate hash.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_data_availability<Context>(ctx: &mut Context, candidate_hash: CandidateHash) -> Result<bool>
where
Context: SubsystemContext<Message = AvailabilityDistributionMessage>,
@@ -984,6 +999,7 @@ where
.map_err(|e| Error::QueryAvailabilityResponseChannel(e))
}
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_chunk<Context>(
ctx: &mut Context,
candidate_hash: CandidateHash,
@@ -1001,6 +1017,7 @@ where
rx.await.map_err(|e| Error::QueryChunkResponseChannel(e))
}
#[tracing::instrument(level = "trace", skip(ctx, erasure_chunk), fields(subsystem = LOG_TARGET))]
async fn store_chunk<Context>(
ctx: &mut Context,
candidate_hash: CandidateHash,
@@ -1028,6 +1045,7 @@ where
}
/// Request the head data for a particular para.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_pending_availability<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -1050,6 +1068,7 @@ where
}
/// Query the validator set.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_validators<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -1072,6 +1091,7 @@ where
}
/// Query the hash of the `K` ancestors
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_k_ancestors<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -1096,6 +1116,7 @@ where
}
/// Query the session index of a relay parent
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_session_index_for_child<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -1118,6 +1139,7 @@ where
}
/// Queries up to k ancestors with the constraints of equiv session
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_up_to_k_ancestors_in_same_session<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -103,7 +103,7 @@ async fn overseer_send(
overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityDistributionMessage>,
msg: AvailabilityDistributionMessage,
) {
log::trace!("Sending message:\n{:?}", &msg);
tracing::trace!(msg = ?msg, "sending message");
overseer
.send(FromOverseer::Communication { msg })
.timeout(TIMEOUT)
@@ -114,13 +114,13 @@ async fn overseer_send(
async fn overseer_recv(
overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityDistributionMessage>,
) -> AllMessages {
log::trace!("Waiting for message ...");
tracing::trace!("waiting for message ...");
let msg = overseer
.recv()
.timeout(TIMEOUT)
.await
.expect("TIMEOUT is enough to recv.");
log::trace!("Received message:\n{:?}", &msg);
tracing::trace!(msg = ?msg, "received message");
msg
}
@@ -439,11 +439,11 @@ fn reputation_verification() {
let peer_b = PeerId::random();
assert_ne!(&peer_a, &peer_b);
log::trace!("peer A: {:?}", peer_a);
log::trace!("peer B: {:?}", peer_b);
tracing::trace!("peer A: {:?}", peer_a);
tracing::trace!("peer B: {:?}", peer_b);
log::trace!("candidate A: {:?}", candidates[0].hash());
log::trace!("candidate B: {:?}", candidates[1].hash());
tracing::trace!("candidate A: {:?}", candidates[0].hash());
tracing::trace!("candidate B: {:?}", candidates[1].hash());
overseer_signal(
&mut virtual_overseer,
@@ -627,7 +627,7 @@ fn reputation_verification() {
let mut candidates2 = candidates.clone();
// check if the availability store can provide the desired erasure chunks
for i in 0usize..2 {
log::trace!("0000");
tracing::trace!("0000");
let avail_data = make_available_data(&test_state, pov_block_a.clone());
let chunks =
derive_erasure_chunks_with_proofs(test_state.validators.len(), &avail_data);
@@ -652,10 +652,10 @@ fn reputation_verification() {
assert_eq!(chunks.len(), test_state.validators.len());
log::trace!("xxxx");
tracing::trace!("xxxx");
// retrieve a stored chunk
for (j, chunk) in chunks.into_iter().enumerate() {
log::trace!("yyyy i={}, j={}", i, j);
tracing::trace!("yyyy i={}, j={}", i, j);
if i != 0 {
// not a validator, so this never happens
break;
@@ -6,7 +6,8 @@ edition = "2018"
[dependencies]
futures = "0.3.8"
log = "0.4.11"
tracing = "0.1.21"
tracing-futures = "0.2.4"
parity-scale-codec = { version = "1.3.5", default-features = false, features = ["derive"] }
polkadot-primitives = { path = "../../../primitives" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
@@ -21,6 +22,7 @@ sp-application-crypto = { git = "https://github.com/paritytech/substrate", branc
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
maplit = "1.0.2"
log = "0.4.11"
env_logger = "0.8.2"
assert_matches = "1.4.0"
tempfile = "3.1.0"
@@ -25,7 +25,6 @@
use parity_scale_codec::{Decode, Encode};
use futures::{channel::oneshot, FutureExt};
use log::{debug, trace, warn};
use polkadot_subsystem::messages::*;
use polkadot_subsystem::{
ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, Subsystem, SubsystemContext, SubsystemResult,
@@ -79,7 +78,7 @@ impl BitfieldGossipMessage {
/// Data used to track information of peers and relay parents the
/// overseer ordered us to work on.
#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
struct ProtocolState {
/// track all active peers and their views
/// to determine what is relevant to them.
@@ -144,6 +143,7 @@ impl BitfieldDistribution {
}
/// Start processing work as passed on from the Overseer.
#[tracing::instrument(skip(self, ctx), fields(subsystem = LOG_TARGET))]
async fn run<Context>(self, mut ctx: Context)
where
Context: SubsystemContext<Message = BitfieldDistributionMessage>,
@@ -154,7 +154,7 @@ impl BitfieldDistribution {
let message = match ctx.recv().await {
Ok(message) => message,
Err(e) => {
debug!(target: LOG_TARGET, "Failed to receive a message from Overseer: {}, exiting", e);
tracing::debug!(target: LOG_TARGET, err = ?e, "Failed to receive a message from Overseer, exiting");
return;
},
};
@@ -162,7 +162,7 @@ impl BitfieldDistribution {
FromOverseer::Communication {
msg: BitfieldDistributionMessage::DistributeBitfield(hash, signed_availability),
} => {
trace!(target: LOG_TARGET, "Processing DistributeBitfield");
tracing::trace!(target: LOG_TARGET, "Processing DistributeBitfield");
if let Err(err) = handle_bitfield_distribution(
&mut ctx,
&mut state,
@@ -170,21 +170,21 @@ impl BitfieldDistribution {
hash,
signed_availability,
).await {
warn!(target: LOG_TARGET, "Failed to reply to `DistributeBitfield` message: {}", err);
tracing::warn!(target: LOG_TARGET, err = ?err, "Failed to reply to `DistributeBitfield` message");
}
}
FromOverseer::Communication {
msg: BitfieldDistributionMessage::NetworkBridgeUpdateV1(event),
} => {
trace!(target: LOG_TARGET, "Processing NetworkMessage");
tracing::trace!(target: LOG_TARGET, "Processing NetworkMessage");
// a network message was received
if let Err(e) = handle_network_msg(&mut ctx, &mut state, &self.metrics, event).await {
warn!(target: LOG_TARGET, "Failed to handle incoming network messages: {:?}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "Failed to handle incoming network messages");
}
}
FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { activated, deactivated })) => {
for relay_parent in activated {
trace!(target: LOG_TARGET, "Start {:?}", relay_parent);
tracing::trace!(target: LOG_TARGET, relay_parent = %relay_parent, "activated");
// query basic system parameters once
match query_basics(&mut ctx, relay_parent).await {
Ok(Some((validator_set, signing_context))) => {
@@ -203,22 +203,22 @@ impl BitfieldDistribution {
);
}
Err(e) => {
warn!(target: LOG_TARGET, "query_basics has failed: {}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "query_basics has failed");
}
_ => {},
}
}
for relay_parent in deactivated {
trace!(target: LOG_TARGET, "Stop {:?}", relay_parent);
tracing::trace!(target: LOG_TARGET, relay_parent = %relay_parent, "deactivated");
// defer the cleanup to the view change
}
}
FromOverseer::Signal(OverseerSignal::BlockFinalized(hash)) => {
trace!(target: LOG_TARGET, "Block finalized {:?}", hash);
tracing::trace!(target: LOG_TARGET, hash = %hash, "block finalized");
}
FromOverseer::Signal(OverseerSignal::Conclude) => {
trace!(target: LOG_TARGET, "Conclude");
tracing::trace!(target: LOG_TARGET, "Conclude");
return;
}
}
@@ -227,6 +227,7 @@ impl BitfieldDistribution {
}
/// Modify the reputation of a peer based on its behaviour.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn modify_reputation<Context>(
ctx: &mut Context,
peer: PeerId,
@@ -235,7 +236,7 @@ async fn modify_reputation<Context>(
where
Context: SubsystemContext<Message = BitfieldDistributionMessage>,
{
trace!(target: LOG_TARGET, "Reputation change of {:?} for peer {:?}", rep, peer);
tracing::trace!(target: LOG_TARGET, rep = ?rep, peer_id = %peer, "reputation change");
ctx.send_message(AllMessages::NetworkBridge(
NetworkBridgeMessage::ReportPeer(peer, rep),
))
@@ -245,6 +246,7 @@ where
/// Distribute a given valid and signature checked bitfield message.
///
/// For this variant the source is this node.
#[tracing::instrument(level = "trace", skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_bitfield_distribution<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -260,17 +262,17 @@ where
let job_data: &mut _ = if let Some(ref mut job_data) = job_data {
job_data
} else {
trace!(
tracing::trace!(
target: LOG_TARGET,
"Not supposed to work on relay parent {} related data",
relay_parent
relay_parent = %relay_parent,
"Not supposed to work on relay parent related data",
);
return Ok(());
};
let validator_set = &job_data.validator_set;
if validator_set.is_empty() {
trace!(target: LOG_TARGET, "Validator set for {:?} is empty", relay_parent);
tracing::trace!(target: LOG_TARGET, relay_parent = %relay_parent, "validator set is empty");
return Ok(());
}
@@ -278,7 +280,7 @@ where
let validator = if let Some(validator) = validator_set.get(validator_index) {
validator.clone()
} else {
trace!(target: LOG_TARGET, "Could not find a validator for index {}", validator_index);
tracing::trace!(target: LOG_TARGET, "Could not find a validator for index {}", validator_index);
return Ok(());
};
@@ -298,6 +300,7 @@ where
/// Distribute a given valid and signature checked bitfield message.
///
/// Can be originated by another subsystem or received via network from another peer.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn relay_message<Context>(
ctx: &mut Context,
job_data: &mut PerRelayParentData,
@@ -342,10 +345,10 @@ where
.collect::<Vec<PeerId>>();
if interested_peers.is_empty() {
trace!(
tracing::trace!(
target: LOG_TARGET,
"No peers are interested in gossip for relay parent {:?}",
message.relay_parent
relay_parent = %message.relay_parent,
"no peers are interested in gossip for relay parent",
);
} else {
ctx.send_message(AllMessages::NetworkBridge(
@@ -360,6 +363,7 @@ where
}
/// Handle an incoming message from a peer.
#[tracing::instrument(level = "trace", skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn process_incoming_peer_message<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -385,10 +389,10 @@ where
let validator_set = &job_data.validator_set;
if validator_set.is_empty() {
trace!(
tracing::trace!(
target: LOG_TARGET,
"Validator set for relay parent {:?} is empty",
&message.relay_parent
relay_parent = %message.relay_parent,
"Validator set is empty",
);
return modify_reputation(ctx, origin, COST_MISSING_PEER_SESSION_KEY).await;
}
@@ -427,10 +431,10 @@ where
// only relay_message a message of a validator once
if one_per_validator.get(&validator).is_some() {
trace!(
tracing::trace!(
target: LOG_TARGET,
"Already received a message for validator at index {}",
validator_index
validator_index,
"already received a message for validator",
);
modify_reputation(ctx, origin, BENEFIT_VALID_MESSAGE).await?;
return Ok(());
@@ -447,6 +451,7 @@ where
/// Deal with network bridge updates and track what needs to be tracked
/// which depends on the message type received.
#[tracing::instrument(level = "trace", skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_network_msg<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -474,7 +479,7 @@ where
NetworkBridgeEvent::PeerMessage(remote, message) => {
match message {
protocol_v1::BitfieldDistributionMessage::Bitfield(relay_parent, bitfield) => {
trace!(target: LOG_TARGET, "Received bitfield gossip from peer {:?}", &remote);
tracing::trace!(target: LOG_TARGET, peer_id = %remote, "received bitfield gossip from peer");
let gossiped_bitfield = BitfieldGossipMessage {
relay_parent,
signed_availability: bitfield,
@@ -488,13 +493,15 @@ where
}
/// Handle the changes necassary when our view changes.
#[tracing::instrument(level = "trace", fields(subsystem = LOG_TARGET))]
fn handle_our_view_change(state: &mut ProtocolState, view: View) -> SubsystemResult<()> {
let old_view = std::mem::replace(&mut (state.view), view);
for added in state.view.difference(&old_view) {
if !state.per_relay_parent.contains_key(&added) {
warn!(
tracing::warn!(
target: LOG_TARGET,
added = %added,
"Our view contains {} but the overseer never told use we should work on this",
&added
);
@@ -510,6 +517,7 @@ fn handle_our_view_change(state: &mut ProtocolState, view: View) -> SubsystemRes
// Send the difference between two views which were not sent
// to that particular peer.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn handle_peer_view_change<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -560,6 +568,7 @@ where
}
/// Send a gossip message and track it in the per relay parent data.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn send_tracked_gossip_message<Context>(
ctx: &mut Context,
state: &mut ProtocolState,
@@ -610,6 +619,7 @@ where
}
/// Query our validator set and signing context for a particular relay parent.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn query_basics<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -639,7 +649,7 @@ where
SigningContext { parent_hash: relay_parent, session_index: s },
))),
(Err(e), _) | (_, Err(e)) => {
warn!(target: LOG_TARGET, "Failed to fetch basics from runtime API: {:?}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "Failed to fetch basics from runtime API");
Ok(None)
}
}
+2 -1
View File
@@ -7,7 +7,8 @@ edition = "2018"
[dependencies]
async-trait = "0.1.41"
futures = "0.3.8"
log = "0.4.11"
tracing = "0.1.21"
tracing-futures = "0.2.4"
polkadot-primitives = { path = "../../../primitives" }
parity-scale-codec = { version = "1.3.5", default-features = false, features = ["derive"] }
sc-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
+24 -12
View File
@@ -68,7 +68,7 @@ const MALFORMED_VIEW_COST: ReputationChange
= ReputationChange::new(-500, "Malformed view");
// network bridge log target
const TARGET: &'static str = "network_bridge";
const LOG_TARGET: &'static str = "network_bridge";
/// Messages received on the network.
#[derive(Debug, Encode, Decode, Clone)]
@@ -264,6 +264,7 @@ enum Action {
Nop,
}
#[tracing::instrument(level = "trace", fields(subsystem = LOG_TARGET))]
fn action_from_overseer_message(
res: polkadot_subsystem::SubsystemResult<FromOverseer<NetworkBridgeMessage>>,
) -> Action {
@@ -286,16 +287,17 @@ fn action_from_overseer_message(
Ok(FromOverseer::Signal(OverseerSignal::BlockFinalized(_)))
=> Action::Nop,
Err(e) => {
log::warn!(target: TARGET, "Shutting down Network Bridge due to error {:?}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "Shutting down Network Bridge due to error");
Action::Abort
}
}
}
#[tracing::instrument(level = "trace", fields(subsystem = LOG_TARGET))]
fn action_from_network_message(event: Option<NetworkEvent>) -> Action {
match event {
None => {
log::info!(target: TARGET, "Shutting down Network Bridge: underlying event stream concluded");
tracing::info!(target: LOG_TARGET, "Shutting down Network Bridge: underlying event stream concluded");
Action::Abort
}
Some(NetworkEvent::Dht(_)) => Action::Nop,
@@ -350,6 +352,7 @@ fn construct_view(live_heads: &[Hash]) -> View {
View(live_heads.iter().rev().take(MAX_VIEW_HEADS).cloned().collect())
}
#[tracing::instrument(level = "trace", skip(net, ctx, validation_peers, collation_peers), fields(subsystem = LOG_TARGET))]
async fn update_view(
net: &mut impl Network,
ctx: &mut impl SubsystemContext<Message = NetworkBridgeMessage>,
@@ -379,7 +382,7 @@ async fn update_view(
NetworkBridgeEvent::OurViewChange(new_view.clone()),
ctx,
).await {
log::warn!(target: TARGET, "Aborting - Failure to dispatch messages to overseer");
tracing::warn!(target: LOG_TARGET, err = ?e, "Aborting - Failure to dispatch messages to overseer");
return Err(e)
}
@@ -387,7 +390,7 @@ async fn update_view(
NetworkBridgeEvent::OurViewChange(new_view.clone()),
ctx,
).await {
log::warn!(target: TARGET, "Aborting - Failure to dispatch messages to overseer");
tracing::warn!(target: LOG_TARGET, err = ?e, "Aborting - Failure to dispatch messages to overseer");
return Err(e)
}
@@ -396,6 +399,7 @@ async fn update_view(
// Handle messages on a specific peer-set. The peer is expected to be connected on that
// peer-set.
#[tracing::instrument(level = "trace", skip(peers, messages, net), fields(subsystem = LOG_TARGET))]
async fn handle_peer_messages<M>(
peer: PeerId,
peers: &mut HashMap<PeerId, PeerData>,
@@ -442,6 +446,7 @@ async fn handle_peer_messages<M>(
Ok(outgoing_messages)
}
#[tracing::instrument(level = "trace", skip(net, peers), fields(subsystem = LOG_TARGET))]
async fn send_validation_message<I>(
net: &mut impl Network,
peers: I,
@@ -454,6 +459,7 @@ async fn send_validation_message<I>(
send_message(net, peers, PeerSet::Validation, message).await
}
#[tracing::instrument(level = "trace", skip(net, peers), fields(subsystem = LOG_TARGET))]
async fn send_collation_message<I>(
net: &mut impl Network,
peers: I,
@@ -516,6 +522,7 @@ async fn dispatch_collation_event_to_all(
dispatch_collation_events_to_all(std::iter::once(event), ctx).await
}
#[tracing::instrument(level = "trace", skip(events, ctx), fields(subsystem = LOG_TARGET))]
async fn dispatch_validation_events_to_all<I>(
events: I,
ctx: &mut impl SubsystemContext<Message=NetworkBridgeMessage>,
@@ -547,6 +554,7 @@ async fn dispatch_validation_events_to_all<I>(
ctx.send_messages(events.into_iter().flat_map(messages_for)).await
}
#[tracing::instrument(level = "trace", skip(events, ctx), fields(subsystem = LOG_TARGET))]
async fn dispatch_collation_events_to_all<I>(
events: I,
ctx: &mut impl SubsystemContext<Message=NetworkBridgeMessage>,
@@ -564,6 +572,7 @@ async fn dispatch_collation_events_to_all<I>(
ctx.send_messages(events.into_iter().flat_map(messages_for)).await
}
#[tracing::instrument(skip(network_service, authority_discovery_service, ctx), fields(subsystem = LOG_TARGET))]
async fn run_network<N, AD>(
mut network_service: N,
mut authority_discovery_service: AD,
@@ -686,7 +695,7 @@ where
};
if let Err(e) = res {
log::warn!("Aborting - Failure to dispatch messages to overseer");
tracing::warn!(err = ?e, "Aborting - Failure to dispatch messages to overseer");
return Err(e);
}
}
@@ -713,8 +722,9 @@ where
};
if let Err(e) = res {
log::warn!(
target: TARGET,
tracing::warn!(
target: LOG_TARGET,
err = ?e,
"Aborting - Failure to dispatch messages to overseer",
);
return Err(e)
@@ -734,8 +744,9 @@ where
events,
&mut ctx,
).await {
log::warn!(
target: TARGET,
tracing::warn!(
target: LOG_TARGET,
err = ?e,
"Aborting - Failure to dispatch messages to overseer",
);
return Err(e)
@@ -754,8 +765,9 @@ where
events,
&mut ctx,
).await {
log::warn!(
target: TARGET,
tracing::warn!(
target: LOG_TARGET,
err = ?e,
"Aborting - Failure to dispatch messages to overseer",
);
return Err(e)
@@ -29,6 +29,7 @@ use polkadot_node_network_protocol::PeerId;
use polkadot_primitives::v1::{AuthorityDiscoveryId, Block, Hash};
const PRIORITY_GROUP: &'static str = "parachain_validators";
const LOG_TARGET: &str = "ValidatorDiscovery";
/// An abstraction over networking for the purposes of validator discovery service.
#[async_trait]
@@ -163,6 +164,7 @@ impl<N: Network, AD: AuthorityDiscovery> Service<N, AD> {
/// Find connected validators using the given `validator_ids`.
///
/// Returns a [`HashMap`] that contains the found [`AuthorityDiscoveryId`]'s and their associated [`PeerId`]'s.
#[tracing::instrument(level = "trace", skip(self, authority_discovery_service), fields(subsystem = LOG_TARGET))]
async fn find_connected_validators(
&mut self,
validator_ids: &[AuthorityDiscoveryId],
@@ -201,6 +203,7 @@ impl<N: Network, AD: AuthorityDiscovery> Service<N, AD> {
/// This method will also clean up all previously revoked requests.
/// it takes `network_service` and `authority_discovery_service` by value
/// and returns them as a workaround for the Future: Send requirement imposed by async fn impl.
#[tracing::instrument(level = "trace", skip(self, connected, revoke, network_service, authority_discovery_service), fields(subsystem = LOG_TARGET))]
pub async fn on_request(
&mut self,
validator_ids: Vec<AuthorityDiscoveryId>,
@@ -283,7 +286,7 @@ impl<N: Network, AD: AuthorityDiscovery> Service<N, AD> {
PRIORITY_GROUP.to_owned(),
multiaddr_to_add,
).await {
log::warn!(target: super::TARGET, "AuthorityDiscoveryService returned an invalid multiaddress: {}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "AuthorityDiscoveryService returned an invalid multiaddress");
}
// the addresses are known to be valid
let _ = network_service.remove_from_priority_group(PRIORITY_GROUP.to_owned(), multiaddr_to_remove).await;
@@ -304,6 +307,7 @@ impl<N: Network, AD: AuthorityDiscovery> Service<N, AD> {
}
/// Should be called when a peer connected.
#[tracing::instrument(level = "trace", skip(self, authority_discovery_service), fields(subsystem = LOG_TARGET))]
pub async fn on_peer_connected(&mut self, peer_id: &PeerId, authority_discovery_service: &mut AD) {
// check if it's an authority we've been waiting for
let maybe_authority = authority_discovery_service.get_authority_id_by_peer_id(peer_id.clone()).await;
@@ -6,7 +6,8 @@ edition = "2018"
[dependencies]
futures = "0.3.8"
log = "0.4.11"
tracing = "0.1.21"
tracing-futures = "0.2.4"
thiserror = "1.0.22"
@@ -16,6 +17,7 @@ polkadot-node-subsystem-util = { path = "../../subsystem-util" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
[dev-dependencies]
log = "0.4.11"
env_logger = "0.8.2"
assert_matches = "1.4.0"
smallvec = "1.5.0"
@@ -19,7 +19,6 @@ use std::collections::HashMap;
use super::{LOG_TARGET, Result};
use futures::{StreamExt, task::Poll};
use log::warn;
use polkadot_primitives::v1::{
CollatorId, CoreIndex, CoreState, Hash, Id as ParaId, CandidateReceipt,
@@ -138,6 +137,7 @@ struct State {
/// or the relay-parent isn't in the active-leaves set, we ignore the message
/// as it must be invalid in that case - although this indicates a logic error
/// elsewhere in the node.
#[tracing::instrument(level = "trace", skip(ctx, state, pov), fields(subsystem = LOG_TARGET))]
async fn distribute_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -152,10 +152,10 @@ where
// This collation is not in the active-leaves set.
if !state.view.contains(&relay_parent) {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Distribute collation message parent {:?} is outside of our view",
relay_parent,
relay_parent = %relay_parent,
"distribute collation message parent is outside of our view",
);
return Ok(());
@@ -171,9 +171,11 @@ where
let (our_core, num_cores) = match determine_core(ctx, id, relay_parent).await? {
Some(core) => core,
None => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Looks like no core is assigned to {:?} at {:?}", id, relay_parent,
para_id = %id,
relay_parent = %relay_parent,
"looks like no core is assigned to {} at {}", id, relay_parent,
);
return Ok(());
}
@@ -183,9 +185,10 @@ where
let our_validators = match determine_our_validators(ctx, our_core, num_cores, relay_parent).await? {
Some(validators) => validators,
None => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"There are no validators assigned to {:?} core", our_core,
core = ?our_core,
"there are no validators assigned to core",
);
return Ok(());
@@ -217,6 +220,7 @@ where
/// Get the Id of the Core that is assigned to the para being collated on if any
/// and the total number of cores.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn determine_core<Context>(
ctx: &mut Context,
para_id: ParaId,
@@ -241,6 +245,7 @@ where
/// Figure out a group of validators assigned to the para being collated on.
///
/// This returns validators for the current group and the next group.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn determine_our_validators<Context>(
ctx: &mut Context,
core_index: CoreIndex,
@@ -280,6 +285,7 @@ where
}
/// Issue a `Declare` collation message to a set of peers.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn declare<Context>(
ctx: &mut Context,
state: &mut State,
@@ -302,6 +308,7 @@ where
/// Issue a connection request to a set of validators and
/// revoke the previous connection request.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn connect_to_validators<Context>(
ctx: &mut Context,
relay_parent: Hash,
@@ -327,6 +334,7 @@ where
}
/// Advertise collation to a set of relay chain validators.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn advertise_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -358,6 +366,7 @@ where
}
/// The main incoming message dispatching switch.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn process_msg<Context>(
ctx: &mut Context,
state: &mut State,
@@ -377,39 +386,39 @@ where
Some(id) if receipt.descriptor.para_id != id => {
// If the ParaId of a collation requested to be distributed does not match
// the one we expect, we ignore the message.
warn!(
tracing::warn!(
target: LOG_TARGET,
"DistributeCollation message for para {:?} while collating on {:?}",
receipt.descriptor.para_id,
id,
para_id = %receipt.descriptor.para_id,
collating_on = %id,
"DistributeCollation for unexpected para_id",
);
}
Some(id) => {
distribute_collation(ctx, state, id, receipt, pov).await?;
}
None => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"DistributeCollation message for para {:?} while not collating on any",
receipt.descriptor.para_id,
para_id = %receipt.descriptor.para_id,
"DistributeCollation message while not collating on any",
);
}
}
}
FetchCollation(_, _, _, _) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"FetchCollation message is not expected on the collator side of the protocol",
);
}
ReportCollator(_) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"ReportCollator message is not expected on the collator side of the protocol",
);
}
NoteGoodCollation(_) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"NoteGoodCollation message is not expected on the collator side of the protocol",
);
@@ -420,9 +429,10 @@ where
state,
event,
).await {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Failed to handle incoming network message: {:?}", e,
err = ?e,
"Failed to handle incoming network message",
);
}
},
@@ -432,6 +442,7 @@ where
}
/// Issue a response to a previously requested collation.
#[tracing::instrument(level = "trace", skip(ctx, state, pov), fields(subsystem = LOG_TARGET))]
async fn send_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -462,6 +473,7 @@ where
}
/// A networking messages switch.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_incoming_peer_message<Context>(
ctx: &mut Context,
state: &mut State,
@@ -475,13 +487,13 @@ where
match msg {
Declare(_) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Declare message is not expected on the collator side of the protocol",
);
}
AdvertiseCollation(_, _) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"AdvertiseCollation message is not expected on the collator side of the protocol",
);
@@ -494,24 +506,25 @@ where
send_collation(ctx, state, request_id, origin, collation.0, collation.1).await?;
}
} else {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Received a RequestCollation for {:?} while collating on {:?}",
para_id, our_para_id,
for_para_id = %para_id,
our_para_id = %our_para_id,
"received a RequestCollation for unexpected para_id",
);
}
}
None => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Received a RequestCollation for {:?} while not collating on any para",
para_id,
for_para_id = %para_id,
"received a RequestCollation while not collating on any para",
);
}
}
}
Collation(_, _, _) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Collation message is not expected on the collator side of the protocol",
);
@@ -522,6 +535,7 @@ where
}
/// Our view has changed.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_peer_view_change<Context>(
ctx: &mut Context,
state: &mut State,
@@ -549,6 +563,7 @@ where
/// A validator is connected.
///
/// `Declare` that we are a collator with a given `CollatorId`.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_validator_connected<Context>(
ctx: &mut Context,
state: &mut State,
@@ -571,6 +586,7 @@ where
}
/// Bridge messages switch.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_network_msg<Context>(
ctx: &mut Context,
state: &mut State,
@@ -605,6 +621,7 @@ where
}
/// Handles our view changes.
#[tracing::instrument(level = "trace", skip(state), fields(subsystem = LOG_TARGET))]
async fn handle_our_view_change(
state: &mut State,
view: View,
@@ -624,6 +641,7 @@ async fn handle_our_view_change(
}
/// The collator protocol collator side main loop.
#[tracing::instrument(skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
pub(crate) async fn run<Context>(
mut ctx: Context,
our_id: CollatorId,
@@ -646,10 +664,10 @@ where
if let Some(mut request) = state.last_connection_request.take() {
while let Poll::Ready(Some((validator_id, peer_id))) = futures::poll!(request.next()) {
if let Err(err) = handle_validator_connected(&mut ctx, &mut state, peer_id, validator_id).await {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Failed to declare our collator id: {:?}",
err,
err = ?err,
"Failed to declare our collator id",
);
}
}
@@ -661,7 +679,7 @@ where
match msg? {
Communication { msg } => {
if let Err(e) = process_msg(&mut ctx, &mut state, msg).await {
warn!(target: LOG_TARGET, "Failed to process message: {}", e);
tracing::warn!(target: LOG_TARGET, err = ?e, "Failed to process message");
}
},
Signal(ActiveLeaves(_update)) => {}
@@ -682,7 +700,6 @@ mod tests {
use assert_matches::assert_matches;
use futures::{executor, future, Future};
use log::trace;
use smallvec::smallvec;
use sp_core::crypto::Pair;
@@ -839,7 +856,7 @@ mod tests {
overseer: &mut test_helpers::TestSubsystemContextHandle<CollatorProtocolMessage>,
msg: CollatorProtocolMessage,
) {
trace!("Sending message:\n{:?}", &msg);
tracing::trace!(msg = ?msg, "sending message");
overseer
.send(FromOverseer::Communication { msg })
.timeout(TIMEOUT)
@@ -854,7 +871,7 @@ mod tests {
.await
.expect(&format!("{:?} is more than enough to receive messages", TIMEOUT));
trace!("Received message:\n{:?}", &msg);
tracing::trace!(msg = ?msg, "received message");
msg
}
@@ -863,7 +880,7 @@ mod tests {
overseer: &mut test_helpers::TestSubsystemContextHandle<CollatorProtocolMessage>,
timeout: Duration,
) -> Option<AllMessages> {
trace!("Waiting for message...");
tracing::trace!("waiting for message...");
overseer
.recv()
.timeout(timeout)
@@ -21,7 +21,6 @@
use std::time::Duration;
use futures::{channel::oneshot, FutureExt, TryFutureExt};
use log::trace;
use thiserror::Error;
use polkadot_subsystem::{
@@ -96,6 +95,7 @@ impl CollatorProtocolSubsystem {
}
}
#[tracing::instrument(skip(self, ctx), fields(subsystem = LOG_TARGET))]
async fn run<Context>(self, ctx: Context) -> Result<()>
where
Context: SubsystemContext<Message = CollatorProtocolMessage>,
@@ -135,13 +135,16 @@ where
}
/// Modify the reputation of a peer based on its behavior.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn modify_reputation<Context>(ctx: &mut Context, peer: PeerId, rep: Rep) -> Result<()>
where
Context: SubsystemContext<Message = CollatorProtocolMessage>,
{
trace!(
tracing::trace!(
target: LOG_TARGET,
"Reputation change of {:?} for peer {:?}", rep, peer,
rep = ?rep,
peer_id = %peer,
"reputation change for peer",
);
ctx.send_message(AllMessages::NetworkBridge(
@@ -25,7 +25,6 @@ use futures::{
future::BoxFuture,
stream::FuturesUnordered,
};
use log::{trace, warn};
use polkadot_primitives::v1::{
Id as ParaId, CandidateReceipt, CollatorId, Hash, PoV,
@@ -188,6 +187,7 @@ struct State {
}
/// Another subsystem has requested to fetch collations on a particular leaf for some para.
#[tracing::instrument(level = "trace", skip(ctx, state, tx), fields(subsystem = LOG_TARGET))]
async fn fetch_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -206,9 +206,10 @@ where
if let Err(e) = tx.send((collation.1.clone(), collation.2.clone())) {
// We do not want this to be fatal because the receving subsystem
// may have closed the results channel for some reason.
trace!(
tracing::trace!(
target: LOG_TARGET,
"Failed to send collation: {:?}", e,
err = ?e,
"Failed to send collation",
);
}
return Ok(());
@@ -238,6 +239,7 @@ where
}
/// Report a collator for some malicious actions.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn report_collator<Context>(
ctx: &mut Context,
state: &mut State,
@@ -259,6 +261,7 @@ where
}
/// Some other subsystem has reported a collator as a good one, bump reputation.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn note_good_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -279,6 +282,7 @@ where
/// A peer's view has changed. A number of things should be done:
/// - Ongoing collation requests have to be cancelled.
/// - Advertisements by this peer that are no longer relevant have to be removed.
#[tracing::instrument(level = "trace", skip(state), fields(subsystem = LOG_TARGET))]
async fn handle_peer_view_change(
state: &mut State,
peer_id: PeerId,
@@ -320,6 +324,7 @@ async fn handle_peer_view_change(
/// - Cancel all ongoing requests
/// - Reply to interested parties if any
/// - Store collation.
#[tracing::instrument(level = "trace", skip(ctx, state, pov), fields(subsystem = LOG_TARGET))]
async fn received_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -368,6 +373,7 @@ where
/// - Check if the requested collation is in our view.
/// - Update PerRequest records with the `result` field if necessary.
/// And as such invocations of this function may rely on that.
#[tracing::instrument(level = "trace", skip(ctx, state, result), fields(subsystem = LOG_TARGET))]
async fn request_collation<Context>(
ctx: &mut Context,
state: &mut State,
@@ -380,19 +386,23 @@ where
Context: SubsystemContext<Message = CollatorProtocolMessage>
{
if !state.view.contains(&relay_parent) {
trace!(
tracing::trace!(
target: LOG_TARGET,
"Collation by {} on {} on relay parent {} is no longer in view",
peer_id, para_id, relay_parent,
peer_id = %peer_id,
para_id = %para_id,
relay_parent = %relay_parent,
"collation is no longer in view",
);
return Ok(());
}
if state.requested_collations.contains_key(&(relay_parent, para_id.clone(), peer_id.clone())) {
trace!(
tracing::trace!(
target: LOG_TARGET,
"Collation by {} on {} on relay parent {} has already been requested",
peer_id, para_id, relay_parent,
peer_id = %peer_id,
para_id = %para_id,
relay_parent = %relay_parent,
"collation has already been requested",
);
return Ok(());
}
@@ -436,6 +446,7 @@ where
}
/// Notify `CandidateSelectionSubsystem` that a collation has been advertised.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn notify_candidate_selection<Context>(
ctx: &mut Context,
collator: CollatorId,
@@ -457,6 +468,7 @@ where
}
/// Networking message has been received.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn process_incoming_peer_message<Context>(
ctx: &mut Context,
state: &mut State,
@@ -495,6 +507,7 @@ where
/// A leaf has become inactive so we want to
/// - Cancel all ongoing collation requests that are on top of that leaf.
/// - Remove all stored collations relevant to that leaf.
#[tracing::instrument(level = "trace", skip(state), fields(subsystem = LOG_TARGET))]
async fn remove_relay_parent(
state: &mut State,
relay_parent: Hash,
@@ -520,6 +533,7 @@ async fn remove_relay_parent(
}
/// Our view has changed.
#[tracing::instrument(level = "trace", skip(state), fields(subsystem = LOG_TARGET))]
async fn handle_our_view_change(
state: &mut State,
view: View,
@@ -543,6 +557,7 @@ async fn handle_our_view_change(
}
/// A request has timed out.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn request_timed_out<Context>(
ctx: &mut Context,
state: &mut State,
@@ -568,6 +583,7 @@ where
}
/// Bridge event switch.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_network_msg<Context>(
ctx: &mut Context,
state: &mut State,
@@ -601,6 +617,7 @@ where
}
/// The main message receiver switch.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn process_msg<Context>(
ctx: &mut Context,
msg: CollatorProtocolMessage,
@@ -613,13 +630,14 @@ where
match msg {
CollateOn(id) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"CollateOn({}) message is not expected on the validator side of the protocol", id,
para_id = %id,
"CollateOn message is not expected on the validator side of the protocol",
);
}
DistributeCollation(_, _) => {
warn!(
tracing::warn!(
target: LOG_TARGET,
"DistributeCollation message is not expected on the validator side of the protocol",
);
@@ -639,9 +657,10 @@ where
state,
event,
).await {
warn!(
tracing::warn!(
target: LOG_TARGET,
"Failed to handle incoming network message: {:?}", e,
err = ?e,
"Failed to handle incoming network message",
);
}
}
@@ -651,6 +670,7 @@ where
}
/// The main run loop.
#[tracing::instrument(skip(ctx, metrics), fields(subsystem = LOG_TARGET))]
pub(crate) async fn run<Context>(
mut ctx: Context,
request_timeout: Duration,
@@ -671,7 +691,7 @@ where
loop {
if let Poll::Ready(msg) = futures::poll!(ctx.recv()) {
let msg = msg?;
trace!(target: LOG_TARGET, "Received a message {:?}", msg);
tracing::trace!(target: LOG_TARGET, msg = ?msg, "received a message");
match msg {
Communication { msg } => process_msg(&mut ctx, msg, &mut state).await?,
@@ -687,7 +707,7 @@ where
// if the chain has not moved on yet.
match request {
CollationRequestResult::Timeout(id) => {
trace!(target: LOG_TARGET, "Request timed out {}", id);
tracing::trace!(target: LOG_TARGET, id, "request timed out");
request_timed_out(&mut ctx, &mut state, id).await?;
}
CollationRequestResult::Received(id) => {
@@ -784,7 +804,7 @@ mod tests {
overseer: &mut test_helpers::TestSubsystemContextHandle<CollatorProtocolMessage>,
msg: CollatorProtocolMessage,
) {
log::trace!("Sending message:\n{:?}", &msg);
tracing::trace!("Sending message:\n{:?}", &msg);
overseer
.send(FromOverseer::Communication { msg })
.timeout(TIMEOUT)
@@ -799,7 +819,7 @@ mod tests {
.await
.expect(&format!("{:?} is enough to receive messages.", TIMEOUT));
log::trace!("Received message:\n{:?}", &msg);
tracing::trace!("Received message:\n{:?}", &msg);
msg
}
@@ -808,7 +828,7 @@ mod tests {
overseer: &mut test_helpers::TestSubsystemContextHandle<CollatorProtocolMessage>,
timeout: Duration,
) -> Option<AllMessages> {
log::trace!("Waiting for message...");
tracing::trace!("Waiting for message...");
overseer
.recv()
.timeout(timeout)
@@ -826,7 +846,7 @@ mod tests {
} = test_harness;
let pair = CollatorPair::generate().0;
log::trace!("activating");
tracing::trace!("activating");
overseer_send(
&mut virtual_overseer,
@@ -6,7 +6,8 @@ edition = "2018"
[dependencies]
futures = "0.3.8"
log = "0.4.11"
tracing = "0.1.21"
tracing-futures = "0.2.4"
polkadot-primitives = { path = "../../../primitives" }
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
@@ -116,6 +116,7 @@ fn send_pov_message(relay_parent: Hash, pov_hash: Hash, pov: PoV)
/// Handles the signal. If successful, returns `true` if the subsystem should conclude,
/// `false` otherwise.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_signal(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -134,10 +135,10 @@ async fn handle_signal(
let n_validators = match vals_rx.await? {
Ok(v) => v.len(),
Err(e) => {
log::warn!(
tracing::warn!(
target: LOG_TARGET,
"Error fetching validators from runtime API for active leaf: {:?}",
e
err = ?e,
"Error fetching validators from runtime API for active leaf",
);
// Not adding bookkeeping here might make us behave funny, but we
@@ -169,6 +170,7 @@ async fn handle_signal(
/// Notify peers that we are awaiting a given PoV hash.
///
/// This only notifies peers who have the relay parent in their view.
#[tracing::instrument(level = "trace", skip(peers, ctx), fields(subsystem = LOG_TARGET))]
async fn notify_all_we_are_awaiting(
peers: &mut HashMap<PeerId, PeerState>,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -195,6 +197,7 @@ async fn notify_all_we_are_awaiting(
}
/// Notify one peer about everything we're awaiting at a given relay-parent.
#[tracing::instrument(level = "trace", skip(ctx, relay_parent_state), fields(subsystem = LOG_TARGET))]
async fn notify_one_we_are_awaiting_many(
peer: &PeerId,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -219,6 +222,7 @@ async fn notify_one_we_are_awaiting_many(
}
/// Distribute a PoV to peers who are awaiting it.
#[tracing::instrument(level = "trace", skip(peers, ctx, metrics, pov), fields(subsystem = LOG_TARGET))]
async fn distribute_to_awaiting(
peers: &mut HashMap<PeerId, PeerState>,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -255,6 +259,7 @@ async fn distribute_to_awaiting(
}
/// Handles a `FetchPoV` message.
#[tracing::instrument(level = "trace", skip(ctx, state, response_sender), fields(subsystem = LOG_TARGET))]
async fn handle_fetch(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -286,8 +291,10 @@ async fn handle_fetch(
}
if relay_parent_state.fetching.len() > 2 * relay_parent_state.n_validators {
log::warn!("Other subsystems have requested PoV distribution to \
fetch more PoVs than reasonably expected: {}", relay_parent_state.fetching.len());
tracing::warn!(
relay_parent_state.fetching.len = relay_parent_state.fetching.len(),
"other subsystems have requested PoV distribution to fetch more PoVs than reasonably expected",
);
return Ok(());
}
@@ -301,6 +308,7 @@ async fn handle_fetch(
}
/// Handles a `DistributePoV` message.
#[tracing::instrument(level = "trace", skip(ctx, state, pov), fields(subsystem = LOG_TARGET))]
async fn handle_distribute(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -336,6 +344,7 @@ async fn handle_distribute(
}
/// Report a reputation change for a peer.
#[tracing::instrument(level = "trace", skip(ctx), fields(subsystem = LOG_TARGET))]
async fn report_peer(
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
peer: PeerId,
@@ -345,6 +354,7 @@ async fn report_peer(
}
/// Handle a notification from a peer that they are awaiting some PoVs.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_awaiting(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -359,7 +369,7 @@ async fn handle_awaiting(
let relay_parent_state = match state.relay_parent_state.get_mut(&relay_parent) {
None => {
log::warn!("PoV Distribution relay parent state out-of-sync with our view");
tracing::warn!("PoV Distribution relay parent state out-of-sync with our view");
return Ok(());
}
Some(s) => s,
@@ -399,6 +409,7 @@ async fn handle_awaiting(
/// Handle an incoming PoV from our peer. Reports them if unexpected, rewards them if not.
///
/// Completes any requests awaiting that PoV.
#[tracing::instrument(level = "trace", skip(ctx, state, pov), fields(subsystem = LOG_TARGET))]
async fn handle_incoming_pov(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -466,6 +477,7 @@ async fn handle_incoming_pov(
}
/// Handles a network bridge update.
#[tracing::instrument(level = "trace", skip(ctx, state), fields(subsystem = LOG_TARGET))]
async fn handle_network_update(
state: &mut State,
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -537,6 +549,7 @@ impl PoVDistribution {
Self { metrics }
}
#[tracing::instrument(skip(self, ctx), fields(subsystem = LOG_TARGET))]
async fn run(
self,
mut ctx: impl SubsystemContext<Message = PoVDistributionMessage>,
@@ -7,7 +7,8 @@ edition = "2018"
[dependencies]
futures = "0.3.8"
log = "0.4.11"
tracing = "0.1.21"
tracing-futures = "0.2.4"
polkadot-primitives = { path = "../../../primitives" }
node-primitives = { package = "polkadot-node-primitives", path = "../../primitives" }
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -111,7 +111,7 @@ impl VcPerPeerTracker {
/// based on a message that we have sent it from our local pool.
fn note_local(&mut self, h: CandidateHash) {
if !note_hash(&mut self.local_observed, h) {
log::warn!("Statement distribution is erroneously attempting to distribute more \
tracing::warn!("Statement distribution is erroneously attempting to distribute more \
than {} candidate(s) per validator index. Ignoring", VC_THRESHOLD);
}
}
@@ -164,6 +164,7 @@ impl PeerRelayParentKnowledge {
///
/// This returns `Some(true)` if this is the first time the peer has become aware of a
/// candidate with the given hash.
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn send(&mut self, fingerprint: &(CompactStatement, ValidatorIndex)) -> Option<bool> {
let already_known = self.sent_statements.contains(fingerprint)
|| self.received_statements.contains(fingerprint);
@@ -212,6 +213,7 @@ impl PeerRelayParentKnowledge {
///
/// This returns `Ok(true)` if this is the first time the peer has become aware of a
/// candidate with given hash.
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn receive(
&mut self,
fingerprint: &(CompactStatement, ValidatorIndex),
@@ -278,6 +280,7 @@ impl PeerData {
///
/// This returns `Some(true)` if this is the first time the peer has become aware of a
/// candidate with the given hash.
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn send(
&mut self,
relay_parent: &Hash,
@@ -302,6 +305,7 @@ impl PeerData {
///
/// This returns `Ok(true)` if this is the first time the peer has become aware of a
/// candidate with given hash.
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn receive(
&mut self,
relay_parent: &Hash,
@@ -411,6 +415,7 @@ impl ActiveHeadData {
///
/// Any other statements or those that reference a candidate we are not aware of cannot be accepted
/// and will return `NotedStatement::NotUseful`.
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
fn note_statement(&mut self, statement: SignedFullStatement) -> NotedStatement {
let validator_index = statement.validator_index();
let comparator = StoredStatementComparator {
@@ -490,6 +495,7 @@ fn check_statement_signature(
/// Informs all registered listeners about a newly received statement.
///
/// Removes all closed listeners.
#[tracing::instrument(level = "trace", skip(listeners), fields(subsystem = LOG_TARGET))]
async fn inform_statement_listeners(
statement: &SignedFullStatement,
listeners: &mut Vec<mpsc::Sender<SignedFullStatement>>,
@@ -509,6 +515,7 @@ async fn inform_statement_listeners(
/// circulates the statement to all peers who have not seen it yet, and
/// sends all statements dependent on that statement to peers who could previously not receive
/// them but now can.
#[tracing::instrument(level = "trace", skip(peers, ctx, active_heads, metrics), fields(subsystem = LOG_TARGET))]
async fn circulate_statement_and_dependents(
peers: &mut HashMap<PeerId, PeerData>,
active_heads: &mut HashMap<Hash, ActiveHeadData>,
@@ -564,6 +571,7 @@ fn statement_message(relay_parent: Hash, statement: SignedFullStatement)
/// Circulates a statement to all peers who have not seen it yet, and returns
/// an iterator over peers who need to have dependent statements sent.
#[tracing::instrument(level = "trace", skip(peers, ctx), fields(subsystem = LOG_TARGET))]
async fn circulate_statement(
peers: &mut HashMap<PeerId, PeerData>,
ctx: &mut impl SubsystemContext<Message = StatementDistributionMessage>,
@@ -597,6 +605,7 @@ async fn circulate_statement(
}
/// Send all statements about a given candidate hash to a peer.
#[tracing::instrument(level = "trace", skip(peer_data, ctx, active_head, metrics), fields(subsystem = LOG_TARGET))]
async fn send_statements_about(
peer: PeerId,
peer_data: &mut PeerData,
@@ -625,6 +634,7 @@ async fn send_statements_about(
}
/// Send all statements at a given relay-parent to a peer.
#[tracing::instrument(level = "trace", skip(peer_data, ctx, active_head, metrics), fields(subsystem = LOG_TARGET))]
async fn send_statements(
peer: PeerId,
peer_data: &mut PeerData,
@@ -666,6 +676,7 @@ async fn report_peer(
//
// This function checks the signature and ensures the statement is compatible with our
// view.
#[tracing::instrument(level = "trace", skip(peer_data, ctx, active_heads, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_incoming_message<'a>(
peer: PeerId,
peer_data: &mut PeerData,
@@ -688,7 +699,10 @@ async fn handle_incoming_message<'a>(
None => {
// This should never be out-of-sync with our view if the view updates
// correspond to actual `StartWork` messages. So we just log and ignore.
log::warn!("Our view out-of-sync with active heads. Head {} not found", relay_parent);
tracing::warn!(
requested_relay_parent = %relay_parent,
"our view out-of-sync with active heads; head not found",
);
return Ok(None);
}
};
@@ -741,6 +755,7 @@ async fn handle_incoming_message<'a>(
}
/// Update a peer's view. Sends all newly unlocked statements based on the previous
#[tracing::instrument(level = "trace", skip(peer_data, ctx, active_heads, metrics), fields(subsystem = LOG_TARGET))]
async fn update_peer_view_and_send_unlocked(
peer: PeerId,
peer_data: &mut PeerData,
@@ -777,6 +792,7 @@ async fn update_peer_view_and_send_unlocked(
Ok(())
}
#[tracing::instrument(level = "trace", skip(peers, active_heads, ctx, metrics), fields(subsystem = LOG_TARGET))]
async fn handle_network_update(
peers: &mut HashMap<PeerId, PeerData>,
active_heads: &mut HashMap<Hash, ActiveHeadData>,
@@ -847,9 +863,13 @@ async fn handle_network_update(
for new in our_view.difference(&old_view) {
if !active_heads.contains_key(&new) {
log::warn!(target: LOG_TARGET, "Our network bridge view update \
tracing::warn!(
target: LOG_TARGET,
unknown_hash = %new,
"Our network bridge view update \
inconsistent with `StartWork` messages we have received from overseer. \
Contains unknown hash {}", new);
Contains unknown hash.",
);
}
}
@@ -860,6 +880,7 @@ async fn handle_network_update(
}
impl StatementDistribution {
#[tracing::instrument(skip(self, ctx), fields(subsystem = LOG_TARGET))]
async fn run(
self,
mut ctx: impl SubsystemContext<Message = StatementDistributionMessage>,
@@ -899,10 +920,10 @@ impl StatementDistribution {
match (val_rx.await?, session_rx.await?) {
(Ok(v), Ok(s)) => (v, s),
(Err(e), _) | (_, Err(e)) => {
log::warn!(
tracing::warn!(
target: LOG_TARGET,
"Failed to fetch runtime API data for active leaf: {:?}",
e,
err = ?e,
"Failed to fetch runtime API data for active leaf",
);
// Lacking this bookkeeping might make us behave funny, although