diff --git a/hydra-node/src/Hydra/Chain.hs b/hydra-node/src/Hydra/Chain.hs index 5ef704f9c46..6d931972f8b 100644 --- a/hydra-node/src/Hydra/Chain.hs +++ b/hydra-node/src/Hydra/Chain.hs @@ -244,8 +244,9 @@ data Chain tx m = Chain UTxOType tx -> tx -> m (Either (PostTxError tx) tx) - -- ^ Create a commit transaction using user provided utxos (zero or many) and - -- a _blueprint_ transaction. Errors are handled at the call site. + -- ^ Create a commit transaction using either user provided utxos (zero or many) or + -- a _blueprint_ transaction together with a 'UTxO' which resolves it. + -- Errors are handled at the call site. , submitTx :: MonadThrow m => tx -> m () -- ^ Submit a cardano transaction. -- diff --git a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs index f0551d89ac9..b53908dabc6 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs @@ -157,7 +157,7 @@ mkChain tracer queryTimeHandle wallet@TinyWallet{getUTxO} ctx LocalChainState{ge atomically (prepareTxToPost timeHandle wallet ctx spendableUTxO tx) >>= finalizeTx wallet ctx spendableUTxO mempty submitTx vtx - , -- Handle that creates a draft commit tx using the user utxo. + , -- Handle that creates a draft commit tx using the user utxo and a _blueprint_ transaction. -- Possible errors are handled at the api server level. draftCommitTx = \headId utxoToCommit blueprintTx -> do ChainStateAt{spendableUTxO} <- atomically getLatest @@ -167,7 +167,7 @@ mkChain tracer queryTimeHandle wallet@TinyWallet{getUTxO} ctx LocalChainState{ge let matchedWalletUtxo = filter (`elem` walletTxIns) userTxIns -- prevent trying to spend internal wallet's utxo if null matchedWalletUtxo - then do + then traverse (finalizeTx wallet ctx spendableUTxO utxoToCommit) $ commit' ctx headId spendableUTxO utxoToCommit blueprintTx else pure $ Left SpendingNodeUtxoForbidden @@ -177,7 +177,6 @@ mkChain tracer queryTimeHandle wallet@TinyWallet{getUTxO} ctx LocalChainState{ge } -- | Balance and sign the given partial transaction. --- TODO: remove tracing finalizeTx :: MonadThrow m => TinyWallet m -> diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index 0bf5db86bf0..88ca04975df 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -344,7 +344,7 @@ commit ctx headId spendableUTxO utxoToCommit = in commit' ctx headId spendableUTxO utxoToCommit blueprintTx -- | Construct a commit transaction based on known, spendable UTxO and some --- arbitrary UTxOs to commit. This does look for "our initial output" to spend +-- user UTxO inputs to commit. This does look for "our initial output" to spend -- and check the given 'UTxO' to be compatible. Hence, this function does fail -- if already committed or if the head is not initializing. -- @@ -354,16 +354,16 @@ commit' :: HeadId -> -- | Spendable 'UTxO' UTxO -> - -- | 'UTxO' to commit + -- | 'UTxO' inputs to commit. UTxO -> Tx -> Either (PostTxError Tx) Tx -commit' ctx headId spendableUTxO utxoToCommit blueprintTx = do +commit' ctx headId spendableUTxO utxo blueprintTx = do pid <- headIdToPolicyId headId ?> InvalidHeadId{headId} (i, o) <- ownInitial pid ?> CannotFindOwnInitial{knownUTxO = spendableUTxO} - rejectByronAddress utxoToCommit - rejectMoreThanMainnetLimit networkId utxoToCommit - pure $ commitTx networkId scriptRegistry headId ownParty utxoToCommit blueprintTx (i, o, vkh) + rejectByronAddress utxo + rejectMoreThanMainnetLimit networkId utxo + pure $ commitTx networkId scriptRegistry headId ownParty utxo blueprintTx (i, o, vkh) where ChainContext{networkId, ownParty, scriptRegistry, ownVerificationKey} = ctx diff --git a/hydra-node/src/Hydra/Chain/Direct/Tx.hs b/hydra-node/src/Hydra/Chain/Direct/Tx.hs index 4cc623d0f3f..b2bc2081481 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Tx.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Tx.hs @@ -242,7 +242,7 @@ commitTx :: ScriptRegistry -> HeadId -> Party -> - -- | The UTxO to commit to the Head. + -- | The UTxO inputs to commit to the Head. UTxO -> -- | _Blueprint_ transaction. Tx -> @@ -250,7 +250,7 @@ commitTx :: -- locked by initial script (TxIn, TxOut CtxUTxO, Hash PaymentKey) -> Tx -commitTx networkId scriptRegistry headId party utxoToCommit blueprintTx (initialInput, out, vkh) = +commitTx networkId scriptRegistry headId party utxo blueprintTx (initialInput, out, vkh) = let ledgerBlueprintTx = toLedgerTx blueprintTx @@ -263,7 +263,7 @@ commitTx networkId scriptRegistry headId party utxoToCommit blueprintTx (initial & auxDataTxL .~ addMetadata txAuxMetadata existingWits = ledgerBlueprintTx ^. witsTxL currentInputs = ledgerBlueprintTx ^. bodyTxL . inputsTxBodyL - commitInputs = Set.map toLedgerTxIn (UTxO.inputSet utxoToCommit) + commitInputs = Set.map toLedgerTxIn (UTxO.inputSet utxo) blueprintRedeemers = unRedeemers $ toLedgerTx blueprintTx ^. witsTxL . rdmrsTxWitsL wits = witsTxL @@ -285,7 +285,7 @@ commitTx networkId scriptRegistry headId party utxoToCommit blueprintTx (initial (Map.union languageMap languageMap') -- Re-Associate the redeemer indices present in some tx with the same inputs but different - -- indices in the current tx. + -- indices in the current (commit) tx. -- -- We need this in order to be able to find the the _old_ tx redeemer and re-add -- it to the tx witnesses using the appropriate index of the _new_ tx input @@ -325,7 +325,7 @@ commitTx networkId scriptRegistry headId party utxoToCommit blueprintTx (initial Initial.ViaCommit (toPlutusTxOutRef <$> committedTxIns) committedTxIns = - fst <$> UTxO.pairs utxoToCommit + fst <$> UTxO.pairs utxo commitOutput = TxOut commitAddress commitValue commitDatum ReferenceScriptNone @@ -337,10 +337,10 @@ commitTx networkId scriptRegistry headId party utxoToCommit blueprintTx (initial mkScriptAddress @PlutusScriptV2 networkId commitScript commitValue = - txOutValue out <> foldMap txOutValue utxoToCommit + txOutValue out <> foldMap txOutValue utxo commitDatum = - mkTxOutDatumInline $ mkCommitDatum party utxoToCommit (headIdToCurrencySymbol headId) + mkTxOutDatumInline $ mkCommitDatum party utxo (headIdToCurrencySymbol headId) TxMetadata metadataMap = mkHydraHeadV1TxName "CommitTx"