Skip to content

cardano-rpc: fix ReadGenesis initial funds and stop retaining the genesis in memory - #1305

Merged
carbolymer merged 1 commit into
masterfrom
mgalazyn/fix/rpc-initial-funds-extraconfig
Aug 25, 2026
Merged

carbolymer merged 1 commit into
masterfrom
mgalazyn/fix/rpc-initial-funds-extraconfig

Conversation

@carbolymer

@carbolymer carbolymer commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Context

The UTxO RPC ReadGenesis response reported an empty initial_funds map for any network created with cardano-cli create-testnet-data.
create-testnet-data provisions wallets by writing their funded addresses into the Shelley genesis' sgExtraConfig.secInitialFunds, leaving the legacy sgInitialFunds field empty, but cardano-rpc's ReadGenesis handler read only sgInitialFunds.

Fixing that at GenesisBundle construction time would have entrenched #1314: the bundle already retained the whole boot-time TransitionConfig, keeping the full parsed genesis in memory for the node's lifetime whether or not RPC was enabled.
This PR fixes both problems together.

Fixes #1314.

  • GenesisBundle no longer stores anything reachable from ProtocolInfoArgs.
    The Byron, Alonzo and Conway genesis values are shared with consensus' own ledger config, and the Shelley genesis is not kept at all, since the only copy the node has is compacted with the initial funds erased.
  • The ReadGenesis handler reads the Shelley genesis file on demand and verifies its bytes against the hash the node computed at startup; a file that changed since startup fails the request with FAILED_PRECONDITION.
    Initial funds are resolved with ledger's own resolveInjectionSource/foldInjectionData, handling both EmbeddedInjection and InjectionFromFile, the latter streamed with content-hash verification.
  • The resolved genesis is held in a new TimedCache: concurrent requests arriving at an empty cache share a single load, every read extends the value's life, and it empties itself after five minutes without a read.
    An idle or unqueried node retains no genesis data and runs no cache thread.
  • cardano-api additionally exports resolveShelleyInitialFunds, operating on a ShelleyGenesis.
  • Breaking: mkNodeKernelAccess no longer takes ProtocolInfoArgs and takes the Shelley genesis file path instead.

The original bug was caught by the ReadGenesis integration test added in cardano-node PR #6655.
A stacked cardano-node PR adapting the mkNodeKernelAccess call site and re-enabling the initialFunds assertion will follow.

How to trust this PR

  • The cardano-rpc unit suite passes (cabal test cardano-rpc-test, 98 tests); the Genesis fixture and property tests pin the per-era proto mappings byte-for-byte.
  • Consumed via a temporary source-repository-package stanza in cardano-node's cabal.project pointing at this branch's head commit, the stacked cardano-node PR will demonstrate the initial-funds fix against the real integration test.
  • The retention fix has not been heap-profiled yet.
    To verify it, profile a node with a large genesis as in [BUG] - Retained genesis in cardano-rpc #1314: the Addr/KeyHashObj/cons-cell bands should return to their 11.0 levels, since nothing in GenesisBundle holds the parsed genesis after startup.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details - unit tests for TimedCache and the funds resolution are queued on this branch; integration coverage is the ReadGenesis test in the stacked cardano-node PR
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

@carbolymer
carbolymer requested a review from Jimbo4350 as a code owner August 20, 2026 13:42
Copilot AI lite review requested due to automatic review settings August 20, 2026 13:42
@carbolymer carbolymer self-assigned this Aug 20, 2026

Copilot AI 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.

Pull request overview

Fixes cardano-rpc’s ReadGenesis behavior so initial_funds is correctly populated for networks produced by cardano-cli create-testnet-data, where funds are stored via sgExtraConfig.secInitialFunds rather than legacy sgInitialFunds. The change resolves initial funds during GenesisBundle construction using the ledger’s injection resolution APIs, and adjusts exported types accordingly.

Changes:

  • Resolve Shelley genesis initial funds from sgExtraConfig.secInitialFunds (including EmbeddedInjection and InjectionFromFile with hash verification) when constructing the GenesisBundle.
  • Make mkNodeKernelAccess / readGenesisBundle monad-polymorphic with (MonadST m, MonadThrow m) and unify the ProtocolInfoArgs monad with the ambient monad.
  • Update cardano-rpc library dependencies to include fs-api and io-classes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess.hs Resolves Shelley initial funds via ledger injection resolution during genesis bundle construction; updates exported mkNodeKernelAccess signature accordingly.
cardano-rpc/cardano-rpc.cabal Adds fs-api and io-classes to support SomeHasFS usage and MonadST/MonadThrow constraints.
.changes/20260820_cardano_rpc_genesis_initial_funds_extraconfig.yml Adds a changelog fragment documenting the bugfix + breaking signature change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +133 to +140
initialFundsSource <-
L.resolveInjectionSource
"initialFunds"
(L.sgExtraConfig genesis)
L.secInitialFunds
(L.sgInitialFunds genesis)
resolvedInitialFunds <-
Exts.fromList <$> L.foldInjectionData hasFS initialFundsSource (flip (:)) []
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch from 444e652 to 518ecea Compare August 20, 2026 13:57
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch 2 times, most recently from c0d48b9 to 39619bb Compare August 20, 2026 14:39
@carbolymer carbolymer linked an issue Aug 24, 2026 that may be closed by this pull request
@carbolymer
carbolymer marked this pull request as draft August 24, 2026 15:32
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch 4 times, most recently from d9e0d14 to 422853f Compare August 24, 2026 20:23
@carbolymer carbolymer linked an issue Aug 24, 2026 that may be closed by this pull request
@carbolymer carbolymer changed the title cardano-rpc: resolve genesis initial funds from sgExtraConfig cardano-rpc: fix ReadGenesis initial funds and stop retaining the genesis in memory Aug 24, 2026
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch from 422853f to d054f18 Compare August 24, 2026 20:26
@carbolymer
carbolymer marked this pull request as ready for review August 24, 2026 20:26
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch from d054f18 to 40865a0 Compare August 25, 2026 12:12
let transCfg = Ledger.mkLatestTransitionConfig shelleyGenesis alonzoGenesis conwayGenesis dijkstraGenesis
pure $ GenesisCardano enc byronGenesis shelleyGenesisHash transCfg

-- | Resolve a Shelley genesis' 'Ledger.sgInitialFunds' against its

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.

Can you confirm if this resolution is temporary? I.e can we eventually remove it? You also need to give come background as to why we have to deal with this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Partially, yes. The reconciliation half exists because ShelleyGenesis still carries both the legacy sgInitialFunds and sgExtraConfig.secInitialFunds (which is what create-testnet-data writes), and the ledger reconciles them only while building the initial ledger state (resolveInjectionSource in Cardano.Ledger.Shelley.Transition), never writing the result back into the ShelleyGenesis value. sgInitialFunds isn't formally deprecated in the ledger yet, but the migration direction is the injection mechanism, and once the legacy field goes, the reconciliation goes with it. What stays necessary even then is materialising secInitialFunds itself, streaming the funds in and hash-verifying from-file sources, because a parsed genesis read outside the ledger's state-construction path never gets that for free. The Haddock on resolveShelleyInitialFunds now carries this background.

@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch 2 times, most recently from 6072730 to 7551026 Compare August 25, 2026 13:23
@carbolymer
carbolymer force-pushed the mgalazyn/fix/rpc-initial-funds-extraconfig branch from 7551026 to 9c71b65 Compare August 25, 2026 13:24
@carbolymer
carbolymer enabled auto-merge August 25, 2026 13:24
@carbolymer
carbolymer added this pull request to the merge queue Aug 25, 2026
Merged via the queue into master with commit 1f00422 Aug 25, 2026
31 checks passed
@carbolymer
carbolymer deleted the mgalazyn/fix/rpc-initial-funds-extraconfig branch August 25, 2026 13:51
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.

[BUG] - ReadGenesis doesn't read sgExtraConfig [BUG] - Retained genesis in cardano-rpc

3 participants