Skip to content

Commit

Permalink
Fix close transaction to use last open state version in output
Browse files Browse the repository at this point in the history
The healthy case of close "outdated" mutations was also not correctly
setting up the versions.
  • Loading branch information
ch1bo committed Jul 11, 2024
1 parent 1e39a6a commit 8053d19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ canCloseWithPendingDecommit tracer workDir node hydraScriptsTxId =

-- Send signed decommit tx
submitSignedDecommitTx n1 headId walletSk body callDecommitHttpEndpoint
threadDelay 2 -- FIXME: this test is actually the same as above, especially as we need to wait here to not fail submission
-- Close and Fanout put whatever is left in the Head back to L1
closeAndFanout headId n1 (headAmount + decommitAmount) walletVk
where
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ closeTx scriptRegistry vk closing startSlotNo (endSlotNo, utcTime) openThreadOut
, contestationPeriod = openContestationPeriod
, headId = headIdToCurrencySymbol headId
, contesters = []
, version = toInteger version
, version = toInteger offChainVersion -- TODO: rename or explain. This is rather "last known open state version"
}

-- TODO: use CloseWithInitialSnapshot etc directly to avoid this tuple
Expand Down
19 changes: 12 additions & 7 deletions hydra-node/test/Hydra/Chain/Direct/Contract/Close/CloseOutdated.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Hydra.Chain.Direct.Contract.Close.Healthy (
healthyContestationPeriod,
healthyContestationPeriodSeconds,
healthyOnChainParties,
healthyOpenDatum,
healthyOpenHeadTxIn,
healthyOpenHeadTxOut,
healthySignature,
Expand All @@ -39,6 +38,7 @@ import Hydra.Chain.Direct.Contract.Mutation (
replaceParties,
replacePolicyIdWith,
replaceSnapshotNumber,
replaceSnapshotVersionInClosed,
replaceUtxoHash,
)
import Hydra.Chain.Direct.Fixture qualified as Fixture
Expand All @@ -53,10 +53,10 @@ import Hydra.Chain.Direct.Tx (
import Hydra.Contract.Error (toErrorCode)
import Hydra.Contract.HeadError (HeadError (..))
import Hydra.Contract.HeadState qualified as Head
import Hydra.Contract.HeadState qualified as HeadState
import Hydra.Contract.HeadTokens (headPolicyId)
import Hydra.Contract.Util (UtilError (MintingOrBurningIsForbidden))
import Hydra.Crypto (MultiSignature (..), toPlutusSignatures)
import Hydra.Ledger (hashUTxO)
import Hydra.Ledger.Cardano (genAddressInEra, genValue, genVerificationKey)
import Hydra.Plutus.Extras (posixFromUTCTime)
import Hydra.Plutus.Orphans ()
Expand Down Expand Up @@ -88,7 +88,15 @@ healthyOutdatedSnapshot =
}

healthyOutdatedOpenDatum :: Head.State
healthyOutdatedOpenDatum = healthyOpenDatum healthyOutdatedSnapshot
healthyOutdatedOpenDatum =
Head.Open
{ parties = healthyOnChainParties
, utxoHash = toBuiltin $ hashUTxO @Tx healthySplitUTxOInHead
, snapshotNumber = toInteger healthyOutdatedSnapshotNumber
, contestationPeriod = healthyContestationPeriod
, headId = toPlutusCurrencySymbol Fixture.testPolicyId
, version = toInteger $ healthyOutdatedSnapshotVersion + 1
}

healthyOutdatedConfirmedClosingSnapshot :: ClosingSnapshot
healthyOutdatedConfirmedClosingSnapshot = healthyConfirmedClosingSnapshot healthyOutdatedSnapshot
Expand All @@ -114,10 +122,7 @@ healthyCloseOutdatedTx =
<> registryUTxO scriptRegistry

datum :: TxOutDatum CtxUTxO
datum = toUTxOContext (mkTxOutDatumInline openDatum)

openDatum :: HeadState.State
openDatum = healthyOpenDatum healthyOutdatedSnapshot
datum = toUTxOContext (mkTxOutDatumInline healthyOutdatedOpenDatum)

openThreadOutput :: OpenThreadOutput
openThreadOutput =
Expand Down

0 comments on commit 8053d19

Please sign in to comment.