Skip to content

Add transaction sub-transaction commands (Dijkstra) - #1453

Merged
Jimbo4350 merged 20 commits into
masterfrom
jordan/basic-sub-tx-integration
Oct 14, 2026
Merged

Jimbo4350 merged 20 commits into
masterfrom
jordan/basic-sub-tx-integration

Conversation

@Jimbo4350

@Jimbo4350 Jimbo4350 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Changelog

- description: |
    Add the Dijkstra-only `sub-transaction {build-raw,sign,txid}` command group and a repeatable `--signed-sub-tx-file FILE` option on `dijkstra transaction build-raw` that embeds signed sub-transactions in a top-level transaction
  type:
    - feature        # introduces a new feature
    # - breaking       # the API has changed in a breaking way
    # - compatible     # the API has changed but is non-breaking
    # - optimisation   # measurable performance improvements
    # - refactoring    # QoL changes
    # - bugfix         # fixes a defect
    # - test           # fixes/modifies tests
    # - maintenance    # not directly related to the code
    # - release        # related to a new release preparation
    # - documentation  # change in code docs, haddocks...

Context

First cut of nested (sub-)transaction support in cardano-cli. Dijkstra lets a top-level transaction embed sub-transactions that other parties build and sign on their own.

cardano-cli dijkstra sub-transaction build-raw --tx-in ... --tx-out ... --guard-key-hash HASH --out-file sub.unsigned
cardano-cli dijkstra sub-transaction sign --sub-tx-file sub.unsigned --signing-key-file k.skey --out-file sub.signed
cardano-cli dijkstra sub-transaction txid --signed-sub-tx-file sub.signed
cardano-cli dijkstra transaction build-raw ... --signed-sub-tx-file sub.signed --out-file tx.body
  • sub-transaction build-raw takes the Conway-era options a sub-transaction body shares with a top-level one, plus guards (--guard-key-hash, --guard-verification-key, --guard-verification-key-file, --guard-script-hash), which replace required signers in Dijkstra. No fee, collateral, required signers or script validity.
  • Files are text envelopes Unwitnessed SubTx DijkstraEra / Witnessed SubTx DijkstraEra. Sub-transactions are fixed to Dijkstra on the API side, so there is no era index. Only signed sub-transactions can be embedded, and duplicates are rejected, since the ledger keys sub-transactions by id.
  • The group and --signed-sub-tx-file are gated on the era GADT and do not exist under conway. latest still maps to Conway.

