Repository navigation
Index Dijkstra sub-transactions through Ogmios - #28
carbolymer wants to merge 5 commits into
Conversation
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.
Jimbo4350
left a comment
There was a problem hiding this comment.
Approving with one issue noted inline about collecting reference scripts from discarded sub-transactions.
| 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) |
There was a problem hiding this comment.
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.
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
guardpurpose now decode. Before, any Dijkstra block with one failed to decode.cborfield when Ogmios includes it (--include-script-cboror--include-cbor), so Kupo stores their on-chain bytes in every era. Without it, Kupo rebuilds them from the JSON as before.guardclause is decoded from theoriginfield that Add origin to the Dijkstra native script guard clause ogmios#45 adds. With neithercbornororigin, Kupo stops with an error that says to upgrade Ogmios or run it with--include-script-cbor.Test vectors
The
test/vectors/ogmiossubmodule now points at IntersectMBO/ogmios instead of CardanoSolutions/ogmios, pinned to the head of IntersectMBO/ogmios#45. A TODO in.gitmodulestracks moving it to the merge commit on master once that PR merges. Existing clones needgit submodule sync --recursiveafter pulling, because the URL changed.Commits
PartialBlock, and the refusal for transactions that carry only their id.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
IsBlockmethod 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 scriptoriginand fromcbor, and both refusals.Also tested end to end on a Dijkstra devnet (
cardano-testnetfrom 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?unspentand/metadatafor a transaction with a sub-transaction. They also returned identical/scriptsbytes for two native reference scripts, one with a key guard and one with a script guard, which the Kupo following Ogmios rebuilt from theoriginfield alone. Neither the Ogmios nor the Kupo logs had errors.Depends on: