diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 79628c21ed..8033adade8 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -3477,9 +3477,9 @@ dependencies = [ [[package]] name = "mick-jaeger" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4247b181b96e62eacb5a1e7a2f1a39a78b945cb0434c0fceaae4ed1882555957" +checksum = "c023c3f16109e7f33aa451f773fd61070e265b4977d0b6e344a51049296dd7df" dependencies = [ "futures 0.3.8", "rand 0.7.3", diff --git a/polkadot/node/core/bitfield-signing/src/lib.rs b/polkadot/node/core/bitfield-signing/src/lib.rs index 8c06f76424..1c5721a42d 100644 --- a/polkadot/node/core/bitfield-signing/src/lib.rs +++ b/polkadot/node/core/bitfield-signing/src/lib.rs @@ -78,7 +78,7 @@ async fn get_core_availability( span: &jaeger::JaegerSpan, ) -> Result { if let CoreState::Occupied(core) = core { - let _span = span.child("query chunk availability"); + let _span = span.child("query-chunk-availability"); let (tx, rx) = oneshot::channel(); sender @@ -246,12 +246,12 @@ impl JobTrait for BitfieldSigningJob { let _timer = metrics.time_run(); drop(_span); - let _span = span.child("availablity"); + let span_availability = span.child("availability"); let bitfield = match construct_availability_bitfield( relay_parent, - &span, + &span_availability, validator.index(), &mut sender, ).await @@ -265,7 +265,7 @@ impl JobTrait for BitfieldSigningJob { Ok(bitfield) => bitfield, }; - drop(_span); + drop(span_availability); let _span = span.child("signing"); let signed_bitfield = validator diff --git a/polkadot/node/jaeger/Cargo.toml b/polkadot/node/jaeger/Cargo.toml index df2528ac97..e106888a14 100644 --- a/polkadot/node/jaeger/Cargo.toml +++ b/polkadot/node/jaeger/Cargo.toml @@ -7,7 +7,7 @@ description = "Polkadot Jaeger primitives" [dependencies] async-std = "1.8.0" -mick-jaeger = "0.1.2" +mick-jaeger = "0.1.4" lazy_static = "1.4" parking_lot = "0.11.1" polkadot-primitives = { path = "../../primitives" } diff --git a/polkadot/node/jaeger/src/lib.rs b/polkadot/node/jaeger/src/lib.rs index c99b498ad0..73e0fb8c17 100644 --- a/polkadot/node/jaeger/src/lib.rs +++ b/polkadot/node/jaeger/src/lib.rs @@ -183,6 +183,14 @@ impl JaegerSpan { Self::Disabled => {}, } } + + /// Adds the `FollowsFrom` relationship to this span with respect to the given one. + pub fn add_follows_from(&mut self, other: &Self) { + match (self, other) { + (Self::Enabled(ref mut inner), Self::Enabled(ref other_inner)) => inner.add_follows_from(&other_inner), + _ => {}, + } + } } impl std::fmt::Debug for JaegerSpan { diff --git a/polkadot/node/network/availability-distribution/src/lib.rs b/polkadot/node/network/availability-distribution/src/lib.rs index f07e48caab..c35e2868bc 100644 --- a/polkadot/node/network/availability-distribution/src/lib.rs +++ b/polkadot/node/network/availability-distribution/src/lib.rs @@ -45,7 +45,7 @@ use polkadot_subsystem::messages::{ NetworkBridgeMessage, RuntimeApiMessage, RuntimeApiRequest, }; use polkadot_subsystem::{ - jaeger, errors::{ChainApiError, RuntimeApiError}, + jaeger, errors::{ChainApiError, RuntimeApiError}, PerLeafSpan, ActiveLeavesUpdate, FromOverseer, OverseerSignal, SpawnedSubsystem, Subsystem, SubsystemContext, SubsystemError, }; use std::collections::{HashMap, HashSet}; @@ -191,12 +191,14 @@ impl PerCandidate { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug)] struct PerRelayParent { /// Set of `K` ancestors for this relay parent. ancestors: Vec, /// Live candidates, according to this relay parent. live_candidates: HashSet, + /// The span that belongs to this relay parent. + span: PerLeafSpan, } impl ProtocolState { @@ -216,7 +218,7 @@ impl ProtocolState { ) } - #[tracing::instrument(level = "trace", skip(candidates), fields(subsystem = LOG_TARGET))] + #[tracing::instrument(level = "trace", skip(candidates, span), fields(subsystem = LOG_TARGET))] fn add_relay_parent( &mut self, relay_parent: Hash, @@ -224,10 +226,13 @@ impl ProtocolState { validator_index: Option, candidates: HashMap, ancestors: Vec, + span: PerLeafSpan, ) { - let per_relay_parent = self.per_relay_parent.entry(relay_parent).or_default(); - per_relay_parent.ancestors = ancestors; - per_relay_parent.live_candidates.extend(candidates.keys().cloned()); + let per_relay_parent = self.per_relay_parent.entry(relay_parent).or_insert_with(|| PerRelayParent { + span, + ancestors, + live_candidates: candidates.keys().cloned().collect(), + }); // register the relation of relay_parent to candidate.. for (receipt_hash, fetched) in candidates { @@ -256,6 +261,11 @@ impl ProtocolState { } }; + // Create some span that will make it able to switch between the candidate and relay parent span. + let mut span = per_relay_parent.span.child("live-candidate"); + span.add_string_tag("candidate-hash", &format!("{:?}", receipt_hash)); + + candidate_entry.span.add_follows_from(&span); candidate_entry.live_in.insert(relay_parent); } } @@ -365,7 +375,9 @@ where let view = state.view.clone(); // add all the relay parents and fill the cache - for added in view.difference(&old_view) { + for (added, span) in view.span_per_head().iter().filter(|v| !old_view.contains(&v.0)) { + let span = PerLeafSpan::new(span.clone(), "availability-distribution"); + let validators = query_validators(ctx, *added).await?; let validator_index = obtain_our_validator_index(&validators, keystore.clone()).await; let (candidates, ancestors) @@ -377,6 +389,7 @@ where validator_index, candidates, ancestors, + span, ); } @@ -436,7 +449,6 @@ where "Retrieved chunk from availability storage", ); - let msg = AvailabilityGossipMessage { candidate_hash, erasure_chunk, diff --git a/polkadot/node/network/availability-distribution/src/tests.rs b/polkadot/node/network/availability-distribution/src/tests.rs index 76a8566246..524855e713 100644 --- a/polkadot/node/network/availability-distribution/src/tests.rs +++ b/polkadot/node/network/availability-distribution/src/tests.rs @@ -1005,9 +1005,14 @@ fn clean_up_receipts_cache_unions_ancestors_and_view() { state.per_relay_parent.insert(hash_a, PerRelayParent { ancestors: vec![hash_b], live_candidates: HashSet::new(), + span: PerLeafSpan::new(Arc::new(jaeger::JaegerSpan::Disabled), "test"), }); - state.per_relay_parent.insert(hash_c, PerRelayParent::default()); + state.per_relay_parent.insert(hash_c, PerRelayParent { + ancestors: Vec::new(), + live_candidates: HashSet::new(), + span: PerLeafSpan::new(Arc::new(jaeger::JaegerSpan::Disabled), "test"), + }); state.clean_up_live_under_cache(); @@ -1030,11 +1035,13 @@ fn remove_relay_parent_only_removes_per_candidate_if_final() { state.per_relay_parent.insert(hash_a, PerRelayParent { ancestors: vec![], live_candidates: std::iter::once(candidate_hash_a).collect(), + span: PerLeafSpan::new(Arc::new(jaeger::JaegerSpan::Disabled), "test"), }); state.per_relay_parent.insert(hash_b, PerRelayParent { ancestors: vec![], live_candidates: std::iter::once(candidate_hash_a).collect(), + span: PerLeafSpan::new(Arc::new(jaeger::JaegerSpan::Disabled), "test"), }); state.per_candidate.insert(candidate_hash_a, { @@ -1079,6 +1086,7 @@ fn add_relay_parent_includes_all_live_candidates() { None, candidates, vec![ancestor_a], + PerLeafSpan::new(Arc::new(jaeger::JaegerSpan::Disabled), "test"), ); assert!( diff --git a/polkadot/node/overseer/src/lib.rs b/polkadot/node/overseer/src/lib.rs index 60e0215d51..05420026e6 100644 --- a/polkadot/node/overseer/src/lib.rs +++ b/polkadot/node/overseer/src/lib.rs @@ -1510,7 +1510,7 @@ where for (hash, number) in std::mem::take(&mut self.leaves) { let _ = self.active_leaves.insert(hash, number); - let span = self.on_head_activated(&hash); + let span = self.on_head_activated(&hash, None); update.activated.push((hash, span)); } @@ -1589,7 +1589,7 @@ where } }; - let span = self.on_head_activated(&block.hash); + let span = self.on_head_activated(&block.hash, Some(block.parent_hash)); let mut update = ActiveLeavesUpdate::start_work(block.hash, span); if let Some(number) = self.active_leaves.remove(&block.parent_hash) { @@ -1705,7 +1705,7 @@ where } #[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))] - fn on_head_activated(&mut self, hash: &Hash) -> Arc { + fn on_head_activated(&mut self, hash: &Hash, parent_hash: Option) -> Arc { self.metrics.on_head_activated(); if let Some(listeners) = self.activation_external_listeners.remove(hash) { for listener in listeners { @@ -1714,7 +1714,13 @@ where } } - let span = Arc::new(jaeger::hash_span(hash, "leave activated")); + let mut span = jaeger::hash_span(hash, "leaf-activated"); + + if let Some(parent_span) = parent_hash.and_then(|h| self.span_per_active_leaf.get(&h)) { + span.add_follows_from(&*parent_span); + } + + let span = Arc::new(span); self.span_per_active_leaf.insert(*hash, span.clone()); span }