Skip to content

Commit e276480

Browse files
Timosdev99yongkangcRjectedCopilot
authored
feat(observability): add phase-level observablity to newPayload processing (#18308)
Co-authored-by: YK <chiayongkang@hotmail.com> Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 44a48ab commit e276480

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

crates/engine/tree/src/tree/metrics.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,22 @@ pub(crate) struct BlockValidationMetrics {
163163
pub(crate) state_root_storage_tries_updated_total: Counter,
164164
/// Total number of times the parallel state root computation fell back to regular.
165165
pub(crate) state_root_parallel_fallback_total: Counter,
166-
/// Histogram of state root duration, ie the time spent blocked waiting for the state root.
167-
pub(crate) state_root_histogram: Histogram,
168166
/// Latest state root duration, ie the time spent blocked waiting for the state root.
169167
pub(crate) state_root_duration: Gauge,
168+
/// Histogram for state root duration ie the time spent blocked waiting for the state root
169+
pub(crate) state_root_histogram: Histogram,
170170
/// Trie input computation duration
171171
pub(crate) trie_input_duration: Histogram,
172172
/// Payload conversion and validation latency
173173
pub(crate) payload_validation_duration: Gauge,
174174
/// Histogram of payload validation latency
175175
pub(crate) payload_validation_histogram: Histogram,
176+
/// Payload processor spawning duration
177+
pub(crate) spawn_payload_processor: Histogram,
178+
/// Post-execution validation duration
179+
pub(crate) post_execution_validation_duration: Histogram,
180+
/// Total duration of the new payload call
181+
pub(crate) total_duration: Histogram,
176182
}
177183

178184
impl BlockValidationMetrics {

crates/engine/tree/src/tree/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ where
508508
trace!(target: "engine::tree", "invoked new payload");
509509
self.metrics.engine.new_payload_messages.increment(1);
510510

511-
let validation_start = Instant::now();
511+
// start timing for the new payload process
512+
let start = Instant::now();
512513

513514
// Ensures that the given payload does not violate any consensus rules that concern the
514515
// block's layout, like:
@@ -537,10 +538,6 @@ where
537538
// This validation **MUST** be instantly run in all cases even during active sync process.
538539
let parent_hash = payload.parent_hash();
539540

540-
self.metrics
541-
.block_validation
542-
.record_payload_validation(validation_start.elapsed().as_secs_f64());
543-
544541
let num_hash = payload.num_hash();
545542
let engine_event = ConsensusEngineEvent::BlockReceived(num_hash);
546543
self.emit_event(EngineApiEvent::BeaconConsensus(engine_event));
@@ -569,6 +566,8 @@ where
569566
let status = self.on_invalid_new_payload(block.into_sealed_block(), invalid)?;
570567
return Ok(TreeOutcome::new(status))
571568
}
569+
// record pre-execution phase duration
570+
self.metrics.block_validation.record_payload_validation(start.elapsed().as_secs_f64());
572571

573572
let status = if self.backfill_sync_state.is_idle() {
574573
let mut latest_valid_hash = None;
@@ -625,6 +624,9 @@ where
625624
}
626625
}
627626

627+
// record total newPayload duration
628+
self.metrics.block_validation.total_duration.record(start.elapsed().as_secs_f64());
629+
628630
Ok(outcome)
629631
}
630632

@@ -663,7 +665,7 @@ where
663665
warn!(target: "engine::tree", current_hash=?current_hash, "Sidechain block not found in TreeState");
664666
// This should never happen as we're walking back a chain that should connect to
665667
// the canonical chain
666-
return Ok(None);
668+
return Ok(None)
667669
}
668670
}
669671

@@ -673,7 +675,7 @@ where
673675
new_chain.reverse();
674676

675677
// Simple extension of the current chain
676-
return Ok(Some(NewCanonicalChain::Commit { new: new_chain }));
678+
return Ok(Some(NewCanonicalChain::Commit { new: new_chain }))
677679
}
678680

