From 909aa03b2d125fff5a28f85d804e63b768db7fe6 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Mon, 14 Oct 2024 13:27:23 +0200 Subject: [PATCH 1/7] Draft initial increment mutation --- .../test/Hydra/Tx/Contract/ContractSpec.hs | 4 ++- hydra-tx/test/Hydra/Tx/Contract/Deposit.hs | 7 ++-- hydra-tx/test/Hydra/Tx/Contract/Increment.hs | 34 +++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs b/hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs index 0ee2fc9ce46..6195bd0b168 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/ContractSpec.hs @@ -43,7 +43,7 @@ import Hydra.Tx.Contract.Contest.ContestCurrent (genContestMutation, healthyCont import Hydra.Tx.Contract.Decrement (genDecrementMutation, healthyDecrementTx) import Hydra.Tx.Contract.Deposit (healthyDepositTx) import Hydra.Tx.Contract.FanOut (genFanoutMutation, healthyFanoutTx) -import Hydra.Tx.Contract.Increment (healthyIncrementTx) +import Hydra.Tx.Contract.Increment (genIncrementMutation, healthyIncrementTx) import Hydra.Tx.Contract.Init (genInitMutation, healthyInitTx) import Hydra.Tx.Contract.Recover (genRecoverMutation, healthyRecoverTx) import Hydra.Tx.Crypto (aggregate, sign, toPlutusSignatures) @@ -112,6 +112,8 @@ spec = parallel $ do describe "Increment" $ do prop "is healthy" $ propTransactionEvaluates healthyIncrementTx + prop "does not survive random adversarial mutations" $ + propMutation healthyIncrementTx genIncrementMutation describe "Decrement" $ do prop "is healthy" $ propTransactionEvaluates healthyDecrementTx diff --git a/hydra-tx/test/Hydra/Tx/Contract/Deposit.hs b/hydra-tx/test/Hydra/Tx/Contract/Deposit.hs index 72068c1ee10..bc6bde8b003 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Deposit.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Deposit.hs @@ -3,6 +3,8 @@ module Hydra.Tx.Contract.Deposit where import Hydra.Cardano.Api import Hydra.Prelude +import Data.Time (UTCTime (..), secondsToDiffTime) +import Data.Time.Calendar (fromGregorian) import Hydra.Tx (mkHeadId) import Hydra.Tx.BlueprintTx (CommitBlueprintTx (..)) import Hydra.Tx.Deposit (depositTx) @@ -18,9 +20,10 @@ healthyDepositTx = testNetworkId (mkHeadId testPolicyId) CommitBlueprintTx{blueprintTx = txSpendingUTxO healthyDepositUTxO, lookupUTxO = healthyDepositUTxO} - deadline + depositDeadline - deadline = arbitrary `generateWith` 42 +depositDeadline :: UTCTime +depositDeadline = UTCTime (fromGregorian 2024 15 0) (secondsToDiffTime 0) healthyDepositUTxO :: UTxO healthyDepositUTxO = genUTxOAdaOnlyOfSize 5 `generateWith` 42 diff --git a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs index b50f188d1a6..ecf72966c95 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs @@ -5,15 +5,23 @@ module Hydra.Tx.Contract.Increment where import Hydra.Cardano.Api import Hydra.Prelude hiding (label) import Test.Hydra.Tx.Mutation ( + Mutation (ChangeInput), + SomeMutation (..), addParticipationTokens, + modifyInlineDatum, ) import Cardano.Api.UTxO qualified as UTxO +import Data.List qualified as List +import Hydra.Contract.Deposit (DepositDatum (..), DepositRedeemer (Claim)) +import Hydra.Contract.DepositError (DepositError (..)) +import Hydra.Contract.Error (toErrorCode) import Hydra.Contract.HeadState qualified as Head import Hydra.Data.Party qualified as OnChain +import Hydra.Ledger.Cardano.Time (slotNoFromUTCTime) import Hydra.Plutus.Orphans () import Hydra.Tx.ContestationPeriod (ContestationPeriod, toChain) -import Hydra.Tx.Contract.Deposit (healthyDepositTx) +import Hydra.Tx.Contract.Deposit (depositDeadline, healthyDepositTx) import Hydra.Tx.Crypto (HydraKey, MultiSignature (..), aggregate, sign) import Hydra.Tx.HeadId (mkHeadId) import Hydra.Tx.HeadParameters (HeadParameters (..)) @@ -26,8 +34,9 @@ import Hydra.Tx.Party (Party, deriveParty, partyToChain) import Hydra.Tx.ScriptRegistry (registryUTxO) import Hydra.Tx.Snapshot (Snapshot (..), SnapshotNumber, SnapshotVersion) import Hydra.Tx.Utils (adaOnly, splitUTxO) +import PlutusLedgerApi.V2 qualified as Plutus import PlutusTx.Builtins (toBuiltin) -import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, testNetworkId, testPolicyId) +import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, slotLength, systemStart, testNetworkId, testPolicyId) import Test.Hydra.Tx.Gen (genForParty, genScriptRegistry, genUTxOSized, genVerificationKey) import Test.QuickCheck (elements) import Test.QuickCheck.Instances () @@ -38,8 +47,8 @@ healthyIncrementTx = where lookupUTxO = UTxO.singleton (headInput, headOutput) - <> registryUTxO scriptRegistry <> depositUTxO + <> registryUTxO scriptRegistry tx = incrementTx @@ -50,6 +59,7 @@ healthyIncrementTx = (headInput, headOutput) healthySnapshot depositUTxO + (slotNoFromUTCTime systemStart slotLength depositDeadline) depositUTxO = utxoFromTx $ fst healthyDepositTx @@ -133,3 +143,21 @@ healthyDatum = , headId = toPlutusCurrencySymbol testPolicyId , version = toInteger healthySnapshotVersion } + +data IncrementMutation + = -- | Move the deadline from the deposit datum back in time + -- so that the increment upper bound is after the deadline + MutateDepositDeadline + deriving stock (Generic, Show, Enum, Bounded) + +genIncrementMutation :: (Tx, UTxO) -> Gen SomeMutation +genIncrementMutation (tx, utxo) = + SomeMutation (pure $ toErrorCode DepositDeadlineSurpassed) MutateDepositDeadline <$> do + let (depositIn, depositOut@(TxOut addr val _ rscript)) = UTxO.pairs (resolveInputsUTxO utxo tx) List.!! 1 + let datum = + txOutDatum $ + flip modifyInlineDatum (toTxContext depositOut) $ \case + DepositDatum (headCS', depositDatumDeadline, commits) -> + DepositDatum (headCS', Plutus.POSIXTime $ Plutus.getPOSIXTime depositDatumDeadline - 1, commits) + let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript + pure $ ChangeInput depositIn newOutput (Just $ toScriptData Claim) From 60072a29ecc67d1925e9324e87658d1e55e62ba4 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Mon, 14 Oct 2024 16:48:13 +0200 Subject: [PATCH 2/7] Set upper validity slot for increment tx --- hydra-node/src/Hydra/Chain/Direct/Handlers.hs | 7 +++++-- hydra-node/src/Hydra/Chain/Direct/State.hs | 13 ++++++++----- hydra-tx/src/Hydra/Tx/Increment.hs | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs index fa3d7490279..0665818c6fa 100644 --- a/hydra-node/src/Hydra/Chain/Direct/Handlers.hs +++ b/hydra-node/src/Hydra/Chain/Direct/Handlers.hs @@ -390,8 +390,11 @@ prepareTxToPost timeHandle wallet ctx spendableUTxO tx = case collect ctx headId headParameters utxo spendableUTxO of Left _ -> throwIO (FailedToConstructCollectTx @Tx) Right collectTx -> pure collectTx - IncrementTx{headId, headParameters, incrementingSnapshot, depositTxId} -> - case increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTxId of + IncrementTx{headId, headParameters, incrementingSnapshot, depositTxId} -> do + (_, currentTime) <- throwLeft currentPointInTime + let HeadParameters{contestationPeriod} = headParameters + (upperBound, _) <- calculateTxUpperBoundFromContestationPeriod currentTime contestationPeriod + case increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTxId upperBound of Left _ -> throwIO (FailedToConstructIncrementTx @Tx) Right incrementTx' -> pure incrementTx' RecoverTx{headId, recoverTxId, deadline} -> do diff --git a/hydra-node/src/Hydra/Chain/Direct/State.hs b/hydra-node/src/Hydra/Chain/Direct/State.hs index f7c7aeabbe1..4b8bf147cb7 100644 --- a/hydra-node/src/Hydra/Chain/Direct/State.hs +++ b/hydra-node/src/Hydra/Chain/Direct/State.hs @@ -498,8 +498,9 @@ increment :: ConfirmedSnapshot Tx -> -- | Deposited TxId TxId -> + SlotNo -> Either IncrementTxError Tx -increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTxId = do +increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTxId upperValiditySlot = do pid <- headIdToPolicyId headId ?> InvalidHeadIdInIncrement{headId} let utxoOfThisHead' = utxoOfThisHead pid spendableUTxO headUTxO <- UTxO.find (isScriptTxOut headScript) utxoOfThisHead' ?> CannotFindHeadOutputInIncrement @@ -516,7 +517,7 @@ increment ctx spendableUTxO headId headParameters incrementingSnapshot depositTx Just deposit | null deposit -> Left SnapshotIncrementUTxOIsNull - | otherwise -> Right $ incrementTx scriptRegistry ownVerificationKey headId headParameters headUTxO sn (UTxO.singleton (depositedIn, depositedOut)) + | otherwise -> Right $ incrementTx scriptRegistry ownVerificationKey headId headParameters headUTxO sn (UTxO.singleton (depositedIn, depositedOut)) upperValiditySlot where headScript = fromPlutusScript @PlutusScriptV2 Head.validatorScript depositScript = fromPlutusScript @PlutusScriptV2 Deposit.validatorScript @@ -1206,12 +1207,13 @@ genIncrementTx numParties = do let version = 1 snapshot <- genConfirmedSnapshot headId 2 version openUTxO (Just deposited) Nothing (ctxHydraSigningKeys ctx) let depositUTxO = utxoFromTx txDeposit + slotNo <- arbitrary pure ( cctx , maybe mempty toList (utxoToCommit $ getSnapshot snapshot) , st , depositUTxO - , unsafeIncrement cctx (openUTxO <> depositUTxO) headId (ctxHeadParameters ctx) snapshot depositTxId + , unsafeIncrement cctx (openUTxO <> depositUTxO) headId (ctxHeadParameters ctx) snapshot depositTxId slotNo ) genDecrementTx :: Int -> Gen (ChainContext, [TxOut CtxUTxO], OpenState, UTxO, Tx) @@ -1363,9 +1365,10 @@ unsafeIncrement :: HeadParameters -> ConfirmedSnapshot Tx -> TxId -> + SlotNo -> Tx -unsafeIncrement ctx spendableUTxO headId parameters incrementingSnapshot depositedTxId = - either (error . show) id $ increment ctx spendableUTxO headId parameters incrementingSnapshot depositedTxId +unsafeIncrement ctx spendableUTxO headId parameters incrementingSnapshot depositedTxId slotNo = + either (error . show) id $ increment ctx spendableUTxO headId parameters incrementingSnapshot depositedTxId slotNo unsafeDecrement :: HasCallStack => diff --git a/hydra-tx/src/Hydra/Tx/Increment.hs b/hydra-tx/src/Hydra/Tx/Increment.hs index 2f30b065226..6248f9b12b7 100644 --- a/hydra-tx/src/Hydra/Tx/Increment.hs +++ b/hydra-tx/src/Hydra/Tx/Increment.hs @@ -14,6 +14,7 @@ import Hydra.Ledger.Cardano.Builder ( addOutputs, addReferenceInputs, emptyTxBody, + setValidityUpperBound, unsafeBuildTransaction, ) import Hydra.Tx.ContestationPeriod (toChain) @@ -43,14 +44,16 @@ incrementTx :: Snapshot Tx -> -- | Deposit output UTxO to be spent in increment transaction UTxO -> + SlotNo -> Tx -incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot depositScriptUTxO = +incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snapshot depositScriptUTxO upperValiditySlot = unsafeBuildTransaction $ emptyTxBody & addInputs [(headInput, headWitness), (depositIn, depositWitness)] & addReferenceInputs [headScriptRef] & addOutputs [headOutput'] & addExtraRequiredSigners [verificationKeyHash vk] + & setValidityUpperBound upperValiditySlot & setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "IncrementTx") where headRedeemer = From baebc49e23551a1fa4df8ed485026f16e32eb358 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Mon, 14 Oct 2024 16:48:35 +0200 Subject: [PATCH 3/7] Add deadline deposit validator check for Claim redeemer --- hydra-plutus/src/Hydra/Contract/Deposit.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hydra-plutus/src/Hydra/Contract/Deposit.hs b/hydra-plutus/src/Hydra/Contract/Deposit.hs index f51ff9d9922..ff726a7ba93 100644 --- a/hydra-plutus/src/Hydra/Contract/Deposit.hs +++ b/hydra-plutus/src/Hydra/Contract/Deposit.hs @@ -16,7 +16,9 @@ import Hydra.Contract.Commit (Commit) import Hydra.Contract.DepositError ( DepositError ( DepositDeadlineNotReached, + DepositDeadlineSurpassed, DepositNoLowerBoundDefined, + DepositNoUpperBoundDefined, IncorrectDepositHash ), ) @@ -34,6 +36,8 @@ import PlutusLedgerApi.V2 ( ScriptContext (..), ScriptHash, SerialisedScript, + UpperBound (..), + ivTo, serialiseCompiledCode, txInfoOutputs, txInfoValidRange, @@ -66,8 +70,7 @@ validator :: DepositDatum -> DepositRedeemer -> ScriptContext -> Bool validator depositDatum r ctx = case r of Claim -> - -- FIXME: Implement Claim redeemer - True + beforeDeadline Recover m -> afterDeadline && recoverOutputs m @@ -81,6 +84,13 @@ validator depositDatum r ctx = hashOfOutputs m = hashTxOuts $ take m (txInfoOutputs txInfo) + beforeDeadline = + case ivTo (txInfoValidRange txInfo) of + UpperBound (Finite t) _ -> + traceIfFalse $(errorCode DepositDeadlineSurpassed) $ + t <= dl + _ -> traceError $(errorCode DepositNoUpperBoundDefined) + afterDeadline = case ivFrom (txInfoValidRange txInfo) of LowerBound (Finite t) _ -> From d37ce4634e07f50ce5805dc55af4bba904e1b2fa Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Tue, 15 Oct 2024 11:48:56 +0200 Subject: [PATCH 4/7] Double the contestation period when setting the deadline We need more time in order to do the increment since when posting the increment we re-use the contestation period to calculate the upper validity slot. --- hydra-node/src/Hydra/API/HTTPServer.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hydra-node/src/Hydra/API/HTTPServer.hs b/hydra-node/src/Hydra/API/HTTPServer.hs index e23ea69082a..44f7cbc0efc 100644 --- a/hydra-node/src/Hydra/API/HTTPServer.hs +++ b/hydra-node/src/Hydra/API/HTTPServer.hs @@ -216,7 +216,10 @@ handleDraftCommitUtxo env directChain getCommitInfo body = do CannotCommit -> pure $ responseLBS status500 [] (Aeson.encode (FailedToDraftTxNotInitializing :: PostTxError tx)) where deposit headId commitBlueprint = do - deadline <- addUTCTime (toNominalDiffTime contestationPeriod) <$> getCurrentTime + -- NOTE: We double the contestation period and use it for the deadline + -- value in order to give enough time for the increment to be valid in + -- terms of deadline. + deadline <- addUTCTime (toNominalDiffTime contestationPeriod * 2) <$> getCurrentTime draftDepositTx headId commitBlueprint deadline <&> \case Left e -> responseLBS status400 [] (Aeson.encode $ toJSON e) Right depositTx -> okJSON $ DraftCommitTxResponse depositTx From c73175bbdcff60796e11025a739390daa488f0f1 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Tue, 15 Oct 2024 12:35:22 +0200 Subject: [PATCH 5/7] Check head id in deposit validator Add head currency symbol in the Claim redeemer and appropriate mutations. --- hydra-plutus/src/Hydra/Contract/Deposit.hs | 19 ++++++--- .../src/Hydra/Contract/DepositError.hs | 4 +- hydra-tx/src/Hydra/Tx/Increment.hs | 2 +- hydra-tx/test/Hydra/Tx/Contract/Increment.hs | 40 +++++++++++++------ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/hydra-plutus/src/Hydra/Contract/Deposit.hs b/hydra-plutus/src/Hydra/Contract/Deposit.hs index ff726a7ba93..816cf00b331 100644 --- a/hydra-plutus/src/Hydra/Contract/Deposit.hs +++ b/hydra-plutus/src/Hydra/Contract/Deposit.hs @@ -19,7 +19,8 @@ import Hydra.Contract.DepositError ( DepositDeadlineSurpassed, DepositNoLowerBoundDefined, DepositNoUpperBoundDefined, - IncorrectDepositHash + IncorrectDepositHash, + WrongHeadIdInDepositDatum ), ) import Hydra.Contract.Error (errorCode) @@ -47,7 +48,8 @@ import PlutusTx qualified data DepositRedeemer = -- | Claims already deposited funds. - Claim + -- FIXME: Make sure to change the spec and add head CS to the Claim redeemer. + Claim CurrencySymbol | -- | Recovers m number of deposited outputs. Recover Integer @@ -61,7 +63,9 @@ PlutusTx.unstableMakeIsData ''DepositDatum -- | v_deposit validator checks -- --- * Claim redeemer -> more checks will be added +-- * Claim redeemer -> +-- * The deadline has not been reached. +-- * HeadId matches. -- -- * Recover redeemer -- * The deadline has been reached. @@ -69,13 +73,16 @@ PlutusTx.unstableMakeIsData ''DepositDatum validator :: DepositDatum -> DepositRedeemer -> ScriptContext -> Bool validator depositDatum r ctx = case r of - Claim -> - beforeDeadline + Claim headId' -> beforeDeadline && checkHeadId headId' Recover m -> afterDeadline && recoverOutputs m where - DepositDatum (_headId, dl, deposits) = depositDatum + DepositDatum (headId, dl, deposits) = depositDatum + + checkHeadId headId' = + traceIfFalse $(errorCode WrongHeadIdInDepositDatum) $ + headId' == headId recoverOutputs m = traceIfFalse $(errorCode IncorrectDepositHash) $ diff --git a/hydra-plutus/src/Hydra/Contract/DepositError.hs b/hydra-plutus/src/Hydra/Contract/DepositError.hs index a0b915d139f..3463d1fe010 100644 --- a/hydra-plutus/src/Hydra/Contract/DepositError.hs +++ b/hydra-plutus/src/Hydra/Contract/DepositError.hs @@ -12,7 +12,7 @@ data DepositError | DepositNoLowerBoundDefined | DepositDeadlineNotReached | IncorrectDepositHash - | DTNotMinted + | WrongHeadIdInDepositDatum deriving stock (Show) instance ToErrorCode DepositError where @@ -22,4 +22,4 @@ instance ToErrorCode DepositError where DepositNoLowerBoundDefined -> "D03" DepositDeadlineNotReached -> "D04" IncorrectDepositHash -> "D05" - DTNotMinted -> "D06" + WrongHeadIdInDepositDatum -> "D06" diff --git a/hydra-tx/src/Hydra/Tx/Increment.hs b/hydra-tx/src/Hydra/Tx/Increment.hs index 6248f9b12b7..9ed588d528b 100644 --- a/hydra-tx/src/Hydra/Tx/Increment.hs +++ b/hydra-tx/src/Hydra/Tx/Increment.hs @@ -95,7 +95,7 @@ incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap -- NOTE: we expect always a single output from a deposit tx (depositIn, depositOut) = List.head $ UTxO.pairs depositScriptUTxO - depositRedeemer = toScriptData Deposit.Claim + depositRedeemer = toScriptData $ Deposit.Claim $ headIdToCurrencySymbol headId depositWitness = BuildTxWith $ diff --git a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs index ecf72966c95..14a01a6dd3d 100644 --- a/hydra-tx/test/Hydra/Tx/Contract/Increment.hs +++ b/hydra-tx/test/Hydra/Tx/Contract/Increment.hs @@ -23,7 +23,7 @@ import Hydra.Plutus.Orphans () import Hydra.Tx.ContestationPeriod (ContestationPeriod, toChain) import Hydra.Tx.Contract.Deposit (depositDeadline, healthyDepositTx) import Hydra.Tx.Crypto (HydraKey, MultiSignature (..), aggregate, sign) -import Hydra.Tx.HeadId (mkHeadId) +import Hydra.Tx.HeadId (headIdToCurrencySymbol, mkHeadId) import Hydra.Tx.HeadParameters (HeadParameters (..)) import Hydra.Tx.Increment ( incrementTx, @@ -36,9 +36,9 @@ import Hydra.Tx.Snapshot (Snapshot (..), SnapshotNumber, SnapshotVersion) import Hydra.Tx.Utils (adaOnly, splitUTxO) import PlutusLedgerApi.V2 qualified as Plutus import PlutusTx.Builtins (toBuiltin) -import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, slotLength, systemStart, testNetworkId, testPolicyId) +import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, slotLength, systemStart, testHeadId, testNetworkId, testPolicyId) import Test.Hydra.Tx.Gen (genForParty, genScriptRegistry, genUTxOSized, genVerificationKey) -import Test.QuickCheck (elements) +import Test.QuickCheck (elements, oneof) import Test.QuickCheck.Instances () healthyIncrementTx :: (Tx, UTxO) @@ -147,17 +147,31 @@ healthyDatum = data IncrementMutation = -- | Move the deadline from the deposit datum back in time -- so that the increment upper bound is after the deadline - MutateDepositDeadline + DepositMutateDepositDeadline + | -- | Alter the head id + DepositMutateHeadId deriving stock (Generic, Show, Enum, Bounded) genIncrementMutation :: (Tx, UTxO) -> Gen SomeMutation genIncrementMutation (tx, utxo) = - SomeMutation (pure $ toErrorCode DepositDeadlineSurpassed) MutateDepositDeadline <$> do - let (depositIn, depositOut@(TxOut addr val _ rscript)) = UTxO.pairs (resolveInputsUTxO utxo tx) List.!! 1 - let datum = - txOutDatum $ - flip modifyInlineDatum (toTxContext depositOut) $ \case - DepositDatum (headCS', depositDatumDeadline, commits) -> - DepositDatum (headCS', Plutus.POSIXTime $ Plutus.getPOSIXTime depositDatumDeadline - 1, commits) - let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript - pure $ ChangeInput depositIn newOutput (Just $ toScriptData Claim) + oneof + [ SomeMutation (pure $ toErrorCode DepositDeadlineSurpassed) DepositMutateDepositDeadline <$> do + let (depositIn, depositOut@(TxOut addr val _ rscript)) = UTxO.pairs (resolveInputsUTxO utxo tx) List.!! 1 + let datum = + txOutDatum $ + flip modifyInlineDatum (toTxContext depositOut) $ \case + DepositDatum (headCS', depositDatumDeadline, commits) -> + DepositDatum (headCS', Plutus.POSIXTime $ Plutus.getPOSIXTime depositDatumDeadline - 1, commits) + let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript + pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (headIdToCurrencySymbol testHeadId)) + , SomeMutation (pure $ toErrorCode WrongHeadIdInDepositDatum) DepositMutateHeadId <$> do + otherHeadId <- arbitrary + let (depositIn, depositOut@(TxOut addr val _ rscript)) = UTxO.pairs (resolveInputsUTxO utxo tx) List.!! 1 + let datum = + txOutDatum $ + flip modifyInlineDatum (toTxContext depositOut) $ \case + DepositDatum (_headCS, depositDatumDeadline, commits) -> + DepositDatum (otherHeadId, depositDatumDeadline, commits) + let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript + pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (headIdToCurrencySymbol testHeadId)) + ] From d42c6e928673e7803b04febbd81b59ec258d871b Mon Sep 17 00:00:00 2001 From: Daniel Firth Date: Tue, 15 Oct 2024 11:32:24 +0000 Subject: [PATCH 6/7] Rgenerate deposit script --- hydra-plutus/scripts/vDeposit.plutus | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hydra-plutus/scripts/vDeposit.plutus b/hydra-plutus/scripts/vDeposit.plutus index 1f7969fe094..6889dc04e5b 100644 --- a/hydra-plutus/scripts/vDeposit.plutus +++ b/hydra-plutus/scripts/vDeposit.plutus @@ -1,5 +1,5 @@ { "type": "PlutusScriptV2", - "description": "hydra-vDeposit-0.19.0-96-g4d48208d28", - "cborHex": "590bae590bab0100003233223332223233223232323232323232323232323232323232323232323232323232323232323232222533533322253353232325335333573466e1d2000002031030112200215335333573466e1d20020020310301321223001003375a6ae840044c05c060d55cf0011aab9d001375400a205c6442a66a6a6a6aa00444444444444400a4400444a666a00442660109210344303400333573466e24004d401c8880080c80cc4c061241034430330013018491034430330013300549010344303500333573466e3cdc9180d99a8048009aa8011111111111110051b923023302030273500422200103002f102f13500122002225335001102d1335738004058646464a66a666ae68cdc3a400000405c05a264646464a66a666ae68cdc3a4000004064062264666444246660020080060046eb8d5d08011bad35742002600a6ae84d5d10009aba20011301801935573c0046aae74004dd51aba1002300b23232325335333573466e1d20000020320311332212330010030023013357420026eb8d5d09aba20011301801935573c0046aae74004dd50008980a00a9aab9e00235573a0026ea800cc8c8c94cd4ccd5cd19b87480000080b80b44cc8848cc00400c008c8c8c94cd4ccd5cd19b87480000080c40c04c8c8c8c8c8c8c8c8c8c8cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cc06006cd5d08059980c00d9aba100a3301801e35742012666048eb9408cd5d08041998123ae50233574200e660300346ae84018ccc09007dd69aba10053232325335333573466e1d200000203e03d1332212330010030023232325335333573466e1d20000020410401332212330010030023301d75a6ae84004c070d5d09aba20011302702835573c0046aae74004dd51aba10013232325335333573466e1d20000020410401332212330010030023301d75a6ae84004c070d5d09aba20011302702835573c0046aae74004dd51aba1357440022604804a6aae78008d55ce8009baa3574200866030eb8d5d080199981200c80a9aba100233302475c02a6ae84004c074d5d09aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae880044c05c060d55cf0011aab9d00137546ae84004c030d5d09aba20011301401535573c0046aae74004dd5000880c89808a481035054350033028221225335333573466e24009200002b02a10251533500110252213350260023353006120013370200890010008900090009191919299a999ab9a3370e900000101481408140a99a999ab9a3370e90010010148140814898078081aab9e00235573a0026ea800488c8c8c94cd4ccd5cd19b87480000080a40a04488800854cd4ccd5cd19b87480080080a40a04c84888c00c010c014d5d08008a99a999ab9a3370e900200101481408911000898078081aab9e00235573a0026ea80048c88c008dd60009812911999aab9f0012021233502030043574200460066ae880080408c8c8c94cd4ccd5cd19b87480000080980944c848888c00c014dd71aba100115335333573466e1d20020020260251321222230010053007357420022a66a666ae68cdc3a400800404c04a26424444600400a60146ae8400454cd4ccd5cd19b87480180080980944c848888c010014c014d5d0800898060069aab9e00235573a0026ea80048c8c8c94cd4ccd5cd19b87480000080940904c848888888c014020c024d5d08008a99a999ab9a3370e900100101281209909111111180380418049aba100115335333573466e1d20040020250241332212222222330060090083009357420026eb8d5d09aba200115335333573466e1d2006002025024133221222222233002009008375c6ae84004dd71aba1357440022a66a666ae68cdc3a401000404a0482664424444444660020120106eb8d5d08009bad357426ae8800454cd4ccd5cd19b874802800809409044888888801054cd4ccd5cd19b874803000809409044888888800c4c02c030d55cf0011aab9d00137540024646464a66a666ae68cdc3a4000004048046266442466002006004600a6ae84004c01cd5d09aba20011300a00b35573c0046aae74004dd50009191919299a999ab9a3370e900000101181109991091980080180118029aba1001375a6ae84d5d1000898048051aab9e00235573a0026ea80048c8c8c94cd4ccd5cd19b87480000080880844dd71aba10011300800935573c0046aae74004dd5000991191919299a999ab9a3370e90000010110108991919999111091999800802802001801191919299a999ab9a3370e900000101381309991091980080180118061aba10013300a00b357426ae880044c034038d55cf0011aab9d00137546ae8400cccc035d728061aba10023232325335333573466e1d20000020270261122200315335333573466e1d200200202702613212223001004375c6ae8400454cd4ccd5cd19b874801000809c0984c84888c008010d5d0800898068071aab9e00235573a0026ea8d5d080099803bae357426ae88004d5d10009aba20011300800935573c0046aae74004dd500091191919299a999ab9a3370e900100101101088910008a99a999ab9a3370e9000001011010899091180100198029aba10011300800935573c0046aae74004dd50009191919299a999ab9a3370e900000101000f899091180100198029aba100115335333573466e1d200200202001f132333222122333001005004003375a6ae84008dd69aba1001375a6ae84d5d10009aba20011300600735573c0046aae74004dd50009191919299a999ab9a3370e900000100f80f09909118010019bae357420022a66a666ae68cdc3a400400403e03c26424460020066eb8d5d0800898028031aab9e00235573a0026ea80048c98cd5ce000802a49035054310013300175ceb488c88c008dd5800980d111999aab9f001201623233501633221233001003002300635573a002600a6aae78004c010d5d10019aba1002005120013016225335001100b221337146eccd40088888cdd2a400066ae80d401088cdd2a400066ae80c02c008cd5d019806119a800919ba548000cd5d018068009bb100f2223374a900119aba0375000666ae80dd400119aba037500026ec4044004dd880699aba033300c75266018ea48dd400080199aba05333500213374a90001bb100b213374a900219aba000137620184266e9520023357406ea4004dd880619aba03300a7520026ec402cc0100048cd40048cdd2a400066ae80dd48009bb100423374a900119aba037520026ec4010894cd400484cdd2a400066ae80c00c004dd8802099ba548008dd8801a4c446446e98c008004c05088cd40052f5bded8c0446a0044466ae80cdd8180400118038009803001980891299a800898011801806110a99a800880111098031803802980811299a8008805910a99a800880191099a8071980380200118030009807911299a8010800910a99a801880219110a999a998088028010a801899a807801198040038008a801899a80600119802800801980711299a80088019109a8011119b8a001300600348810035003222001350022220023500122200333230010012212323330022300222230030042300222230020042300222230010042353300400400335003001122223330042533500113350060070072215335001133500800300922153233353300d00500315001133300800333500b00500c002150011333006002233500b00500100122253350011335008335008003002300600932221533353300d00600215003133300800233500b0060050011500313350083350080030023006001222532335002130014988854c8ccd4cc03801c00c540044c011261500113330070022300633500c0070010012335009300333500900400a30070021220021221223300100400332223500222350022235005223500222533353300b00600215335333573466e1c01400404003c403854cd4ccd5cd19b8900500101000f100c100d13300b00600213300b006002225335333573466e3c00800401c018401454cd4ccd5cd19b91002001007006100310041222003122200212220011220021220012323001001230022330020020011" + "description": "hydra-vDeposit-0.19.0-231-gc73175bbd", + "cborHex": "590c15590c12010000323322333222323322323232323232323232323232323232323232323232323232323232323232323232222533533332322223233500325335353530075002220012253335002213300949010344303100333573466e24004d40208880080d80d44c06924103443032001301a4910344303200133006490103443036003301d00135005222003103225335353530075002220022253335002213300949010344303400333573466e24004d40208880080d40d84c06924103443033001301a4910344303300133006490103443035003301d3724603c66a0160026aa0044444444444440146e48c098c08cc0a8d401488800440c84d400488008894cd400440bc4cd5ce00101711a800911111111111002991919299a999ab9a3370e9000001017817099191919299a999ab9a3370e9000001019819099199911091998008020018011bae357420046eb4d5d080098029aba1357440026ae880044c060064d55cf0011aab9d00137546ae84008c02c8c8c8c94cd4ccd5cd19b87480000080cc0c84cc8848cc00400c008c04cd5d08009bae357426ae880044c060064d55cf0011aab9d00137540022602802a6aae78008d55ce8009baa0033232325335333573466e1d200000202f02e1321223002003375c6ae8400454cd4ccd5cd19b87480080080bc0b84c8488c00400cdd69aba10011301401535573c0046aae74004dd5001191919299a999ab9a3370e9000001017817099910919800801801191919299a999ab9a3370e9000001019018899191919191919191919199999999999911111111111091999999999998008068060058050048040038030028020018011980c00d9aba100b3301801b357420146603003c6ae84024ccc091d728119aba100833302475ca0466ae8401ccc060068d5d080319981200fbad3574200a646464a66a666ae68cdc3a400000407e07c266442466002006004646464a66a666ae68cdc3a40000040840822664424660020060046603aeb4d5d0800980e1aba1357440022604e0506aae78008d55ce8009baa35742002646464a66a666ae68cdc3a40000040840822664424660020060046603aeb4d5d0800980e1aba1357440022604e0506aae78008d55ce8009baa357426ae880044c090094d55cf0011aab9d00137546ae84010cc061d71aba100333302401901535742004666048eb8054d5d0800980e9aba1357440026ae88004d5d10009aba2001357440026ae88004d5d10009aba2001357440026ae88004d5d10008980b80c1aab9e00235573a0026ea8d5d080098061aba1357440022602802a6aae78008d55ce8009baa001101a13011491035054350033029221225335333573466e24009200002c02b10261533500110262213350270023353006120013370200890010008900090009191919299a999ab9a3370e900000101501488148a99a999ab9a3370e90010010150148815098078081aab9e00235573a0026ea800488c8c8c94cd4ccd5cd19b87480000080a80a44488800854cd4ccd5cd19b87480080080a80a44c84888c00c010c014d5d08008a99a999ab9a3370e900200101501488911000898078081aab9e00235573a0026ea80048c88c008dd60009813111999aab9f0012022233502130043574200460066ae880080408c8c8c94cd4ccd5cd19b874800000809c0984c848888c00c014dd71aba100115335333573466e1d20020020270261321222230010053007357420022a66a666ae68cdc3a400800404e04c26424444600400a60146ae8400454cd4ccd5cd19b874801800809c0984c848888c010014c014d5d0800898060069aab9e00235573a0026ea80048c8c8c94cd4ccd5cd19b87480000080980944c848888888c014020c024d5d08008a99a999ab9a3370e900100101301289909111111180380418049aba100115335333573466e1d20040020260251332212222222330060090083009357420026eb8d5d09aba200115335333573466e1d2006002026025133221222222233002009008375c6ae84004dd71aba1357440022a66a666ae68cdc3a401000404c04a2664424444444660020120106eb8d5d08009bad357426ae8800454cd4ccd5cd19b874802800809809444888888801054cd4ccd5cd19b874803000809809444888888800c4c02c030d55cf0011aab9d00137540024646464a66a666ae68cdc3a400000404a048266442466002006004600a6ae84004c01cd5d09aba20011300a00b35573c0046aae74004dd50009191919299a999ab9a3370e900000101201189991091980080180118029aba1001375a6ae84d5d1000898048051aab9e00235573a0026ea80048c8c8c94cd4ccd5cd19b874800000808c0884dd71aba10011300800935573c0046aae74004dd5000991191919299a999ab9a3370e90000010118110991919999111091999800802802001801191919299a999ab9a3370e900000101401389991091980080180118061aba10013300a00b357426ae880044c034038d55cf0011aab9d00137546ae8400cccc035d728061aba10023232325335333573466e1d20000020280271122200315335333573466e1d200200202802713212223001004375c6ae8400454cd4ccd5cd19b87480100080a009c4c84888c008010d5d0800898068071aab9e00235573a0026ea8d5d080099803bae357426ae88004d5d10009aba20011300800935573c0046aae74004dd500091191919299a999ab9a3370e900100101181108910008a99a999ab9a3370e9000001011811099091180100198029aba10011300800935573c0046aae74004dd50009191919299a999ab9a3370e9000001010810099091180100198029aba100115335333573466e1d2002002021020132333222122333001005004003375a6ae84008dd69aba1001375a6ae84d5d10009aba20011300600735573c0046aae74004dd50009191919299a999ab9a3370e900000101000f89909118010019bae357420022a66a666ae68cdc3a400400404003e26424460020066eb8d5d0800898028031aab9e00235573a0026ea80048c98cd5ce000802a49035054310013300175ceb488c88c008dd5800980d911999aab9f001201723233501733221233001003002300635573a002600a6aae78004c010d5d10019aba10020051200122333573466e3c00800406005cc058894cd4004402c884cdc51bb33500222223374a900019aba035004223374a900019aba0300b00233574066018466a002466e952000335740601a0026ec403c888cdd2a400466ae80dd400199aba0375000466ae80dd40009bb1011001376201a66ae80ccc031d4998063a92375000200666ae814ccd40084cdd2a40006ec402c84cdd2a400866ae80004dd88061099ba548008cd5d01ba9001376201866ae80cc029d48009bb100b3004001233500123374a900019aba037520026ec40108cdd2a400466ae80dd48009bb1004225335001213374a900019aba030030013762008266e952002376200693111911ba630020013014223350014bd6f7b630111a8011119aba0337606010004600e002600c006602244a66a002260046006018442a66a0022004442600c600e00a602044a66a0022016442a66a002200644266a01c6600e008004600c002601e444a66a0042002442a66a006200864442a666a6602200a0042a006266a01e0046601000e0022a006266a0180046600a002006601c44a66a00220064426a0044466e28004c01800d22010035003222001350022220023500122200333230010012212323330022300222230030042300222230020042300222230010042353300400400335003001122223330042533500113350060070072215335001133500800300922153233353300d00500315001133300800333500b00500c002150011333006002233500b00500100122253350011335008335008003002300600932221533353300d00600215003133300800233500b0060050011500313350083350080030023006001222532335002130014988854c8ccd4cc03801c00c540044c011261500113330070022300633500c0070010012335009300333500900400a30070021220021221223300100400332223500222350022235005223500222533353300b00600215335333573466e1c01400404003c403854cd4ccd5cd19b8900500101000f100c100d13300b00600213300b006002225335333573466e3c00800401c018401454cd4ccd5cd19b91002001007006100310041222003122200212220011220021220012323001001230022330020020011" } From 362f9cd931e147472c0c9f52d97af6228ae69a58 Mon Sep 17 00:00:00 2001 From: Sasha Bogicevic Date: Tue, 15 Oct 2024 14:15:21 +0200 Subject: [PATCH 7/7] Wait for the deadline to pass in cluster recover tests --- hydra-cluster/src/Hydra/Cluster/Scenarios.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs index 626125db518..753ddcdf531 100644 --- a/hydra-cluster/src/Hydra/Cluster/Scenarios.hs +++ b/hydra-cluster/src/Hydra/Cluster/Scenarios.hs @@ -801,8 +801,8 @@ canRecoverDeposit tracer workDir node hydraScriptsTxId = `shouldReturn` 0 let path = BSC.unpack $ urlEncode False $ encodeUtf8 $ T.pack $ show (getTxId $ getTxBody tx) - - threadDelay $ fromIntegral deadline + -- NOTE: we need to wait for the deadline to pass before we can recover the deposit + threadDelay $ fromIntegral (deadline * 2) recoverResp <- parseUrlThrow ("DELETE " <> hydraNodeBaseUrl n1 <> "/commits/" <> path) @@ -885,7 +885,8 @@ canSeePendingDeposits tracer workDir node hydraScriptsTxId = forM_ deposited $ \deposit -> do let path = BSC.unpack $ urlEncode False $ encodeUtf8 $ T.pack $ show deposit - threadDelay $ fromIntegral deadline + -- NOTE: we need to wait for the deadline to pass before we can recover the deposit + threadDelay $ fromIntegral (deadline * 2) recoverResp <- parseUrlThrow ("DELETE " <> hydraNodeBaseUrl n1 <> "/commits/" <> path) >>= httpJSON