Skip to content

Commit

Permalink
chore(engine): track elapsed on fork block added (#10710)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Sep 5, 2024
1 parent ba3fc6a commit c267c1c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/consensus/beacon/src/engine/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::{sync::Arc, time::Duration};
pub enum BeaconConsensusEngineEvent {
/// The fork choice state was updated, and the current fork choice status
ForkchoiceUpdated(ForkchoiceState, ForkchoiceStatus),
/// A block was added to the fork chain.
ForkBlockAdded(Arc<SealedBlock>, Duration),
/// 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),
/// The consensus engine is involved in live sync, and has specific progress
LiveSyncProgress(ConsensusEngineLiveSyncProgress),
/// A block was added to the fork chain.
ForkBlockAdded(Arc<SealedBlock>),
}

impl BeaconConsensusEngineEvent {
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ where
let event = if attachment.is_canonical() {
BeaconConsensusEngineEvent::CanonicalBlockAdded(block, elapsed)
} else {
BeaconConsensusEngineEvent::ForkBlockAdded(block)
BeaconConsensusEngineEvent::ForkBlockAdded(block, elapsed)
};
self.event_sender.notify(event);
PayloadStatusEnum::Valid
Expand Down
6 changes: 4 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,10 +2112,11 @@ where
let finalized = self.state.forkchoice_state_tracker.sync_target_finalized();

// emit insert event
let elapsed = start.elapsed();
let engine_event = if self.is_fork(block_hash, finalized)? {
BeaconConsensusEngineEvent::ForkBlockAdded(sealed_block)
BeaconConsensusEngineEvent::ForkBlockAdded(sealed_block, elapsed)
} else {
BeaconConsensusEngineEvent::CanonicalBlockAdded(sealed_block, start.elapsed())
BeaconConsensusEngineEvent::CanonicalBlockAdded(sealed_block, elapsed)
};
self.emit_event(EngineApiEvent::BeaconConsensus(engine_event));

Expand Down Expand Up @@ -2665,6 +2666,7 @@ mod tests {
match event {
EngineApiEvent::BeaconConsensus(BeaconConsensusEngineEvent::ForkBlockAdded(
block,
_,
)) => {
assert!(block.hash() == expected_hash);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/node/events/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ impl NodeState {

info!(number=head.number, hash=?head.hash(), ?elapsed, "Canonical chain committed");
}
BeaconConsensusEngineEvent::ForkBlockAdded(block) => {
info!(number=block.number, hash=?block.hash(), "Block added to fork chain");
BeaconConsensusEngineEvent::ForkBlockAdded(block, elapsed) => {
info!(number=block.number, hash=?block.hash(), ?elapsed, "Block added to fork chain");
}
}
}
Expand Down

0 comments on commit c267c1c

Please sign in to comment.