fix(nonce): use per-network genesis nonce seed instead of hardcoded mainnet#118
fix(nonce): use per-network genesis nonce seed instead of hardcoded mainnet#118
Conversation
…ainnet The nonce evolution was seeded with mainnet's Shelley genesis hash for ALL networks. Preview (and preprod) have different genesis nonces, so every computed epoch nonce was wrong from epoch 0 onwards. Add per-network genesis nonce constants (verified against Koios): mainnet: 1a3be38b... (epoch 208) preprod: 162d29c4... (epoch 4) preview: 363498d1... (epoch 0) Add shelleyStartForNetwork() and genesisNonceForNetwork() helpers. Replace all hardcoded ShelleyGenesisHash references in ComputeEpochNonce, BackfillNonces, and NonceIntegrityCheck with network-aware lookups. Add PreviewShelleyStartEpoch = 0 (preview has no Byron era).
📝 WalkthroughWalkthroughThe PR introduces network-specific nonce initialization by adding genesis nonce constants for mainnet, preprod, and preview networks, creating helper functions to select network-appropriate values, and updating the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@comprehensive_test.go`:
- Around line 1642-1643: The prevNonce is created with MainnetNetworkMagic but
the test constructs the NonceTracker using PreprodNetworkMagic; update the call
to initialNonce to use PreprodNetworkMagic so the nonce network magic matches
the NonceTracker setup (change prevNonce := initialNonce(true,
MainnetNetworkMagic) to use PreprodNetworkMagic); ensure this change is applied
in the test where prevNonce is used alongside store.UpsertEvolvingNonce and the
NonceTracker instance so the recomputation/repair scenario remains identical.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f5c4c9f3-24a0-4138-8cbe-31fbdddaf3df
📒 Files selected for processing (3)
comprehensive_test.goleaderlog.gononce.go
| prevNonce := initialNonce(true, MainnetNetworkMagic) | ||
| if err := store.UpsertEvolvingNonce(ctx, epoch-1, prevNonce, 100); err != nil { |
There was a problem hiding this comment.
Network magic mismatch in test setup.
The test uses PreprodNetworkMagic for the NonceTracker (line 1648) but initializes prevNonce with MainnetNetworkMagic. For consistency with the test scenario, this should use PreprodNetworkMagic:
🔧 Suggested fix
- prevNonce := initialNonce(true, MainnetNetworkMagic)
+ prevNonce := initialNonce(true, networkMagic)The test still validates the recomputation mechanism correctly (block count mismatch triggers repair), but using the matching network magic makes the test setup more realistic and consistent.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| prevNonce := initialNonce(true, MainnetNetworkMagic) | |
| if err := store.UpsertEvolvingNonce(ctx, epoch-1, prevNonce, 100); err != nil { | |
| prevNonce := initialNonce(true, networkMagic) | |
| if err := store.UpsertEvolvingNonce(ctx, epoch-1, prevNonce, 100); err != nil { |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@comprehensive_test.go` around lines 1642 - 1643, The prevNonce is created
with MainnetNetworkMagic but the test constructs the NonceTracker using
PreprodNetworkMagic; update the call to initialNonce to use PreprodNetworkMagic
so the nonce network magic matches the NonceTracker setup (change prevNonce :=
initialNonce(true, MainnetNetworkMagic) to use PreprodNetworkMagic); ensure this
change is applied in the test where prevNonce is used alongside
store.UpsertEvolvingNonce and the NonceTracker instance so the
recomputation/repair scenario remains identical.
Summary
Nonce evolution was seeded with mainnet's Shelley genesis hash for ALL networks. Preview and preprod have different genesis nonces, so every computed epoch nonce was wrong from epoch 0 onwards.
Changes
genesisNonceForNetwork()andshelleyStartForNetwork()helpersShelleyGenesisHashreferences with network-aware lookupsPreviewShelleyStartEpoch = 0(preview has no Byron era)Test plan
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes