fix: unify sync-status definition across metric, duties, and reaggregation#438
Conversation
…ation PR #417 added the spec-aligned SyncStatusTracker (4-slot lag threshold, hysteresis, network-stall detection) and pointed lean_node_sync_status at it, but the legacy heuristic in process_block (head_slot >= current_slot, 0-slot tolerance) kept writing the same metric on every block import. The two writers raced, so the gauge flapped between two different definitions of "synced". Drop the metric write from process_block, leaving SyncStatusTracker (refreshed on tick) as the single source of truth. process_block no longer needs to compute or return the synced bool. Gate post-import reaggregation on sync_status.duties_allowed() instead of the strict bool, so "in sync" has one spec-aligned meaning across the metric, validator duties, and reaggregation.
🤖 Kimi Code ReviewOverall Assessment: Good architectural refactoring that properly separates block processing from sync status tracking. The change eliminates duplicate sync logic and ensures validator duties and reaggregation use a consistent sync gate. Issues and Concerns: 1. Potential metrics regression (Line 643-650) 2. Race condition on sync status check (Line 782)
Recommendation: Consider immediately updating the sync status tracker with the new head slot before the 3. Semantic equivalence of sync check (Line 782) let synced = head_slot >= current_slot;If Positive Notes:
Nit: The doc comment at line 638 references Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Codex Code Review
I didn’t see other obvious bugs in this small diff once that point is addressed. Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewI now have full context. Here is the review: PR #438 — fix: unify sync-status definition across metric, duties, and reaggregationOverview: This PR fixes a genuine race condition where CorrectnessThe race condition is real and the fix is correct. The two conflicting writers were:
Removing the write from The reaggregation gate change is semantically sound and consistent. Line 352 (attestation production gate) already used Subtle behavioral difference worth acknowledgingThe old For reaggregation this is harmless in practice (the PR description explicitly notes this), but it's worth confirming one startup edge case:
This is low risk, but it may be worth adding a comment that Code quality
TestingThe PR reports 38 existing unit tests pass and SummaryThe fix is correct, the implementation is clean, and the motivating race condition is clearly documented. The only non-critical note is the default- Automated review by Claude (Anthropic) · sonnet · custom prompt |
🗒️ Description / Motivation
PR #417 added the spec-aligned
SyncStatusTracker(4-slot lag threshold, hysteresis, network-stall detection) and pointedlean_node_sync_statusat it. But the legacy heuristic inprocess_block(head_slot >= current_slot, 0-slot tolerance, no hysteresis, no stall awareness) kept writing the same metric on every block import.The two writers raced on
set_node_sync_status:Whichever ran last won, so the gauge flapped between two contradictory definitions of "synced", and #417's goal of aligning the metric with leanSpec was only half-done.
What Changed
set_node_sync_statuswrite fromprocess_block.SyncStatusTracker(refreshed on each tick viaupdate_sync_status) is now the single source of truth for the metric.process_blockno longer computes/returns thesyncedbool; it returnsResult<(), StoreError>.sync_status.duties_allowed()instead of the strict bool, so reaggregation, validator duties, and the metric all share one spec-aligned definition of "in sync".Behavior
lean_node_sync_statushead >= currentduties_allowed()(tracker)Note: the reaggregation gate now reads the last-tick tracker assessment rather than recomputing at import time. During backfill the tracker reports
syncing(large head-lag), so reaggregation stays suppressed as intended; the only difference is sub-interval staleness, which is harmless here.Tests
cargo test -p ethlambda-blockchain --lib— 38 passed.cargo clippy -p ethlambda-blockchain --lib -- -D warnings— clean.cargo fmt --all -- --check— clean.Related