Skip to content

feat(metrics): implement RAII-based block timing with Prometheus support#60

Merged
louisliu2048 merged 7 commits intodevfrom
leo/optimize-block-timing
Dec 3, 2025
Merged

feat(metrics): implement RAII-based block timing with Prometheus support#60
louisliu2048 merged 7 commits intodevfrom
leo/optimize-block-timing

Conversation

@LeoGuo621
Copy link

No description provided.


/// Manually finish timing and return the duration.
/// This updates the target immediately and prevents the drop handler from running.
pub fn finish(mut self) -> Duration {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The finish() method calls record(), and then when the guard is dropped, Drop::drop() calls record() again, resulting in Prometheus metrics being recorded twice.

impl Drop for BlockTimingContext {
fn drop(&mut self) {
if self.auto_store {
self.update_totals();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In crates/engine/tree/src/tree/mod.rs, update_totals() is called manually: timing_ctx.update_totals(), and then called again in this Drop implementation. This causes Prometheus total metrics to be recorded twice.

/// These metrics track the duration of various phases in block production and insertion.
#[derive(Metrics, Clone)]
#[metrics(scope = "block.timing")]
pub struct BlockTimingPrometheusMetrics {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current Prometheus metrics are global histograms without any labels to distinguish different scenarios. This makes it difficult to analyze metrics by:

  • Block number
  • Whether the block was locally built vs received from network
  • Other contextual information

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend use dynamic labels to solve it.

@louisliu2048 louisliu2048 merged commit ecfb199 into dev Dec 3, 2025
Vui-Chee added a commit that referenced this pull request Dec 11, 2025
* dev:
  chore: Update cargo deps (#65)
  feat(flashblock): Enable eth_getTransactionByHash support for flashblock (paradigmxyz#19954)
  feat(flashblocks): Cache recent flashblocks (paradigmxyz#19786)
  feat(flashblock): improve state root calculation condition (paradigmxyz#19667)
  feat(flashblocks): add metrics for current block and index (paradigmxyz#19712)
  refactor(flashblock): Move all flashblocks related data structure to op-alloy (paradigmxyz#19608)
  chore: add target: flashblock for all flashblock related traces (paradigmxyz#19656)
  feat(metrics): implement RAII-based block timing with Prometheus support (#60)
  Fix fmt (#62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants