Repository navigation
Index Dijkstra sub-transactions - #19
Conversation
0588cfa to
766bd93
Compare
2892161 to
bd9a974
Compare
766bd93 to
6da14c2
Compare
| let pt = getPoint blk in foldBlock (fnBatch pt) mempty blk | ||
| where | ||
| -- Sub-transactions share the transaction index of their top-level transaction. | ||
| -- Of the discarded ones, only the datums and scripts are collected. |
There was a problem hiding this comment.
Please also explain why we collect these datums and scripts. A phase-2-invalid transaction is still included on-chain, so it can reveal the datum or script behind a hash even though its normal inputs are not spent and its normal outputs are not created. Those bytes remain useful for lookup by hash. The same rationale applies to discarded sub-transactions; documenting it here would make this behavior easier to understand.
There was a problem hiding this comment.
Done: the comment now says that a discarded (phase-2 invalid) transaction or sub-transaction still puts its datums and scripts on chain, so only those are collected, for lookup by hash.
| Ledger.Phase2Invalid -> | ||
| [] | ||
| SubTransactionDijkstra{} -> | ||
| [] |
There was a problem hiding this comment.
Please add a comment explaining why this returns an empty list: CIP-118 forbids sub-transactions from containing further sub-transactions, so this case has no children to return. For example: -- Sub-transactions cannot themselves contain sub-transactions.
| [spent0, spent1, subOutput0, subOutput1, output] <- generate (vectorOf 5 genOutput) | ||
| let funding = mkTransaction [fundingInput] [spent0, spent1] | ||
| let sub0 = mkTransaction [mkOutputReference (topLevelId funding) 0] [subOutput0] | ||
| let sub1 = mkTransaction [mkOutputReference (topLevelId funding) 1, subInput] [subOutput1] |
There was a problem hiding this comment.
Please extend the regression coverage with two cases:
- One sub-transaction creates an output that a later sub-transaction or the parent spends. Both sub-transactions here spend outputs from an earlier block, so this does not yet exercise spending within a batch.
- An output is spent by a sub-transaction, that block is rolled back, and an ordinary transaction then spends the output. Check that
/matchesreports the replacement spender andspent_at.top_level_transaction_idis null.
I did not find a failure in these paths, but these tests would give useful coverage of the new behavior.
There was a problem hiding this comment.
Added both:
spends the outputs that sub-transactions create within the same block: one sub-transaction creates an output, a later one spends it and creates another, and the parent spends that. All three outputs are indexed, and each spend reports its spender and top-level transaction id.reports an ordinary spender after a spending sub-transaction is rolled back: after the rollback,/matchesreports the ordinary transaction as spender, withspent_at.top_level_transaction_idnull.
Neither found a failure.
3058ac6 to
6b5b1d3
Compare
ecd67c8 to
a158f69
Compare
6b5b1d3 to
b4445d5
Compare
The inputs table gains three nullable columns. Top-level transactions leave all three empty. IsBlock gains subTransactions, which lists the sub-transactions of a top-level transaction, and discardedSubTransactions, which lists those that the ledger discards with a phase-2 invalid one, both none by default. matchBlock matches the former with the transaction index of their top-level transaction, records the top-level transaction id and the sub-transaction position on their outputs, and the top-level transaction id on their spends. Of the latter, it collects only the datums and scripts, as it does for a phase-2 invalid top-level transaction. The database layer writes and reads the three sub-transaction columns. No block lists sub-transactions yet, so the index does not change.
Outputs of sub-transactions come before those of the top-level transaction, by sub-transaction index, in both directions.
Transaction gains SubTransactionDijkstra. The Block instance of IsBlock lists the sub-transactions of a phase-2 valid Dijkstra transaction in ledger order, and reads their inputs, outputs, datums, scripts, metadata and spend redeemers from their own bodies and witness sets. A phase-2 invalid transaction lists none, because the ledger then applies none of them; it lists them as discarded instead, so that their datums and scripts are still collected. Kupo still refuses blocks that carry sub-transactions, so the index does not change.
Blocks from cardano-node that carry sub-transactions no longer stop Kupo: it indexes the outputs and spends of each sub-transaction. The refusal stays for Dijkstra blocks from Ogmios, whose transactions Kupo cannot inspect. Without the refusal, the library no longer uses cardano-data.
Each match gains sub_transaction_index and top_level_transaction_id, null for outputs of top-level transactions, and spent_at gains top_level_transaction_id, null unless a sub-transaction spent the output.
GET /matches accepts top_level_transaction_id, which returns the outputs created by the sub-transactions of that transaction and not its own. The filter excludes policy_id, transaction_id and output_index. Tests also cover the transaction_id filter and the transaction id patterns with the id of a sub-transaction.
/metadata/{slot} lists the metadata of the sub-transactions of a Dijkstra
transaction before that of the transaction itself, and names the
transaction of each entry with transaction_id and top_level_transaction_id.
The transaction_id filter accepts the id of a sub-transaction.
The sub-transaction tests read Dijkstra transactions through a test-only block type. These tests build a real Dijkstra Block, with a header signed by keys derived from fixed seeds, and check its point, its fold over the top-level transactions, the sub-transactions it lists, that it passes checkSubTransactions, and what matchBlock reads from it.
The schema images were drawn by hand, no script produced them, and they no longer matched the schema. A Mermaid erDiagram in db/README.md replaces them; GitHub renders it in light and dark themes. It shows the tables after all migrations, their primary keys, the foreign key from policies to inputs, and the lookups that queries make by value. The complete definition also gains the inputsByDatumHash and policiesByPolicyId indexes that Kupo creates, and no longer declares payment_credential NOT NULL, which its migration never did.
a158f69 to
eb4be63
Compare
Part of #12.
Summary
Kupo refused Dijkstra blocks that contain sub-transactions (CIP-118). When it is connected directly to cardano-node, it now indexes the outputs and spends of each sub-transaction, and reports them through
/matchesand/metadata. The Ogmios path still refuses such blocks, see #21, which is blocked by IntersectMBO/ogmios#21.Stack
This PR is based on #23 (cardano-config layout of the node configuration), which is on #18 (CHaP bump), which is on master. The base branch is
mgalazyn/feature/cardano-config-envelope. The 10 commits on top of it are new in this PR.Changes
One bullet per commit, in order.
v2.12.0/003adds three nullable columns toinputs(sub_transaction_index,top_level_transaction_id,spent_by_top_level_transaction_id). It is automatic and instant, existing rows keep NULL, and no resync is needed.IsBlockgainssubTransactionsanddiscardedSubTransactions,matchBlockfills the columns, and the database layer writes and reads them. No block lists sub-transactions yet, so the index does not change.TransactiongainsSubTransactionDijkstra, and theBlockinstance lists the sub-transactions of a phase-2 valid transaction in ledger order, with their inputs, outputs, datums, scripts, metadata and spend redeemers. A phase-2 invalid parent lists none as applied, so its sub-transactions create and spend nothing and add no metadata, but it lists them as discarded, so their datums and scripts are still collected, as for an invalid top-level transaction. Kupo still refuses such blocks at this commit.cardano-data.sub_transaction_indexandtop_level_transaction_id, null for outputs of top-level transactions.spent_atgainstop_level_transaction_id, null unless a sub-transaction spent the output (spent_atitself is null for an unspent output).GET /matches?top_level_transaction_id=<T>returns only the outputs created by the sub-transactions of T, not T's own. Together withpolicy_id,asset_name,transaction_idoroutput_index, or when given twice, it is rejected with 400invalidMatchFilter. Tests also cover thetransaction_idfilter and the transaction id patterns with the id of a sub-transaction.transaction_idandtop_level_transaction_id(null for top-level transactions). The metadata of the sub-transactions of a transaction comes before that of the transaction itself. Thetransaction_idfilter accepts the id of a sub-transaction.db/README.md.Block, with a header signed by keys derived from fixed seeds, and check its point, its fold over the top-level transactions, the sub-transactions it lists, that it passescheckSubTransactions, and whatmatchBlockreads from it.erDiagramindb/README.mdreplaces the two schema PNGs, which were drawn by hand and no longer matched the schema. It also adds theinputsByDatumHashandpoliciesByPolicyIdindexes and drops aNOT NULLonpayment_credentialthat the migration never declared.The API documentation (
docs/api/nightly.yaml) and the changelog describe the new fields and the filter.Remaining work
/matchesJSON fields and atop_level_transaction_idfilter./metadataentries withtransaction_idandtop_level_transaction_id.The unsupported Postgres backend is out of scope.
Verification
At the tip, the builds of
kupoandkupo-testspass with no GHC warnings, and the unit tests run 448 examples with 0 failures. After the rebase onto master, only the tip was rebuilt and tested.I also ran Kupo at the tip of this branch by hand against a Dijkstra devnet made with cardano-testnet from the cardano-node 11.2.0 release (cardano-cli 11.6.0.0), raised to protocol version 12 by governance votes. I submitted a transaction with one sub-transaction, built with the
cardano-cli dijkstracommands, with metadata on both the sub-transaction and its parent, and it landed in a block. Kupo followed the chain past that block to the tip with no errors./matchesgave the sub-transaction's output asub_transaction_indexof 0 and the parent id intop_level_transaction_id, and both fields are null for the parent's output. Thetop_level_transaction_idfilter returned only the sub-transaction's output.spent_at.top_level_transaction_idis the parent id for the output the sub-transaction spent and null for the one the parent spent. Withorder=oldest_firstthe sub-transaction's output comes before the parent's, and/metadatafor that slot lists the sub-transaction's entry first, with the parent id, then the parent's, with null. The node configuration was flattened with jq first, as described in #22. A phase-2-invalid parent with sub-transactions was not covered on the devnet.