feat: Enhance block import log line (#6095)

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
This commit is contained in:
Danno Ferrin
2024-02-09 05:14:37 -07:00
committed by GitHub
parent 51ffa822c3
commit 3f57fc8cc9
3 changed files with 76 additions and 27 deletions

View File

@ -6,11 +6,11 @@ use std::{sync::Arc, time::Duration};
/// Events emitted by [crate::BeaconConsensusEngine].
#[derive(Clone, Debug)]
pub enum BeaconConsensusEngineEvent {
/// The fork choice state was updated.
/// The fork choice state was updated, and the current fork choice status
ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
/// A block was added to the canonical chain.
CanonicalBlockAdded(Arc<SealedBlock>),
/// A canonical chain was committed.
/// A block was added to the canonical chain, and the elapsed time validating the block
CanonicalBlockAdded(Arc<SealedBlock>, Duration),
/// A canonical chain was committed, and the elapsed time committing the data
CanonicalChainCommitted(Box<SealedHeader>, Duration),
/// A block was added to the fork chain.
ForkBlockAdded(Arc<SealedBlock>),

View File

@ -1271,16 +1271,18 @@ where
debug_assert!(self.sync.is_pipeline_idle(), "pipeline must be idle");
let block_hash = block.hash();
let start = Instant::now();
let status = self
.blockchain
.insert_block_without_senders(block.clone(), BlockValidationKind::Exhaustive)?;
let elapsed = start.elapsed();
let mut latest_valid_hash = None;
let block = Arc::new(block);
let status = match status {
InsertPayloadOk::Inserted(BlockStatus::Valid(attachment)) => {
latest_valid_hash = Some(block_hash);
let event = if attachment.is_canonical() {
BeaconConsensusEngineEvent::CanonicalBlockAdded(block)
BeaconConsensusEngineEvent::CanonicalBlockAdded(block, elapsed)
} else {
BeaconConsensusEngineEvent::ForkBlockAdded(block)
};