fix(nonce): prevent computing nonces from incomplete chain data#76
fix(nonce): prevent computing nonces from incomplete chain data#76
Conversation
📝 WalkthroughWalkthroughGetNonceForEpoch in Changes
Sequence DiagramsequenceDiagram
participant Caller as Caller
participant Indexer as Indexer / isSynced
participant GetNonce as GetNonceForEpoch
participant Chain as Chain Data Compute
participant Koios as Koios Service
participant DB as Nonce Cache (DB)
Caller->>GetNonce: Request epoch nonce
GetNonce->>Indexer: Check last synced slot / isSynced
alt synced_slot >= epoch_end_slot
GetNonce->>Chain: Compute nonce from chain data
Chain-->>GetNonce: Computed nonce
GetNonce->>DB: Cache nonce
DB-->>GetNonce: Cached
GetNonce-->>Caller: Return chain-derived nonce
else not synced
GetNonce->>Koios: Request nonce (fallback)
Koios-->>GetNonce: Koios nonce
GetNonce->>DB: Cache Koios nonce
DB-->>GetNonce: Cached
GetNonce-->>Caller: Return Koios nonce
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Two fixes: 1. GetNonceForEpoch sync guard: In full mode, check GetLastSyncedSlot against the target epoch's end slot before computing locally. Falls through to Koios when sync is incomplete, preventing garbage nonces from being cached. 2. Historical sync gate: Add historicalSyncDone atomic flag. All data-dependent commands (leaderlog, nonce, nextblock, validate) and the auto leaderlog trigger return early with "sync in progress" until historical sync completes. Lite mode starts synced. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d91cb20 to
e74180e
Compare
Two fixes: 1. GetNonceForEpoch sync guard: In full mode, check GetLastSyncedSlot against the target epoch's end slot before computing locally. Falls through to Koios when sync is incomplete, preventing garbage nonces from being cached. 2. Historical sync gate: Add historicalSyncDone atomic flag. All data-dependent commands (leaderlog, nonce, nextblock, validate) and the auto leaderlog trigger return early with "sync in progress" until historical sync completes. Lite mode starts synced. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
GetNonceForEpochin full mode calledComputeEpochNonceduring sync, when the DB only had blocks for epochs 208-222 plus live epoch 612. The 390-epoch gap produced a garbage nonce that got permanently cached.GetLastSyncedSlotvs the target epoch's end slot before computing locally. Falls through to Koios when sync is incomplete.goduckbot_testDB already.What changed
GetNonceForEpochnow only computes from local chain data when sync has passed the target epochTest plan
go build && go vet && go test— all pass🤖 Generated with Claude Code
Summary by CodeRabbit
Improvements
New Features