Skip to content

fix(nonce): compute next epoch nonce from frozen candidate#79

Merged
wcatz merged 1 commit intomasterfrom
fix/next-epoch-nonce-computation
Feb 17, 2026
Merged

fix(nonce): compute next epoch nonce from frozen candidate#79
wcatz merged 1 commit intomasterfrom
fix/next-epoch-nonce-computation

Conversation

@wcatz
Copy link
Copy Markdown
Owner

@wcatz wcatz commented Feb 17, 2026

Summary

  • GetNonceForEpoch(N+1) always failed at the leaderlog trigger point (60% of epoch N) because the next epoch's nonce doesn't exist in DB, Koios, or chain sync yet
  • Added TICKN rule computation: epochNonce = BLAKE2b-256(candidateNonce_N || lastBlockHash_N-1)
  • New Store methods: GetCandidateNonce, GetLastBlockHashForEpoch

Test plan

  • All 20 tests pass (go test ./... -v)
  • go vet clean
  • Deploy and verify epoch 614 leaderlog computes successfully

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Improvements

    • Enhanced nonce computation to use local on-chain data when available, improving reliability and reducing external service dependency.
  • Tests

    • Added comprehensive test coverage for new nonce retrieval functionality.

GetNonceForEpoch(N+1) always failed at the leaderlog trigger point
(60% of epoch N) because the next epoch's nonce doesn't exist in DB,
chain sync, or Koios yet. Added TICKN rule computation path:
  epochNonce = BLAKE2b-256(candidateNonce_N || lastBlockHash_N-1)

New Store methods: GetCandidateNonce, GetLastBlockHashForEpoch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wcatz wcatz merged commit cda8327 into master Feb 17, 2026
1 check passed
@wcatz wcatz deleted the fix/next-epoch-nonce-computation branch February 17, 2026 10:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 17, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The pull request adds database accessor methods to both PgStore and SqliteStore for retrieving candidate nonces and last block hashes by epoch. The GetNonceForEpoch function is enhanced with a full-mode computation path that derives epoch nonces from frozen candidate nonces and block hashes, using Koios as a fallback. Tests validate the new database methods.

Changes

Cohort / File(s) Summary
Store Interface & Implementations
store.go, db.go
Added GetCandidateNonce and GetLastBlockHashForEpoch methods to Store interface and implemented in both SqliteStore and PgStore to query epoch_nonces and blocks tables respectively.
Nonce Computation Logic
nonce.go
Enhanced GetNonceForEpoch with full-mode path: computes next epoch nonce as hash(candidate_nonce || last_block_hash) when frozen candidate exists, with Koios fallback for missing conditions.
Tests
store_test.go
Added TestGetCandidateNonce and TestGetLastBlockHashForEpoch to validate candidate nonce retrieval, storage, and last block hash lookup across epochs.

Sequence Diagram

sequenceDiagram
    participant Client as Caller
    participant Nonce as GetNonceForEpoch
    participant Store as Store (DB)
    participant Cache as Nonce Cache
    participant Koios as Koios Fallback

    Client->>Nonce: GetNonceForEpoch(ctx, epoch)
    alt Full Mode & Previous Epoch Data Available
        Nonce->>Store: GetCandidateNonce(epoch-1)
        Store-->>Nonce: candidate_nonce (or error)
        alt Candidate Exists
            Nonce->>Store: GetLastBlockHashForEpoch(epoch-1)
            Store-->>Nonce: block_hash (or error)
            alt Last Block Hash Exists
                Nonce->>Nonce: Derive: hash(candidate || block_hash)
                Nonce->>Cache: Cache derived nonce
                Cache-->>Nonce: ✓ Cached
                Nonce-->>Client: Derived nonce
            else No Block Hash
                Nonce->>Koios: Fetch nonce
                Koios-->>Nonce: nonce
                Nonce-->>Client: Koios nonce
            end
        else No Candidate
            Nonce->>Koios: Fetch nonce
            Koios-->>Nonce: nonce
            Nonce-->>Client: Koios nonce
        end
    else Non-Full Mode or No Data
        Nonce->>Koios: Fetch nonce
        Koios-->>Nonce: nonce
        Nonce-->>Client: Koios nonce
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A nonce by any other hash
Would smell as sweet, cache so fast!
From frozen candidates we derive,
In full mode chains our hopes survive. 🔗✨

✨ 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/next-epoch-nonce-computation

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 18, 2026
fix(nonce): compute next epoch nonce from frozen candidate
wcatz added a commit that referenced this pull request Feb 18, 2026
fix(nonce): compute next epoch nonce from frozen candidate
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