Skip to content

cardano-rpc: Add ReadGenesis method - #1277

Open
carbolymer wants to merge 5 commits into
masterfrom
mgalazyn/feature/rpc-add-readgenesis-method
Open

cardano-rpc: Add ReadGenesis method#1277
carbolymer wants to merge 5 commits into
masterfrom
mgalazyn/feature/rpc-add-readgenesis-method

Conversation

@carbolymer

@carbolymer carbolymer commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Context

Implements the UTxO RPC QueryService.ReadGenesis method in cardano-rpc.
Fixes #1217.

The response carries:

  • genesis - the Blake2b-256 hash of the raw Shelley genesis file bytes, matching what Dolos returns and what cardano-node itself computes at startup.
  • caip2 - a chain identifier keyed on the Shelley network magic: cardano:mainnet, cardano:preprod, cardano:preview, or cardano:<magic> for other networks (matches Dolos, since the spec leaves the format open).
  • cardano - the full per-era genesis configuration: Byron (proto fields 1-9), Shelley (10-23, including initial_funds), Alonzo (24-31) and Conway (32-42), with cost_models composed from Alonzo's PlutusV1 and Conway's PlutusV3 models.

The handler performs no disk reads: all genesis data comes from values cardano-node already parsed at boot, threaded into mkNodeKernelAccess via ProtocolInfoArgs (whose TransitionConfig retains the full, uncompacted ShelleyGenesis - consensus's own copy erases sgInitialFunds/sgStaking) and a Shelley genesis hash returned alongside SomeConsensusProtocol. The cardano-node side of that threading is a separate cardano-node PR.

How to trust this PR

  • The commit sequence separates the proto change, the regenerated code, the cardano-api export additions, the implementation and the tests - the Regenerate proto code commit can be skipped when reviewing.
  • Test.Cardano.Rpc.Genesis.Fixture proves the wire encodings byte-for-byte against trimmed mainnet genesis JSON parsed with the ledger's own readers (AVVM base64 keys, base58 Byron addresses, hex hashes, LovelacePortion numerators, the seconds-to-milliseconds slotLength conversion).
  • Test.Cardano.Rpc.Genesis.Property checks structural correspondence of all four era mappers on arbitrary ledger-generated genesis values (map sizes, key sets, exact rational numerators/denominators).
  • An end-to-end test (TASTY_PATTERN='/RPC ReadGenesis/' cabal test cardano-testnet-test, in the cardano-node PR) starts a testnet with RPC enabled and asserts initial_funds is non-empty - which only holds if the uncompacted boot-time genesis reaches the wire.
  • Run the whole unit suite with TASTY_PATTERN='genesis' cabal test cardano-rpc-test.

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
  • Self-reviewed the diff
  • Changelog fragment added in .changes/

@carbolymer carbolymer changed the title Mgalazyn/feature/rpc add readgenesis method cardano-rpc: Add ReadGenesis method Aug 4, 2026
@carbolymer
carbolymer marked this pull request as ready for review August 4, 2026 14:22
Copilot AI lite review requested due to automatic review settings August 4, 2026 14:22
@carbolymer
carbolymer force-pushed the mgalazyn/feature/rpc-add-readgenesis-method branch from 34a5576 to 6588f07 Compare August 4, 2026 14:25
@carbolymer carbolymer self-assigned this Aug 4, 2026
@carbolymer carbolymer moved this to In Progress in DevTools roadmap Aug 4, 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

Implements the UTxO RPC QueryService.ReadGenesis endpoint in cardano-rpc, sourcing per-era genesis configuration from in-process node kernel access (boot-time parsed configs) and exposing it over gRPC along with a Shelley genesis hash and CAIP-2 chain identifier.

Changes:

  • Add ReadGenesis to the QueryService proto and generated bindings, wire it into the server, and implement readGenesisMethod.
  • Introduce a GenesisBundle in node-kernel access and a new UtxoRpc.Type.Genesis mapper to populate the full per-era cardano.Genesis message (Byron/Shelley/Alonzo/Conway).
  • Add fixture-based and property-based tests plus genesis JSON fixtures to validate mapping/encoding.

Reviewed changes

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

Show a summary per file
File Description
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Query.hs Implements readGenesisMethod, CAIP-2 derivation, and returns genesis hash + mapped config.
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type/Genesis.hs New conversion module mapping per-era ledger genesis/params into the U5c.Genesis proto.
cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess/Type.hs Adds GenesisBundle and stores genesis config in NodeKernelAccess.
cardano-rpc/src/Cardano/Rpc/Server/NodeKernelAccess.hs Changes mkNodeKernelAccess to accept boot-time inputs and builds GenesisBundle.
cardano-rpc/src/Cardano/Rpc/Server/Internal/Tracing.hs Adds new trace constructors for ReadGenesis and node-kernel-access events.
cardano-rpc/src/Cardano/Rpc/Server.hs Registers ReadGenesis handler and wraps it in a tracing span.
cardano-rpc/proto/utxorpc/v1beta/query/query.proto Adds rpc ReadGenesis(...) to QueryService.
cardano-rpc/gen/Proto/Utxorpc/V1beta/Query/Query.hs Regenerated service bindings to include ReadGenesis.
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type/Certificate.hs Factors constitution conversion into a shared helper (reused by genesis mapping).
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type/Governance.hs Uses the new constitution helper.
cardano-rpc/src/Cardano/Rpc/Server/Internal/UtxoRpc/Type.hs Re-exports genesisBundleToProto.
cardano-rpc/cardano-rpc.cabal Adds new module and dependencies; extends test-suite deps and modules.
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/Genesis/Fixture.hs Differential tests against real (trimmed) mainnet genesis JSON fixtures.
cardano-rpc/test/cardano-rpc-test/Test/Cardano/Rpc/Genesis/Property.hs Structural property tests for all era mappers with bounded generators/clipping.
cardano-rpc/test/cardano-rpc-test/files/genesis/byron-genesis.json Byron genesis fixture.
cardano-rpc/test/cardano-rpc-test/files/genesis/shelley-genesis.json Shelley genesis fixture.
cardano-rpc/test/cardano-rpc-test/files/genesis/alonzo-genesis.json Alonzo genesis fixture.
cardano-rpc/test/cardano-rpc-test/files/genesis/conway-genesis.json Conway genesis fixture.
cardano-rpc/test/cardano-rpc-test/cardano-rpc-test.hs Adjusts tasty-discover options.
cardano-api/src/Cardano/Api/LedgerState.hs Exports readShelleyGenesis + error types for downstream use.
cardano-api/src/Cardano/Api/Consensus.hs Re-exports additional consensus helpers needed for node-kernel threading.
cardano-api/src/Cardano/Api/Consensus/Internal/Protocol.hs Exposes helpers to extract transition config / Byron params from protocol args.
cardano-api/src/Cardano/Api/Consensus/Internal/Reexport.hs Re-exports shelleyLedgerGenesis.
.changes/20260804_cardano_rpc_readgenesis.yml Changelog fragment for cardano-rpc ReadGenesis work.
.changes/20260804_cardano_api_readgenesis_reexports.yml Changelog fragment for cardano-api export/re-export additions.

Comment on lines +169 to +173
-- | Handle the @ReadGenesis@ RPC method.
-- Returns the chain's identity - the Shelley genesis hash and the CAIP-2 chain
-- identifier - together with the @cardano@ config, the Byron, Shelley, Alonzo
-- and Conway genesis parameters mapped by 'genesisBundleToProto'.
readGenesisMethod
Comment on lines +3 to +6
kind:
- feature
description: |
Add the `QueryService.ReadGenesis` UTxO RPC method, returning the full per-era genesis configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

gRPC: Implement ReadGenesis (UTxO RPC QueryService) in cardano-rpc

3 participants