Skip to content

feat(ledger): initialize genesis network state#2838

Merged
wolf31o2 merged 1 commit into
mainfrom
codex/issue-1959-genesis-reserves
Jul 15, 2026
Merged

feat(ledger): initialize genesis network state#2838
wolf31o2 merged 1 commit into
mainfrom
codex/issue-1959-genesis-reserves

Conversation

@wolf31o2

@wolf31o2 wolf31o2 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Summary

  • initialize slot-0 network state from genesis circulation and max supply
  • backfill missing genesis network state for upgrade-safe databases
  • cover direct genesis and Mithril import paths

Part of #1959.

Validation

  • make golines
  • golangci-lint run ./...
  • make import-boundaries
  • go build ./cmd/dingo
  • go build -tags extra_plugins ./cmd/dingo
  • go test -race ./ledger ./ledgerstate
  • go test -race ./internal/test/conformance
  • internal/test/devnet/run-tests.sh

modernize ./... and nilaway ./... were also run; both report existing findings outside this change.

Documentation

  • updated DATABASE.md
  • updated ARCHITECTURE.md

Summary by cubic

Initialize slot-0 network_state (treasury/reserves) from genesis and persist certified account state on Mithril import so epoch rewards, MIR, donations, and pot transitions start from the correct baseline. Contributes to #1959 by deriving reserves as maxLovelaceSupply minus combined Byron+Shelley genesis UTxOs and safely backfilling older databases.

  • New Features

    • From-genesis startup writes the slot-0 baseline: treasury 0, reserves = maxLovelaceSupply − sum(genesis UTxOs), with input validation.
    • Backfill slot-0 baseline for matching-genesis databases when network_state is empty; no rewrite when history exists.
    • Mithril import persists AccountState treasury/reserves at the imported tip (no genesis derivation).
    • Updated devnet config to exercise reserves depletion; added tests and docs.
  • Migration

    • New syncs: no action; baseline is created automatically.
    • Existing DB with matching genesis and empty network_state: baseline is backfilled on startup.
    • If your DB already contains later network_state rows, resync from genesis to reconstruct the correct history.

Written for commit c090c89. Summary will update on new commits.

Review in cubic

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2
wolf31o2 requested review from a team as code owners July 15, 2026 12:21
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@wolf31o2, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 54338271-f6a3-4595-ae94-1fcb691e6329

📥 Commits

Reviewing files that changed from the base of the PR and between 3806f3d and c090c89.

📒 Files selected for processing (7)
  • ARCHITECTURE.md
  • DATABASE.md
  • internal/test/devnet/testnet.yaml
  • ledger/chainsync.go
  • ledger/genesis_network_state.go
  • ledger/genesis_network_state_test.go
  • ledgerstate/network_state_import_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-1959-genesis-reserves

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Re-trigger cubic

Comment thread ledger/chainsync.go
if err != nil {
return fmt.Errorf("get existing network state: %w", err)
}
if state != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is returning silently when network_state already has rows. If a node ran epoch boundaries under the old bug (reserves defaulted to 0), its existing rows are wrong and the PR says it needs a resync — but nothing in the logs tells the operator that. Can't distinguish "already backfilled, fine" from "needs resync" just by watching logs.

Fix: Please add one log line for the early return

if state != nil {
    ls.config.Logger.Debug(
        "network state already present, skipping genesis baseline backfill",
        "component", "ledger",
        "slot", state.Slot,
        "treasury", uint64(state.Treasury),
        "reserves", uint64(state.Reserves),
    )
    return nil
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. Resync from scratch is common for our operators. We don't guarantee backfill or fixing data on upgrade.

arepala-uml
arepala-uml previously approved these changes Jul 15, 2026
@wolf31o2
wolf31o2 force-pushed the codex/issue-1959-genesis-reserves branch from 54c3d04 to c090c89 Compare July 15, 2026 14:46
@wolf31o2

Copy link
Copy Markdown
Member Author

Merging without waiting. I pushed back to the approved exact ref.

@wolf31o2
wolf31o2 merged commit d144e45 into main Jul 15, 2026
18 checks passed
@wolf31o2
wolf31o2 deleted the codex/issue-1959-genesis-reserves branch July 15, 2026 14:49
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.

2 participants