Repository navigation
cardano-rpc: fix ReadGenesis initial funds and stop retaining the genesis in memory - #1305
Conversation
There was a problem hiding this comment.
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(includingEmbeddedInjectionandInjectionFromFilewith hash verification) when constructing theGenesisBundle. - Make
mkNodeKernelAccess/readGenesisBundlemonad-polymorphic with(MonadST m, MonadThrow m)and unify theProtocolInfoArgsmonad with the ambient monad. - Update
cardano-rpclibrary dependencies to includefs-apiandio-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.
| initialFundsSource <- | ||
| L.resolveInjectionSource | ||
| "initialFunds" | ||
| (L.sgExtraConfig genesis) | ||
| L.secInitialFunds | ||
| (L.sgInitialFunds genesis) | ||
| resolvedInitialFunds <- | ||
| Exts.fromList <$> L.foldInjectionData hasFS initialFundsSource (flip (:)) [] |
444e652 to
518ecea
Compare
c0d48b9 to
39619bb
Compare
d9e0d14 to
422853f
Compare
422853f to
d054f18
Compare
d054f18 to
40865a0
Compare
| let transCfg = Ledger.mkLatestTransitionConfig shelleyGenesis alonzoGenesis conwayGenesis dijkstraGenesis | ||
| pure $ GenesisCardano enc byronGenesis shelleyGenesisHash transCfg | ||
|
|
||
| -- | Resolve a Shelley genesis' 'Ledger.sgInitialFunds' against its |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
6072730 to
7551026
Compare
…med cache of resolved Shelley Genesis.
7551026 to
9c71b65
Compare
Context
The UTxO RPC
ReadGenesisresponse reported an emptyinitial_fundsmap for any network created withcardano-cli create-testnet-data.create-testnet-dataprovisions wallets by writing their funded addresses into the Shelley genesis'sgExtraConfig.secInitialFunds, leaving the legacysgInitialFundsfield empty, but cardano-rpc'sReadGenesishandler read onlysgInitialFunds.Fixing that at
GenesisBundleconstruction time would have entrenched #1314: the bundle already retained the whole boot-timeTransitionConfig, 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.
GenesisBundleno longer stores anything reachable fromProtocolInfoArgs.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.
ReadGenesishandler 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 withFAILED_PRECONDITION.Initial funds are resolved with ledger's own
resolveInjectionSource/foldInjectionData, handling bothEmbeddedInjectionandInjectionFromFile, the latter streamed with content-hash verification.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.
resolveShelleyInitialFunds, operating on aShelleyGenesis.mkNodeKernelAccessno longer takesProtocolInfoArgsand takes the Shelley genesis file path instead.The original bug was caught by the
ReadGenesisintegration test added in cardano-node PR #6655.A stacked cardano-node PR adapting the
mkNodeKernelAccesscall site and re-enabling theinitialFundsassertion will follow.How to trust this PR
cabal test cardano-rpc-test, 98 tests); the Genesis fixture and property tests pin the per-era proto mappings byte-for-byte.source-repository-packagestanza in cardano-node'scabal.projectpointing at this branch's head commit, the stacked cardano-node PR will demonstrate the initial-funds fix against the real integration test.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 inGenesisBundleholds the parsed genesis after startup.Checklist
TimedCacheand the funds resolution are queued on this branch; integration coverage is theReadGenesistest in the stacked cardano-node PR.changes/