Builds against the released cardano-api 11.9.0.0 from CHaP, which carries the merged sub-transaction support (IntersectMBO/cardano-api#1361). No source-repository-package stanzas.

Deferred to follow-ups: sub-transaction witness/assemble, --required-top-level-guard*, --direct-deposit, --account-balance-interval, --signed-sub-tx-file on the balanced build (fee estimation does not account for sub-transactions yet), and showing sub-transactions in debug transaction view.

How to trust this PR

  • Test.Golden.Dijkstra.Transaction.SubTransaction pins every file in the pipeline: unsigned and signed sub-transaction envelopes, the sub-transaction id (equal before and after signing), and a top-level body embedding the sub-transaction, which then signs and identifies as usual.
  • Test.Cli.Transaction.SubTransaction checks that the group and --signed-sub-tx-file do not parse under conway, that duplicate and unsigned sub-transactions are rejected, and that Byron keys are refused for sub-transaction signing.
  • Help golden files changed only for dijkstra; conway_* and latest_* are byte-identical.

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/

@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from 1a5e13d to 2f85784 Compare September 29, 2026 13:35
@Jimbo4350 Jimbo4350 changed the title Pin cardano-api to sub-transaction commit and adapt to API changes Add transaction sub-transaction commands (Dijkstra) Sep 29, 2026
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch 5 times, most recently from c76aa6b to 573c791 Compare September 29, 2026 19:08
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from 573c791 to 03011f3 Compare September 29, 2026 19:09
Jimbo4350 added a commit to IntersectMBO/cardano-node that referenced this pull request Sep 29, 2026
Add `hprop_nested_transaction_swap` ("Nested transaction swap"). It mints
100 TokenA to Alice in Conway and funds Bob, hard forks the cluster into
Dijkstra through governance (shared with the "Hard fork to Dijkstra"
test), then settles a multi-asset swap with a nested transaction built
with `cardano-cli dijkstra transaction sub-transaction`:

  * Alice's sub-transaction spends her 100 TokenA and pays herself 53 ADA
    (50 ADA price + the 3 ADA that travelled with the tokens);
  * Bob's sub-transaction spends 60 ADA and pays himself the 100 TokenA
    plus 7 ADA change, i.e. exactly 50 ADA;
  * the batcher's top-level transaction embeds both signed
    sub-transactions and pays the fee.

Each sub-transaction is guarded by and signed with its owner's key only.
The proof is read back from `query utxo`: Bob holds the 100 TokenA, Alice
gained exactly 50 ADA, Bob lost exactly 50 ADA, the batcher paid the fee.

The test needs a cardano-cli with the sub-transaction commands
(IntersectMBO/cardano-cli#1453), pointed at via CARDANO_CLI. It does not
assert the era after the hard fork on purpose, so that on a consensus that
never leaves Conway the failure shows up at submission ("The node is
running in the Conway era, but the transaction is for the Dijkstra era").

Supporting changes:

  * `Testnet.Components.Query.stopEpochStateView` stops the client-side
    ledger fold behind an EpochStateView. cardano-api 11.7's ledger event
    conversion has no Dijkstra case and dies on the first Dijkstra block,
    so both Dijkstra tests stop the view before PV12 can be enacted, keep
    the epoch state logger off, and observe the node through the CLI.
  * `hardForkToDijkstra` waits for PV12 via `query protocol-parameters`
    and the era assertion now explains that a Conway answer means the
    pinned consensus ignores the Dijkstra trigger.
Jimbo4350 added a commit to IntersectMBO/cardano-node that referenced this pull request Oct 5, 2026
Add `hprop_nested_transaction_swap` ("Nested transaction swap"). It mints
100 TokenA to Alice in Conway and funds Bob, hard forks the cluster into
Dijkstra through governance (shared with the "Hard fork to Dijkstra"
test), then settles a multi-asset swap with a nested transaction built
with `cardano-cli dijkstra transaction sub-transaction`:

  * Alice's sub-transaction spends her 100 TokenA and pays herself 53 ADA
    (50 ADA price + the 3 ADA that travelled with the tokens);
  * Bob's sub-transaction spends 60 ADA and pays himself the 100 TokenA
    plus 7 ADA change, i.e. exactly 50 ADA;
  * the batcher's top-level transaction embeds both signed
    sub-transactions and pays the fee.

Each sub-transaction is guarded by and signed with its owner's key only.
The proof is read back from `query utxo`: Bob holds the 100 TokenA, Alice
gained exactly 50 ADA, Bob lost exactly 50 ADA, the batcher paid the fee.

The test needs a cardano-cli with the sub-transaction commands
(IntersectMBO/cardano-cli#1453), pointed at via CARDANO_CLI.
Jimbo4350 added a commit to IntersectMBO/cardano-node that referenced this pull request Oct 5, 2026
Add `hprop_nested_transaction_swap` ("Nested transaction swap"). It mints
100 TokenA to Alice in Conway and funds Bob, hard forks the cluster into
Dijkstra through governance (shared with the "Hard fork to Dijkstra"
test), then settles a multi-asset swap with a nested transaction built
with `cardano-cli dijkstra transaction sub-transaction`:

  * Alice's sub-transaction spends her 100 TokenA and pays herself 53 ADA
    (50 ADA price + the 3 ADA that travelled with the tokens);
  * Bob's sub-transaction spends 60 ADA and pays himself the 100 TokenA
    plus 7 ADA change, i.e. exactly 50 ADA;
  * the batcher's top-level transaction embeds both signed
    sub-transactions and pays the fee.

Each sub-transaction is guarded by and signed with its owner's key only.
The proof is read back from `query utxo`: Bob holds the 100 TokenA, Alice
gained exactly 50 ADA, Bob lost exactly 50 ADA, the batcher paid the fee.

The test needs a cardano-cli with the sub-transaction commands
(IntersectMBO/cardano-cli#1453), pointed at via CARDANO_CLI, and
cardano-ledger-dijkstra >= 0.4: before IntersectMBO/cardano-ledger#6129,
UTxO-HD key fetching through `allInputsTxBodyF` did not load
sub-transaction inputs and the ledger rejected the nested transaction
with SubBadInputsUTxO.
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from 03011f3 to c506264 Compare October 6, 2026 18:49
Jimbo4350 added a commit to IntersectMBO/cardano-node that referenced this pull request Oct 6, 2026
…ction commands

Point cardano-api (and cardano-rpc) at IntersectMBO/cardano-api@c9943eb3,
which is master after IntersectMBO/cardano-api#1328 (ouroboros-consensus
5.0, cardano-ledger-core 1.22) and IntersectMBO/cardano-api#1361 (the
Dijkstra sub-transaction API), replacing the input-output-hk fork pin.

Point cardano-cli at IntersectMBO/cardano-cli@c5062645, the head of
IntersectMBO/cardano-cli#1453 ("Add transaction sub-transaction commands
(Dijkstra)") on top of the 11.2 bounds update, so that the cardano-cli in
the build plan has the `dijkstra transaction sub-transaction` commands the
"Nested transaction swap" test needs. Previously the test could only run
with CARDANO_CLI pointing at a separate build of that PR, and a build
against the old ledger at that, since its `create-testnet-data` writes a
Dijkstra genesis without `minPoolMargin`.

With these pins both Dijkstra tests pass with no environment overrides.
The cardano-cli pin is temporary: replace it once #1453 is released.
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from c506264 to 9215632 Compare October 8, 2026 12:35
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch 2 times, most recently from 7ec3f6a to ecc5d0f Compare October 8, 2026 14:17
@Jimbo4350
Jimbo4350 marked this pull request as ready for review October 8, 2026 17:05
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from ecc5d0f to 8140104 Compare October 8, 2026 17:05
Copilot AI balanced review requested due to automatic review settings October 8, 2026 17:05

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.

🟡 Changes recommended

Script guards cannot currently be witnessed, and the signing command advertises an unusable Byron-address option.

2 open findings
What changed in this PR

Adds Dijkstra-only sub-transaction construction, signing, identification, and embedding support.

Changes:

  • Adds sub-transaction build-raw, sign, and txid.
  • Embeds repeatable signed sub-transactions in top-level transactions.
  • Adds CLI, golden, help, envelope, and changelog coverage.
File Description
.changes/​20260929_114047_cardano-cli_jordan.millar_sub_transaction_commands.yml Adds the feature changelog.
cardano-cli/​cardano-cli.cabal Registers new modules and tests.
cardano-cli/​src/​Cardano/​CLI/​Compatible/​Transaction/​Run.hs Uses the relocated witness helper.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Command.hs Adds sub-transaction commands and build arguments.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Internal/​Common.hs Extracts shared transaction-building helpers.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Option.hs Integrates Dijkstra-only parsers.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​Run.hs Embeds signed sub-transactions.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Command.hs Defines command argument types.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Option.hs Defines command and guard parsers.
cardano-cli/​src/​Cardano/​CLI/​EraBased/​Transaction/​SubTransaction/​Run.hs Builds, signs, identifies, and reads sub-transactions.
cardano-cli/​src/​Cardano/​CLI/​Read.hs Reads signed and unsigned envelopes.
cardano-cli/​src/​Cardano/​CLI/​Type/​Common.hs Adds sub-transaction file types.
cardano-cli/​src/​Cardano/​CLI/​Type/​Error/​TxCmdError.hs Adds duplicate and Byron-witness errors.
cardano-cli/​test/​cardano-cli-test/​Test/​Cli/​Transaction/​SubTransaction.hs Tests rejection and era-gating behavior.
cardano-cli/​test/​cardano-cli-golden/​Test/​Golden/​Dijkstra/​Transaction/​SubTransaction.hs Tests the end-to-end pipeline.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction/​sub-transaction/​signed_out Pins the signed envelope.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction/​sub-transaction/​tx_body_with_sub_tx_out Pins the embedded transaction body.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction/​sub-transaction/​txid_out Pins the sub-transaction ID.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​dijkstra/​transaction/​sub-transaction/​unsigned_out Pins the unsigned envelope.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help.cli Updates aggregate help.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction.cli Lists the new command group.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_build-raw.cli Documents embedding options.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_sub-transaction.cli Documents the subgroup.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_sub-transaction_build-raw.cli Documents sub-transaction construction.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_sub-transaction_sign.cli Documents signing.
cardano-cli/​test/​cardano-cli-golden/​files/​golden/​help/​dijkstra_transaction_sub-transaction_txid.cli Documents ID output.

🧠 Review effort: Balanced


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

fmap SubTransactionSignCmd $
SubTransactionSignCmdArgs
<$> pUnsignedSubTxFileIn
<*> many pWitnessSigningData

@palas palas 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.

I like the design, it is very simple. I include a couple of issues I saw. I probably should look more in depth at the code later. But it looks good in general

…ation

Add era-aware and explicit-language parsers for all six script purposes, removing obsolete wrappers and version helpers. Top-level builders select languages using their actual era; Dijkstra sub-transactions use V4-only parsers directly.

Reject pre-V4 executed sub-transaction witnesses. Cover V4 reference scripts, older top-level languages, native and stored scripts, and era restrictions.
Refresh the top-level transaction help goldens and changelog to reflect the era-aware parser changes.
…ards

Add required top-level guards to sub-transaction build-raw
@Jimbo4350
Jimbo4350 force-pushed the jordan/basic-sub-tx-integration branch from 55cff1e to 7467cef Compare October 14, 2026 15:27
@Jimbo4350
Jimbo4350 enabled auto-merge October 14, 2026 15:39
Jimbo4350 added a commit to IntersectMBO/cardano-node that referenced this pull request Oct 14, 2026
Add `hprop_nested_transaction_swap` ("Nested transaction swap"). It mints
100 TokenA to Alice in Conway and funds Bob, hard forks the cluster into
Dijkstra through governance (shared with the "Hard fork to Dijkstra"
test), then settles a multi-asset swap with a nested transaction built
with `cardano-cli dijkstra transaction sub-transaction`:

  * Alice's sub-transaction spends her 100 TokenA and pays herself 53 ADA
    (50 ADA price + the 3 ADA that travelled with the tokens);
  * Bob's sub-transaction spends 60 ADA and pays himself the 100 TokenA
    plus 7 ADA change, i.e. exactly 50 ADA;
  * the batcher's top-level transaction embeds both signed
    sub-transactions and pays the fee.

Each sub-transaction is guarded by and signed with its owner's key only.
The proof is read back from `query utxo`: Bob holds the 100 TokenA, Alice
gained exactly 50 ADA, Bob lost exactly 50 ADA, the batcher paid the fee.

The test needs a cardano-cli with the sub-transaction commands
(IntersectMBO/cardano-cli#1453), pointed at via CARDANO_CLI, and
cardano-ledger-dijkstra >= 0.4: before IntersectMBO/cardano-ledger#6129,
UTxO-HD key fetching through `allInputsTxBodyF` did not load
sub-transaction inputs and the ledger rejected the nested transaction
with SubBadInputsUTxO.
@Jimbo4350
Jimbo4350 added this pull request to the merge queue Oct 14, 2026
Merged via the queue into master with commit aa9915b Oct 14, 2026
25 checks passed
@Jimbo4350
Jimbo4350 deleted the jordan/basic-sub-tx-integration branch October 14, 2026 19:01
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.

5 participants