Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
93 stars 50 forks source link

Support creation and submitting multiple interdependent transactions at the same time #310

Closed L-as closed 1 year ago

L-as commented 2 years ago

It should be possible to create a DAG of transactions locally, and submit them in one go, without doing any roundtrips to any server between the transactions. The lack of support of this can potentially decrease throughput by several orders of magnitude.

In the naive case where you wait for the first transaction to be accepted into the blockchain, you have to wait a very long time until you can submit the transactions that depend on that transaction. You can send the transactions in order without waiting, and in fact according to Duncan Coutts, the protocol is designed such that upstream nodes do in fact preserve the ordering of the transactions.

This is important, because the ledger is essentially a set of TxOutRefs, where each transaction is applied incrementally, meaning that such a DAG of dependent transactions can all be accepted into the same block.

(snippet from e-mail between George Flerovsky and Duncan Coutts)

As a follow-up question: if a node's validation context includes the pending transactions that it has validated previously, does that mean that it can validate a transaction that attempts to consume an output from one of those pending transactions?

Yes indeed! Because as I note above, it's a sequence of transactions, and the validation context is a ledger state, then yes there can be dependent transactions. This is perfectly legitimate, and the transaction propagation mechanism is designed to avoid reordering them. So it's actually a use case that's supported by the design.

(edited)

klntsky commented 2 years ago

It depends on behavior of Ogmios.

From this I can conclude that sending TXs one-by-one is technically supported by Ogmios. However, we also rely on utxo call to get UTXOs during tx construction, and it's not clear whether mempool TXs are included in its output.

We also maintain a list of spent outputs to prevent double-spending attempts.

In the worst case (if Ogmios utxo call is blind w.r.t. local mempool) I think we could use Ogmios Local Tx Monitor and consider utxos received from that.

klntsky commented 2 years ago

I think I can check how utxo call works soon.

L-as commented 2 years ago

I changed the issue given that you've confirmed that at the very least you have to do a roundtrip on the network to some server to do this, which wouldn't be great either.

klntsky commented 2 years ago

It's not strictly required to call utxo, one can use CTL as a thin wrapper around CSL. But if balancing is used, utxo is called.

L-as commented 2 years ago

@klntsky Can you give an example of how to do this then?

klntsky commented 2 years ago

Sorry for slow reply (I was ill). There's no example, but the idea is that you can construct a transaction by hand without using Contract API, the same way you can do it with cardano-serialization-library in pure JS.

firefrorefiddle commented 2 years ago

With https://github.com/Plutonomicon/cardano-transaction-lib/pulls you can create multiple transactions at the same time. Not really in a DAG, but in a flat list, but at least without double spending.

However, it's not yet possible to submit them in one go.

klntsky commented 2 years ago

@firefrorefiddle I think your link is incorrect

firefrorefiddle commented 2 years ago

Sorry, https://github.com/Plutonomicon/cardano-transaction-lib/pull/456

L-as commented 2 years ago

With https://github.com/Plutonomicon/cardano-transaction-lib/pulls you can create multiple transactions at the same time. Not really in a DAG, but in a flat list, but at least without double spending.

However, it's not yet possible to submit them in one go.

Transactions that depend on each other?

the-headless-ghost commented 1 year ago

This is now possible with the mustUseAdditionalUtxos balance constraint.