fix(nonce): compute next epoch nonce from frozen candidate#79
Conversation
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>
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
fix(nonce): compute next epoch nonce from frozen candidate
fix(nonce): compute next epoch nonce from frozen candidate
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 yetepochNonce = BLAKE2b-256(candidateNonce_N || lastBlockHash_N-1)GetCandidateNonce,GetLastBlockHashForEpochTest plan
go test ./... -v)go vetclean🤖 Generated with Claude Code
Summary by CodeRabbit
Improvements
Tests