Skip to content

Migrate tx-generator to the experimental Cardano API (Conway and later) #6592

@carbolymer

Description

@carbolymer

Background

Raised by @Jimbo4350 in review of PR #6575.

The experimental Cardano API (Cardano.Api.Experimental) provides makeUnsignedTx and signTx as the supported transaction construction path, replacing direct ledger-level construction.
It only supports Conway and Dijkstra eras.

Mainnet is on Conway (protocol version 9+) and all production benchmark profiles already target Conway exclusively.
No active profile sets an era below Conway.
The pre-Conway code paths are dead in production.

This targets the master branch version of the code.

Scope

Paths are relative to bench/tx-generator/.

Core transaction building

  • src/Cardano/TxGenerator/Tx.hs - rewrite genTx from manual Ledger.mkBasicTx / WitVKey / ShelleyTx construction to Exp.makeUnsignedTx + Exp.makeKeyWitness + Exp.signTx.

Era dispatch - narrow to Conway + Dijkstra

  • src/Cardano/Benchmarking/Script/Core.hs:71-81 - withEra dispatches on every era from Shelley to Dijkstra. Remove pre-Conway branches.
  • src/Cardano/TxGenerator/Fund.hs:80-88 - getFundWitness pattern-matches on every era in InAnyCardanoEra. Narrow to Conway and Dijkstra.
  • src/Cardano/TxGenerator/Utils.hs:27-35 - liftAnyEra pattern-matches on every era in InAnyCardanoEra. Narrow to Conway and Dijkstra.
  • nix/nixos/tx-generator-service.nix:120-128 - the era option enum lists shelley through conway. Narrow to conway and dijkstra.

Selftest era migration

  • src/Cardano/Benchmarking/Script/Selftest.hs:103 - change AnyCardanoEra AllegraEra to AnyCardanoEra ConwayEra.

The era binding propagates consistently to all AddFund, Submit, and createChange actions - no witness mismatch.
The change is structurally safe: no golden files, no asserted transaction sizes, no hardcoded expected values exist.

However, the protocol parameter conversion takes a different code path for Conway (via toConwayPParamstoBabbagePParamstoAlonzoCommonPParams) and requires fields not needed for Allegra (executionUnitPrices, maxTxExecutionUnits, utxoCostPerByte, costModels, etc.).
The current data/protocol-parameters.json has protocolVersion: {major: 6} (Shelley/Allegra vintage) - semantically wrong for Conway.

  • Update selftest protocol parameters file to data/protocol-parameters-v9.json (or v10), which already exists in the data directory with Conway-appropriate values (PlutusV1/V2/V3 cost models, utxoCostPerByte: 538, version 9).

  • test/Bench.hs:21 - uses runSelftest for criterion benchmarks. Only checks Right/Left, no size assertions. Verify it passes after the era + parameter file change.

Unaffected areas:

  • SizedMetadata costs differ between eras (Allegra: 39 bytes first entry, Conway: 42 bytes) but are not exercised by the selftest (TxMetadataNone throughout).
  • Plutus script handling is not exercised (selftest uses PayToAddr exclusively).
  • Genesis configuration is not used (selftest loads protocol parameters directly from JSON).
  • Transaction CBOR size will change (Conway body has additional fields) but is unasserted.

Other files

  • src/Cardano/TxGenerator/PureExample.hs - hardcodes BabbageEra throughout. Rewrite to Conway using the experimental API.
  • src/Cardano/Benchmarking/GeneratorTx/SizedMetadata.hs:48-95 - per-era cost properties from Shelley to Dijkstra. Keep for completeness.

Definition of done

  • tx-generator builds with no warnings on the experimental API.
  • selftest CLI passes on Conway with the v9/v10 protocol parameters.
  • test/Bench.hs criterion benchmark passes.
  • No remaining sub-Conway transaction construction paths in bench/tx-generator/.
  • Per-era dispatchers (withEra, getFundWitness, liftAnyEra) narrowed to Conway + Dijkstra.
  • Nix era enum updated.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions