chore(tree): improved debug logging for block insertion (#11958)

This commit is contained in:
Federico Gimenez
2024-10-22 16:56:04 +02:00
committed by GitHub
parent b3015c75b1
commit b20a271551

View File

@ -259,6 +259,7 @@ impl TreeState {
}
}
}
debug!(target: "engine::tree", ?upper_bound, ?last_persisted_hash, "Removed canonical blocks from the tree");
}
/// Removes all blocks that are below the finalized block, as well as removing non-canonical
@ -1593,7 +1594,7 @@ where
/// Returns an error if we failed to fetch the state from the database.
fn state_provider(&self, hash: B256) -> ProviderResult<Option<StateProviderBox>> {
if let Some((historical, blocks)) = self.state.tree_state.blocks_by_hash(hash) {
trace!(target: "engine::tree", %hash, "found canonical state for block in memory");
debug!(target: "engine::tree", %hash, %historical, "found canonical state for block in memory");
// the block leads back to the canonical chain
let historical = self.provider.state_by_block_hash(historical)?;
return Ok(Some(Box::new(MemoryOverlayStateProvider::new(historical, blocks))))
@ -1601,13 +1602,13 @@ where
// the hash could belong to an unknown block or a persisted block
if let Some(header) = self.provider.header(&hash)? {
trace!(target: "engine::tree", %hash, number = %header.number, "found canonical state for block in database");
debug!(target: "engine::tree", %hash, number = %header.number, "found canonical state for block in database");
// the block is known and persisted
let historical = self.provider.state_by_block_hash(hash)?;
return Ok(Some(historical))
}
trace!(target: "engine::tree", %hash, "no canonical state found for block");
debug!(target: "engine::tree", %hash, "no canonical state found for block");
Ok(None)
}
@ -2137,7 +2138,8 @@ where
&mut self,
block: SealedBlockWithSenders,
) -> Result<InsertPayloadOk2, InsertBlockErrorKindTwo> {
debug!(target: "engine::tree", block=?block.num_hash(), "Inserting new block into tree");
debug!(target: "engine::tree", block=?block.num_hash(), parent = ?block.parent_hash, state_root = ?block.state_root, "Inserting new block into tree");
if self.block_by_hash(block.hash())?.is_some() {
return Ok(InsertPayloadOk2::AlreadySeen(BlockStatus2::Valid))
}
@ -2206,7 +2208,7 @@ where
let hashed_state = HashedPostState::from_bundle_state(&output.state.state);
trace!(target: "engine::tree", block=?BlockNumHash::new(block_number, block_hash), "Calculating block state root");
trace!(target: "engine::tree", block=?sealed_block.num_hash(), "Calculating block state root");
let root_time = Instant::now();
let mut state_root_result = None;
@ -2232,7 +2234,7 @@ where
let (state_root, trie_output) = if let Some(result) = state_root_result {
result
} else {
debug!(target: "engine::tree", persistence_in_progress, "Failed to compute state root in parallel");
debug!(target: "engine::tree", block=?sealed_block.num_hash(), persistence_in_progress, "Failed to compute state root in parallel");
state_provider.state_root_with_updates(hashed_state.clone())?
};
@ -2252,7 +2254,7 @@ where
let root_elapsed = root_time.elapsed();
self.metrics.block_validation.record_state_root(&trie_output, root_elapsed.as_secs_f64());
debug!(target: "engine::tree", ?root_elapsed, ?block_number, "Calculated state root");
debug!(target: "engine::tree", ?root_elapsed, block=?sealed_block.num_hash(), "Calculated state root");
let executed = ExecutedBlock {
block: sealed_block.clone(),
@ -2301,6 +2303,7 @@ where
let mut input = TrieInput::default();
if let Some((historical, blocks)) = self.state.tree_state.blocks_by_hash(parent_hash) {
debug!(target: "engine::tree", %parent_hash, %historical, "Calculating state root in parallel, parent found in memory");
// Retrieve revert state for historical block.
let revert_state = consistent_view.revert_state(historical)?;
input.append(revert_state);
@ -2311,6 +2314,7 @@ where
}
} else {
// The block attaches to canonical persisted parent.
debug!(target: "engine::tree", %parent_hash, "Calculating state root in parallel, parent found in disk");
let revert_state = consistent_view.revert_state(parent_hash)?;
input.append(revert_state);
}