cardano-rpc: Populate transaction bodies in FetchBlock responses#1247
Draft
carbolymer wants to merge 8 commits into
Draft
cardano-rpc: Populate transaction bodies in FetchBlock responses#1247carbolymer wants to merge 8 commits into
carbolymer wants to merge 8 commits into
Conversation
f9cb860 to
812cb1c
Compare
4 tasks
73e1a16 to
534dce1
Compare
812cb1c to
b0dbce2
Compare
The Rational to RationalNumber conversion used fromIntegral into the int32 numerator and uint32 denominator, which wraps modulo 2^32: a pool margin of 1 % 2^33 emitted denominator 0. The conversion now returns the best representable approximation via a continued-fraction walk when either component exceeds its field, and converts exactly otherwise. The comment claiming the conversion clips was wrong and is gone.
Handler boundary types, the Inject orphans and nested fields of Proto messages all expect Proto values, so wrapping throughout eliminates the getProto and Proto shims at every seam. The predicate matchers now take Proto-wrapped patterns and scriptWitnessIndexToRedeemerPurpose returns a Proto-wrapped enum, since grapesy rewraps enum fields too.
…pers txOutToUtxoRpcTxOutput now takes an explicit ShelleyBasedEra witness instead of IsEra, so it can convert outputs of blocks from any Shelley-based era rather than only the current one. Export txoRefUtxoRpcToTxIn and add exactAddressPredicate so RPC clients and tests build requests from library code instead of duplicating it.
fetchBlock now yields the block in era context via fromConsensusBlock instead of just the block number, so handlers can inspect the block content. The Sync proto wrapper re-exports the whole generated Cardano_Fields module (hiding the four lenses that clash with Sync_Fields), giving FetchBlock consumers access to all cardano message field lenses.
Move the conversions between cardano-api types and their UTxO RPC protobuf counterparts from the monolithic UtxoRpc.Type module into dedicated submodules: BigInt, ChainPoint, PlutusData, ProtocolParameters, Script, TxEval and TxOutput. UtxoRpc.Type becomes an umbrella module which re-exports the same names it exported before, so the import surface is unchanged and existing importers keep compiling without modification.
Map fetched block transactions onto the UTxO RPC Tx message, covering all 14 proto fields: inputs, outputs, reference inputs, certificates, withdrawals, mint, witnesses, collateral, fee, validity, successful, auxiliary data, hash and governance proposals. - Convert at ledger level for every Shelley-based era, with era-gated fields (reference inputs, mint, collateral, proposals) empty where the era predates them - Wire spending, withdrawal and certificate redeemers to their entries by script witness index; successful reflects the phase-2 IsValid flag - Add Type.Certificate mapping all 19 certificate variants (Dijkstra-safe via concrete-era dispatch) and Type.Governance mapping all 7 governance actions including partial parameter updates - Convert Byron transactions directly from the Byron ledger types (cardano-api's Tx has no Byron constructor); Byron fees are implicit and stay unset; epoch boundary blocks yield no transactions - Re-export byronBlockRaw from Cardano.Api.Consensus - Add property tests: per-field projections against generated transactions, wire-level encode/decode totality across eras, injected-redeemer wiring, a forged-annotation guard pinning Byron transaction ids to the on-chain bytes, and a golden test over a mainnet Byron block and epoch boundary block
2daffe7 to
ecc1f35
Compare
b0dbce2 to
0d12995
Compare
a5413ed to
9396d3b
Compare
Base automatically changed from
mgalazyn/refactor/rpc-reorganise-modules
to
master
July 11, 2026 02:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Part of the node kernel access work (ADR-019):
FetchBlockpreviously returned raw block bytes, the block header and the timestamp, but leftbody.txempty.This PR populates the transaction bodies. All 14 fields of the UTxO RPC
Txmessage are mapped: inputs, outputs, reference inputs, certificates, withdrawals, mint, witnesses, collateral, fee, validity, successful, auxiliary data, hash and governance proposals.successfulreflects the phase-2IsValidflag.Certificatemodule maps all 19 certificate variants (Dijkstra-safe via concrete-era dispatch); a newGovernancemodule maps all 7 governance actions including partial parameter updates.Tx erahas no Byron constructor. Byron fees are implicit in the UTxO and stay unset; epoch boundary blocks yield no transactions. This makesFetchBlockserve transaction data for the full mainnet history.byronBlockRawis re-exported fromCardano.Api.Consensus.Known limitations, deliberate and documented in code:
TxInput.as_outputis unset (resolving it requires UTxO lookups).feeis unset (implicit in Byron; requires UTxO lookups).WitnessSet;native_bytesis the fidelity escape hatch.bytes-field encoding divergences (TxOutput.addressas text, inlineDatum.hashcarrying CBOR) are tracked separately in gRPC:bytesfields encoded as text or wrong payload (TxOutput.address,Datum.hash) #1246 and not changed here.How to trust this PR
The conversion is covered at three levels:
cardano-rpc-test, 61 tests): per-field projections of generated transactions against the ledger values, certificate arm routing, injected-redeemer wiring (spending/rewarding/certifying at known indices), a wire-level protobuf encode/decode roundtrip forcing total evaluation across all eras, and a forged-annotation guard pinning Byron transaction ids to the on-chain bytes rather than a re-serialisation.cardano-testnet-test, cardano-node repository): submits a payment transaction and a native-script minting transaction over gRPC, locates their blocks, fetches them viaFetchBlockand asserts the mapped fields (hash, fee, inputs, outputs, validity, mint, witness set contents) against the submitted values.Review commit by commit; the conversion lives in
Cardano.Rpc.Server.Internal.UtxoRpc.{Type,Certificate,Governance,Byron}and the handler wiring inCardano.Rpc.Server.Internal.UtxoRpc.Sync.Run the tests:
Checklist
.changes/