Skip to content

Index Dijkstra sub-transactions through Ogmios - #28

Open
carbolymer wants to merge 5 commits into
masterfrom
mgalazyn/feature/ogmios-dijkstra-subtransactions
Open

carbolymer wants to merge 5 commits into
masterfrom
mgalazyn/feature/ogmios-dijkstra-subtransactions

Conversation

@carbolymer

@carbolymer carbolymer commented Nov 27, 2026 •

Copy link
Copy Markdown

Fixes #21.

Summary

Kupo stopped at the first Dijkstra block when it followed the chain through Ogmios. It now decodes Dijkstra transactions as Ogmios serialises them since IntersectMBO/ogmios#22, sub-transactions included, and indexes them the same way as the direct node connection from #19. A sub-transaction's outputs and spends are indexed under its own id, its position is its index in the parent's subTransactions, and matches carry the parent transaction id. When the parent fails phase-2 validation, its sub-transactions are discarded but their datums and scripts are still collected.

An Ogmios older than PR 22 sends each Dijkstra transaction with only its id. Kupo still refuses those, so it never indexes them as empty transactions, and the error now says to upgrade Ogmios.

Scripts and guards

  • Redeemers with the guard purpose now decode. Before, any Dijkstra block with one failed to decode.
  • Native scripts are read from their cbor field when Ogmios includes it (--include-script-cbor or --include-cbor), so Kupo stores their on-chain bytes in every era. Without it, Kupo rebuilds them from the JSON as before.
  • A native script guard clause is decoded from the origin field that Add origin to the Dijkstra native script guard clause ogmios#45 adds. With neither cbor nor origin, Kupo stops with an error that says to upgrade Ogmios or run it with --include-script-cbor.

Test vectors

The test/vectors/ogmios submodule now points at IntersectMBO/ogmios instead of CardanoSolutions/ogmios, pinned to the head of IntersectMBO/ogmios#45. A TODO in .gitmodules tracks moving it to the merge commit on master once that PR merges. Existing clones need git submodule sync --recursive after pulling, because the URL changed.

Commits

  1. Index Dijkstra sub-transactions through Ogmios: the decoders, PartialBlock, and the refusal for transactions that carry only their id.
  2. Decode the guard redeemer purpose from Ogmios.
  3. Read native scripts from their CBOR when Ogmios includes it.
  4. Decode native script guard clauses from Ogmios.
  5. Take the Ogmios test vectors from IntersectMBO/ogmios: the submodule move and the tests that read Ogmios' golden Dijkstra transaction, which only the new submodule has. The tests for commit 1 are here for that reason.

Testing

The unit suite passes locally (471 examples, 0 failures). The new tests decode Ogmios' golden Dijkstra transaction from its JSON and from its CBOR and check that every IsBlock method gives the same result, for a valid and for a phase-2 invalid parent. They also check sub-transaction positions and the parent id in matches, guard clauses with a key and a script origin and from cbor, and both refusals.

Also tested end to end on a Dijkstra devnet (cardano-testnet from cardano-node 11.2.0), with Ogmios built from IntersectMBO/ogmios#45 on its default flags, so without script CBOR. A Kupo following Ogmios and a Kupo following the node directly returned identical /matches, /matches?spent, /matches?unspent and /metadata for a transaction with a sub-transaction. They also returned identical /scripts bytes for two native reference scripts, one with a key guard and one with a script guard, which the Kupo following Ogmios rebuilt from the origin field alone. Neither the Ogmios nor the Kupo logs had errors.

Depends on:

Ogmios now serialises Dijkstra transactions in full, including their
sub-transactions, so Kupo no longer needs to stop at the first Dijkstra
block that holds transactions. It reads each sub-transaction as a
transaction of its own and files it under the top-level transaction, as
the node-to-client path already does.

Kupo still stops at a Dijkstra transaction without 'inputs', which is
what an Ogmios from before full Dijkstra support sends. The flag that
records this is renamed from 'isDijkstraBlock' to
'hasTransactionStubs', because a Dijkstra block is no longer a reason
to refuse by itself.
Dijkstra transactions can carry redeemers for guards, and Ogmios names
their purpose 'guard'. Without a case for it, Kupo failed on "unknown
script purpose: guard" for any such transaction.
Ogmios adds the CBOR of a native script only when it runs with
--include-script-cbor. Decode it when it is there, so that Kupo stores
the on-chain bytes instead of a re-encoding of the JSON, and fall back
to the JSON otherwise. Plutus scripts already come from their CBOR.

The CBOR also covers every clause the JSON cannot describe fully, such
as the guard clauses of Dijkstra native scripts.
A guard clause names a hash that is either a key or a script, and the
ledger hashes the two differently. Ogmios includes the 'origin' of the
hash in the JSON of the clause, so read it from there when the script
has no CBOR. When there is neither, fail with a message that says how
to fix it, instead of guessing the wrong script hash.
The sub-transaction support of the Ogmios path lives in
IntersectMBO/ogmios, not in the cardanosolutions fork. Point the
submodule there, at the head of the pull request that adds the guard
clause origin, so that the tests read its Dijkstra golden files.

New tests decode the golden Dijkstra transaction from its JSON and from
its CBOR and compare what Kupo reads from the two, which covers the
sub-transactions, their positions, and the discarded sub-transactions
of a phase-2 invalid transaction.
@carbolymer carbolymer self-assigned this Nov 27, 2026
@carbolymer
carbolymer marked this pull request as ready for review November 27, 2026 09:16
@carbolymer carbolymer changed the title Mgalazyn/feature/ogmios dijkstra subtransactions Index Dijkstra sub-transactions through Ogmios Nov 27, 2026

@Jimbo4350 Jimbo4350 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with one issue noted inline about collecting reference scripts from discarded sub-transactions.

Comment thread src/Kupo/Data/Ogmios.hs
outs <- o .:? "outputs" .!= ([] :: [Json.Value])
colReturn <- o .:? "collateralReturn" >>= traverse decodeOutput
pure $ withReferences (fromIntegral $ length outs) id (maybeToList colReturn)
pure (withReferences (fromIntegral $ length outs) id (maybeToList colReturn), [], subTransactions)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference scripts carried only in the outputs of discarded sub-transactions are missed here. When the parent fails phase-2 validation, matchBlock collects these sub-transactions through witnessedScripts. For PartialBlock, that returns only the transaction's scripts map, whereas Ogmios puts output reference scripts in outputs[].script. The direct-node implementation also collects scripts from those outputs.

If the block otherwise matches (for example, through its collateral return), /scripts/<hash> can therefore return nothing through Ogmios while returning the script through the node. Please merge output reference scripts into the collected scripts for sub-transactions and add a comparison test where the script appears only in a discarded sub-transaction's output. The current golden transaction has no output reference scripts, so it does not exercise this case.

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.

Index Dijkstra sub-transactions on the Ogmios path

2 participants