From 2e4f4d8e87017dd02c2080e75eb7eb86fdf6e5e6 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Thu, 19 Nov 2020 16:55:36 -0800 Subject: [PATCH] consensus: fix span handling in BlockVerifier The BlockVerifier constructed a tracing span and manually entered it inside of an async block. Manually entering spans inside async blocks can cause problems where the span might not be entered and exited correctly as the resulting future is polled. Instead, using the .instrument creates a wrapper future that handles the bookkeeping. I changed the span name and contents to be consistent with the spans in the checkpoint verifier. --- zebra-consensus/src/block.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/zebra-consensus/src/block.rs b/zebra-consensus/src/block.rs index 6c2926ea7..97ccfb707 100644 --- a/zebra-consensus/src/block.rs +++ b/zebra-consensus/src/block.rs @@ -19,6 +19,7 @@ use futures::stream::FuturesUnordered; use futures_util::FutureExt; use thiserror::Error; use tower::{Service, ServiceExt}; +use tracing::Instrument; use zebra_chain::{ block::{self, Block}, @@ -114,14 +115,14 @@ where let mut transaction_verifier = self.transaction_verifier.clone(); let network = self.network; + // We don't include the block hash, because it's likely already in a parent span + let span = tracing::debug_span!("block", height = ?block.coinbase_height()); + // TODO(jlusby): Error = Report, handle errors from state_service. async move { + tracing::trace!("beginning block verification"); + let hash = block.hash(); - - // The height is already included in the ChainVerifier span - let span = tracing::debug_span!("BlockVerifier::call", ?hash); - let _entered = span.enter(); - // Check that this block is actually a new block. match state_service .ready_and() @@ -200,6 +201,7 @@ where _ => unreachable!("wrong response for CommitBlock"), } } + .instrument(span) .boxed() } }