fix(metrics): discard block-processing time for duplicate blocks#523
Conversation
lean_fork_choice_block_processing_time_seconds is sampled by a TimingGuard created at the top of on_block_core, before the idempotent duplicate-block check returns early. A duplicate does no block processing, so it recorded a near-zero sample that skewed the histogram low (duplicates are common during range sync). Add TimingGuard::discard() to cancel a measurement before the guard drops, and call it on the duplicate-block early return. The block hashing stays inside the timed span since it is real work; only the sample for the no-op duplicate is dropped. Other early returns (validation rejections) still record, as they represent real processing time.
🤖 Kimi Code ReviewThe PR is well-crafted and addresses a real metrics accuracy issue. The implementation is correct, safe, and idiomatic. Minor suggestions:
Consensus/Security note: Summary: No blockers. The PR correctly prevents skewed histogram measurements during range sync while maintaining the existing performance characteristics (single bool check on drop). Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Claude Code ReviewEverything checks out. This is a clean, minimal, well-tested fix. Here's the review. Review: fix(metrics): discard block-processing time for duplicate blocksOverall: Clean, minimal, well-targeted fix. The Observations (non-blocking):
No security, correctness, or fork-choice/consensus concerns — this only affects a Prometheus histogram sample, not any state-transition or fork-choice logic. Comment in Automated review by Claude (Anthropic) · sonnet · custom prompt |
🤖 Codex Code Review
No blocking correctness, safety, or consensus-layer issues stood out in this diff. The change is metrics-only, Testing gap: I could not run the Rust tests in this environment because Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
Greptile SummaryThis PR excludes duplicate blocks from the block-processing timing histogram. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| crates/blockchain/src/store.rs | Discards the timing sample only when the exact block root already has stored state. |
| crates/common/metrics/src/timing.rs | Adds an explicit disarmed state to the timing guard and tests both drop paths. |
Reviews (1): Last reviewed commit: "fix(metrics): discard block-processing t..." | Re-trigger Greptile
Change discard from a `&mut self` disarmed-flag defusal to a consuming `discard(self)` that deconstructs the guard via `ManuallyDrop`, inhibiting the recording `Drop` without `mem::forget` or `unsafe`. Drop the timing unit tests.
Problem
lean_fork_choice_block_processing_time_secondsis sampled by aTimingGuardcreated at the top ofon_block_core, before the idempotent duplicate-block check returns early. A duplicate block does no processing, so it recorded a near-zero sample that skews the histogram low. Duplicates are common during range sync, so the effect is not negligible.This is the same class of issue as the recently fixed tick-interval metric (#514): the sample boundary didn't line up with the unit of work — there it inflated the tail, here it deflates the percentiles.
Change
TimingGuard::discard()to cancel a measurement before the guard drops (adisarmedflag checked inDrop).on_block_core.The block hashing (
hash_tree_root) stays inside the timed span since it is real work; only the sample for a no-op duplicate is dropped. All other early returns (validation rejections) still record, as they represent real processing time.Verification
make fmt,make lint(clean), full workspace build. Two new unit tests intiming.rscover the guard:records_a_sample_on_dropanddiscard_suppresses_the_sample(both pass).cargo test -p ethlambda-blockchain46 unit tests pass. Fork-choice/signature spec tests require downloaded fixtures (absent in this env).