Skip to content

Commit

Permalink
Fix close used healthy tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ffakenz committed Oct 24, 2024
1 parent ffb252c commit 5873c91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 13 additions & 12 deletions hydra-tx/src/Hydra/Tx/Close.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,27 @@ closeTx scriptRegistry vk headId openVersion confirmedSnapshot startSlotNo (endS
ConfirmedSnapshot{signatures, snapshot = Snapshot{version, utxoToCommit, utxoToDecommit}}
| version == openVersion
, isJust utxoToCommit ->
Head.CloseUnusedInc{signature = toPlutusSignatures signatures, alreadyCommittedUTxOHash = toBuiltin . hashUTxO $ fromMaybe mempty utxoToCommit}
Head.CloseUnusedInc
{ signature = toPlutusSignatures signatures
, alreadyCommittedUTxOHash = toBuiltin . hashUTxO $ fromMaybe mempty utxoToCommit
}
| version == openVersion
, isJust utxoToDecommit ->
Head.CloseUnusedDec{signature = toPlutusSignatures signatures}
| otherwise ->
-- NOTE: This will only work for version == openVersion - 1
if isJust utxoToCommit
then
case (utxoToCommit, utxoToDecommit) of
(Just _, Nothing) ->
Head.CloseUsedInc
{ signature = toPlutusSignatures signatures
}
else
if isJust utxoToDecommit
then
Head.CloseUsedDec
{ signature = toPlutusSignatures signatures
, alreadyDecommittedUTxOHash = toBuiltin . hashUTxO $ fromMaybe mempty utxoToDecommit
}
else
error "closeTx: unexpected snapshot"
(Nothing, Just _) ->
Head.CloseUsedDec
{ signature = toPlutusSignatures signatures
, alreadyDecommittedUTxOHash = toBuiltin . hashUTxO $ fromMaybe mempty utxoToDecommit
}
(Nothing, Nothing) -> Head.CloseInitial
_ -> error "closeTx: unexpected snapshot"

headOutputAfter =
modifyTxOutDatum (const headDatumAfter) headOutputBefore
Expand Down
3 changes: 2 additions & 1 deletion hydra-tx/test/Hydra/Tx/Contract/Close/CloseUsed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Hydra.Tx.Contract.Close.Healthy (
healthyOpenHeadTxOut,
healthySignature,
healthySplitUTxOInHead,
healthySplitUTxOToDecommit,
somePartyCardanoVerificationKey,
)
import Hydra.Tx.Crypto (MultiSignature (..), toPlutusSignatures)
Expand Down Expand Up @@ -89,7 +90,7 @@ healthyOutdatedSnapshot =
, confirmed = []
, utxo = healthySplitUTxOInHead
, utxoToCommit = Nothing
, utxoToDecommit = Nothing -- NOTE: In the `CloseOutdated` case, we expect the utxoToDecommit to be Nothing
, utxoToDecommit = Just healthySplitUTxOToDecommit
}

healthyOutdatedOpenDatum :: Head.State
Expand Down

0 comments on commit 5873c91

Please sign in to comment.