Conversation
1. Fix canceled context in /nextblock command: - Move cancelShort() after scheduleNonceMatches() call - Prevents passing canceled context to function 2. Add in-memory verified nonce cache: - Add verifiedNonces map[int][]byte to NonceTracker - Check cache before recomputing from genesis (10min operation) - Prevents blocking adder pipeline on hot paths - Cache guards with existing mutex Resolves CodeRabbit findings from PR #71. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR adds verified epoch nonce caching to NonceTracker and integrates nonce validation checks throughout the leader schedule pipeline. Cached schedules are now validated against the currently expected nonce before use; mismatches trigger fresh schedule computation instead of relying on stale data. Changes
Sequence DiagramsequenceDiagram
actor Client
participant Indexer
participant NonceTracker
participant Database
Client->>Indexer: Request leaderlog/nextblock
Indexer->>Indexer: Check cached schedule
alt Cached schedule exists
Indexer->>NonceTracker: GetVerifiedNonceForEpoch(epoch-1)
NonceTracker->>NonceTracker: Check verifiedNonces cache
alt Nonce in cache
NonceTracker-->>Indexer: Return cached nonce
else Cache miss
NonceTracker->>NonceTracker: ComputeEpochNonce()
NonceTracker->>Database: Check DB cache
alt DB differs from computed
NonceTracker->>Database: Write corrected nonce
end
NonceTracker->>NonceTracker: Update verifiedNonces cache
NonceTracker-->>Indexer: Return verified nonce
end
Indexer->>Indexer: scheduleNonceMatches(cached_schedule)
alt Nonces match
Indexer-->>Client: Use cached schedule
else Nonces mismatch (stale)
Indexer->>Indexer: Compute fresh schedule
Indexer-->>Client: Use fresh schedule
end
else No cached schedule
Indexer->>Indexer: Compute fresh schedule
Indexer-->>Client: Return schedule
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly Related PRs
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
regression) PR #73 replaced all GetNonceForEpoch calls with GetVerifiedNonceForEpoch, which recomputes nonces by streaming all ~2.1M blocks from Shelley genesis on every uncached lookup. This made the bot unable to calculate leader schedules — every nonce lookup either timed out or took minutes. Changes: - Revert all GetVerifiedNonceForEpoch -> GetNonceForEpoch (trust DB cache) - Remove GetVerifiedNonceForEpoch function entirely - Remove scheduleNonceMatches (called GetVerifiedNonceForEpoch on hot paths) - Remove verifiedNonces in-memory cache (no longer needed) - Keep backfillSchedules epoch-1 fix from PR #73 (correct bug fix) - Fix withQuery deadlock: move close(connClosed) to top-level defer so it always fires even if NewConnection fails Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
regression) (#74) PR #73 replaced all GetNonceForEpoch calls with GetVerifiedNonceForEpoch, which recomputes nonces by streaming all ~2.1M blocks from Shelley genesis on every uncached lookup. This made the bot unable to calculate leader schedules — every nonce lookup either timed out or took minutes. Changes: - Revert all GetVerifiedNonceForEpoch -> GetNonceForEpoch (trust DB cache) - Remove GetVerifiedNonceForEpoch function entirely - Remove scheduleNonceMatches (called GetVerifiedNonceForEpoch on hot paths) - Remove verifiedNonces in-memory cache (no longer needed) - Keep backfillSchedules epoch-1 fix from PR #73 (correct bug fix) - Fix withQuery deadlock: move close(connClosed) to top-level defer so it always fires even if NewConnection fails Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
regression) (#75) PR #73 replaced all GetNonceForEpoch calls with GetVerifiedNonceForEpoch, which recomputes nonces by streaming all ~2.1M blocks from Shelley genesis on every uncached lookup. This made the bot unable to calculate leader schedules — every nonce lookup either timed out or took minutes. Changes: - Revert all GetVerifiedNonceForEpoch -> GetNonceForEpoch (trust DB cache) - Remove GetVerifiedNonceForEpoch function entirely - Remove scheduleNonceMatches (called GetVerifiedNonceForEpoch on hot paths) - Remove verifiedNonces in-memory cache (no longer needed) - Keep backfillSchedules epoch-1 fix from PR #73 (correct bug fix) - Fix withQuery deadlock: move close(connClosed) to top-level defer so it always fires even if NewConnection fails Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* fix(leaderlog): verify nonce from chain before serving schedules * fix(pr71): address CodeRabbit performance and context issues 1. Fix canceled context in /nextblock command: - Move cancelShort() after scheduleNonceMatches() call - Prevents passing canceled context to function 2. Add in-memory verified nonce cache: - Add verifiedNonces map[int][]byte to NonceTracker - Check cache before recomputing from genesis (10min operation) - Prevents blocking adder pipeline on hot paths - Cache guards with existing mutex Resolves CodeRabbit findings from PR #71. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
regression) (#74) PR #73 replaced all GetNonceForEpoch calls with GetVerifiedNonceForEpoch, which recomputes nonces by streaming all ~2.1M blocks from Shelley genesis on every uncached lookup. This made the bot unable to calculate leader schedules — every nonce lookup either timed out or took minutes. Changes: - Revert all GetVerifiedNonceForEpoch -> GetNonceForEpoch (trust DB cache) - Remove GetVerifiedNonceForEpoch function entirely - Remove scheduleNonceMatches (called GetVerifiedNonceForEpoch on hot paths) - Remove verifiedNonces in-memory cache (no longer needed) - Keep backfillSchedules epoch-1 fix from PR #73 (correct bug fix) - Fix withQuery deadlock: move close(connClosed) to top-level defer so it always fires even if NewConnection fails Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
regression) (#75) PR #73 replaced all GetNonceForEpoch calls with GetVerifiedNonceForEpoch, which recomputes nonces by streaming all ~2.1M blocks from Shelley genesis on every uncached lookup. This made the bot unable to calculate leader schedules — every nonce lookup either timed out or took minutes. Changes: - Revert all GetVerifiedNonceForEpoch -> GetNonceForEpoch (trust DB cache) - Remove GetVerifiedNonceForEpoch function entirely - Remove scheduleNonceMatches (called GetVerifiedNonceForEpoch on hot paths) - Remove verifiedNonces in-memory cache (no longer needed) - Keep backfillSchedules epoch-1 fix from PR #73 (correct bug fix) - Fix withQuery deadlock: move close(connClosed) to top-level defer so it always fires even if NewConnection fails Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary by CodeRabbit