Skip to content

Fix/pr71 coderabbit issues#73

Merged
wcatz merged 2 commits intomasterfrom
fix/pr71-coderabbit-issues
Feb 12, 2026
Merged

Fix/pr71 coderabbit issues#73
wcatz merged 2 commits intomasterfrom
fix/pr71-coderabbit-issues

Conversation

@wcatz
Copy link
Copy Markdown
Owner

@wcatz wcatz commented Feb 12, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced leader schedule validation by verifying epoch nonce consistency before using cached schedules.
    • Automatically detects and refreshes stale schedules instead of relying on potentially outdated data.
    • Strengthens reliability of leaderlog queries and nextblock operations by preventing use of schedules with mismatched nonces.
    • Ensures on-demand schedule computations align with expected epoch nonce values for improved accuracy.

wcatz and others added 2 commits February 12, 2026 08:45
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>
@wcatz wcatz merged commit d0c7f5b into master Feb 12, 2026
2 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Nonce Verification and Caching
nonce.go
Introduces in-memory cache verifiedNonces in NonceTracker and adds GetVerifiedNonceForEpoch() method. In full mode, checks cache first, recomputes via ComputeEpochNonce if needed, repairs DB cache on mismatch, and updates both caches. Delegates to GetNonceForEpoch in lite mode.
Schedule Validation
commands.go
Adds scheduleNonceMatches() helper method to Indexer to verify that a cached LeaderSchedule was built with the expected epoch nonce. Replaces direct nonce fetches with GetVerifiedNonceForEpoch calls in leaderlog and nextblock paths.
Validation Integration
main.go
Integrates scheduleNonceMatches() checks in leaderlog trigger and backfill paths to validate cached schedules before use. Replaces GetNonceForEpoch with GetVerifiedNonceForEpoch for verified nonce retrieval. Adds validation guard before caching schedule existence flags.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly Related PRs

Poem

🐰 A rabbit hops through schedules old and new,
Checking nonces verify before they're due,
Stale caches caught, fresh schedules bloom,
With verification logic clearing the gloom!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/pr71-coderabbit-issues

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

wcatz added a commit that referenced this pull request Feb 12, 2026
 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>
wcatz added a commit that referenced this pull request Feb 12, 2026
 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>
wcatz added a commit that referenced this pull request Feb 12, 2026
 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>
@wcatz wcatz deleted the fix/pr71-coderabbit-issues branch February 18, 2026 03:18
wcatz added a commit that referenced this pull request Feb 18, 2026
* 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>
wcatz added a commit that referenced this pull request Feb 18, 2026
 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>
wcatz added a commit that referenced this pull request Feb 18, 2026
 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>
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.

1 participant