From 05135c41efa30c0b108697bb4baac0979be4ad9e Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 25 Jul 2024 18:44:03 +0200 Subject: [PATCH] chore: more misc tracing (#9809) --- crates/chain-state/src/in_memory.rs | 15 +++++++++++++++ crates/engine/tree/src/tree.rs | 5 +---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index a16fdca43b..6ce742c69e 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -515,6 +515,21 @@ pub enum NewCanonicalChain { } impl NewCanonicalChain { + /// Returns the length of the new chain. + pub fn new_block_count(&self) -> usize { + match self { + Self::Commit { new } | Self::Reorg { new, .. } => new.len(), + } + } + + /// Returns the length of the reorged chain. + pub fn reorged_block_count(&self) -> usize { + match self { + Self::Commit { .. } => 0, + Self::Reorg { old, .. } => old.len(), + } + } + /// Converts the new chain into a notification that will be emitted to listeners pub fn to_chain_notification(&self) -> CanonStateNotification { // TODO: do we need to merge execution outcome for multiblock commit or reorg? diff --git a/crates/engine/tree/src/tree.rs b/crates/engine/tree/src/tree.rs index 6faf2a23b0..28b4b21192 100644 --- a/crates/engine/tree/src/tree.rs +++ b/crates/engine/tree/src/tree.rs @@ -272,9 +272,6 @@ impl EngineApiTreeState { } /// The type responsible for processing engine API requests. -/// -/// TODO: design: should the engine handler functions also accept the response channel or return the -/// result and the caller redirects the response pub trait EngineApiTreeHandler { /// The engine type that this handler is for. type Engine: EngineTypes; @@ -1473,7 +1470,7 @@ where // 2. ensure we can apply a new chain update for the head block if let Some(chain_update) = self.state.tree_state.on_new_head(state.head_block_hash) { - trace!(target: "engine", "applying new chain update"); + trace!(target: "engine", new_blocks = %chain_update.new_block_count(), reorged_blocks = %chain_update.reorged_block_count() ,"applying new chain update"); // update the tracked canonical head self.state.tree_state.set_canonical_head(chain_update.tip().num_hash());