679681
// We have a reorg. Walk back both chains to find the fork point.
@@ -690,7 +692,7 @@ where
690692
} else {
691693
// This shouldn't happen as we're walking back the canonical chain
692694
warn!(target: "engine::tree", current_hash=?old_hash, "Canonical block not found in TreeState");
693-
return Ok(None);
695+
return Ok(None)
694696
}
695697
}
696698

@@ -706,7 +708,7 @@ where
706708
} else {
707709
// This shouldn't happen as we're walking back the canonical chain
708710
warn!(target: "engine::tree", current_hash=?old_hash, "Canonical block not found in TreeState");
709-
return Ok(None);
711+
return Ok(None)
710712
}
711713

712714
if let Some(block) = self.state.tree_state.executed_block_by_hash(current_hash).cloned()
@@ -716,7 +718,7 @@ where
716718
} else {
717719
// This shouldn't happen as we've already walked this path
718720
warn!(target: "engine::tree", invalid_hash=?current_hash, "New chain block not found in TreeState");
719-
return Ok(None);
721+
return Ok(None)
720722
}
721723
}
722724
new_chain.reverse();

crates/engine/tree/src/tree/payload_validator.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ where
335335
Ok(val) => val,
336336
Err(e) => {
337337
let block = self.convert_to_block(input)?;
338-
return Err(InsertBlockError::new(block.into_sealed_block(), e.into()).into())
338+
return Err(
339+
InsertBlockError::new(block.into_sealed_block(), e.into()).into()
340+
)
339341
}
340342
}
341343
};
@@ -437,7 +439,8 @@ where
437439
// Use state root task only if prefix sets are empty, otherwise proof generation is too
438440
// expensive because it requires walking over the paths in the prefix set in every
439441
// proof.
440-
if trie_input.prefix_sets.is_empty() {
442+
let spawn_payload_processor_start = Instant::now();
443+
let handle = if trie_input.prefix_sets.is_empty() {
441444
self.payload_processor.spawn(
442445
env.clone(),
443446
txs,
@@ -450,9 +453,25 @@ where
450453
debug!(target: "engine::tree", block=?block_num_hash, "Disabling state root task due to non-empty prefix sets");
451454
use_state_root_task = false;
452455
self.payload_processor.spawn_cache_exclusive(env.clone(), txs, provider_builder)
453-
}
456+
};
457+
458+
// record prewarming initialization duration
459+
self.metrics
460+
.block_validation
461+
.spawn_payload_processor
462+
.record(spawn_payload_processor_start.elapsed().as_secs_f64());
463+
handle
454464
} else {
455-
self.payload_processor.spawn_cache_exclusive(env.clone(), txs, provider_builder)
465+
let prewarming_start = Instant::now();
466+
let handle =
467+
self.payload_processor.spawn_cache_exclusive(env.clone(), txs, provider_builder);
468+
469+
// Record prewarming initialization duration
470+
self.metrics
471+
.block_validation
472+
.spawn_payload_processor
473+
.record(prewarming_start.elapsed().as_secs_f64());
474+
handle
456475
};
457476

458477
// Use cached state provider before executing, used in execution after prewarming threads
@@ -491,6 +510,7 @@ where
491510
};
492511
}
493512

513+
let post_execution_start = Instant::now();
494514
trace!(target: "engine::tree", block=?block_num_hash, "Validating block consensus");
495515
// validate block consensus rules
496516
ensure_ok!(self.validate_block_inner(&block));
@@ -519,6 +539,12 @@ where
519539
return Err(InsertBlockError::new(block.into_sealed_block(), err.into()).into())
520540
}
521541

542+
// record post-execution validation duration
543+
self.metrics
544+
.block_validation
545+
.post_execution_validation_duration
546+
.record(post_execution_start.elapsed().as_secs_f64());
547+
522548
debug!(target: "engine::tree", block=?block_num_hash, "Calculating block state root");
523549

524550
let root_time = Instant::now();
@@ -892,7 +918,7 @@ where
892918
) {
893919
if state.invalid_headers.get(&block.hash()).is_some() {
894920
// we already marked this block as invalid
895-
return;
921+
return
896922
}
897923
self.invalid_block_hook.on_invalid_block(parent_header, block, output, trie_updates);
898924
}

0 commit comments

Comments
 (0)