Skip to content

Commit fbdb64f

Browse files
committed
Increase tx size to make increment work for now
1 parent a6ef190 commit fbdb64f

File tree

7 files changed

+47
-26
lines changed

7 files changed

+47
-26
lines changed

hydra-cluster/config/devnet/genesis-shelley.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"keyDeposit": 0,
2323
"maxBlockBodySize": 65536,
2424
"maxBlockHeaderSize": 1100,
25-
"maxTxSize": 16384,
25+
"maxTxSize": 17700,
2626
"minFeeA": 44,
2727
"minFeeB": 155381,
2828
"minPoolCost": 0,

hydra-cluster/src/Hydra/Cluster/Scenarios.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,9 @@ canCommit :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> TxId -> IO ()
701701
canCommit tracer workDir node hydraScriptsTxId =
702702
(`finally` returnFundsToFaucet tracer node Alice) $ do
703703
refuelIfNeeded tracer node Alice 30_000_000
704-
let contestationPeriod = UnsafeContestationPeriod 1
704+
-- NOTE: it is important to provide _large_ enough contestation period so that
705+
-- increment tx can be submitted before the deadline
706+
let contestationPeriod = UnsafeContestationPeriod 5
705707
aliceChainConfig <-
706708
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
707709
<&> setNetworkId networkId
@@ -752,7 +754,7 @@ canRecoverDeposit tracer workDir node hydraScriptsTxId =
752754
refuelIfNeeded tracer node Alice 30_000_000
753755
refuelIfNeeded tracer node Bob 30_000_000
754756
-- NOTE: this value is also used to determine the deposit deadline
755-
let deadline = 1
757+
let deadline = 5
756758
let contestationPeriod = UnsafeContestationPeriod deadline
757759
aliceChainConfig <-
758760
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod

hydra-plutus/src/Hydra/Contract/Head.hs

+19-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# OPTIONS_GHC -fno-specialize #-}
44
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:conservative-optimisation #-}
55
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:defer-errors #-}
6+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:optimize #-}
67
-- Plutus core version to compile to. In babbage era, that is Cardano protocol
78
-- version 7 and 8, only plutus-core version 1.0.0 is available.
89
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-}
@@ -41,11 +42,10 @@ import PlutusLedgerApi.V2 (
4142
TxInInfo (..),
4243
TxInfo (..),
4344
TxOut (..),
44-
TxOutRef (..),
4545
UpperBound (..),
4646
Value (Value),
4747
)
48-
import PlutusLedgerApi.V2.Contexts (findOwnInput, spendsOutput)
48+
import PlutusLedgerApi.V2.Contexts (findOwnInput, findTxInByTxOutRef)
4949
import PlutusTx (CompiledCode)
5050
import PlutusTx qualified
5151
import PlutusTx.AssocMap qualified as AssocMap
@@ -240,34 +240,42 @@ checkIncrement ::
240240
IncrementRedeemer ->
241241
Bool
242242
checkIncrement ctx@ScriptContext{scriptContextTxInfo = txInfo} openBefore redeemer =
243-
-- FIXME: spec is mentioning the n also needs to be unchanged - what is n here?
243+
-- FIXME: spec is mentioning the n also needs to be unchanged - what is n here? utxo hash?
244244
-- "parameters cid, 𝑘̃ H , 𝑛, 𝑇 stay unchanged"
245245
mustNotChangeParameters (prevParties, nextParties) (prevCperiod, nextCperiod) (prevHeadId, nextHeadId)
246246
&& mustIncreaseVersion
247-
&& checkSnapshotSignature
248247
&& mustIncreaseValue
249248
&& mustBeSignedByParticipant ctx prevHeadId
249+
&& checkSnapshotSignature
250250
&& claimedDepositIsSpent
251251
where
252-
deposited = foldMap (depositDatum . txInInfoResolved) (txInfoInputs txInfo)
252+
inputs = txInfoInputs txInfo
253+
254+
depositInput =
255+
case findTxInByTxOutRef increment txInfo of
256+
Nothing -> traceError $(errorCode DepositInputNotFound)
257+
Just i -> i
253258

254-
depositHash = hashPreSerializedCommits deposited
259+
commits = depositDatum $ txInInfoResolved depositInput
255260

256-
depositInput = txInfoInputs txInfo !! 1
261+
depositHash = hashPreSerializedCommits commits
257262

258263
depositRef = txInInfoOutRef depositInput
259264

260265
depositValue = txOutValue $ txInInfoResolved depositInput
261266

262-
headInValue = txOutValue $ txInInfoResolved (head (txInfoInputs txInfo))
267+
headInValue =
268+
case find (hasST prevHeadId) $ txOutValue . txInInfoResolved <$> inputs of
269+
Nothing -> traceError $(errorCode HeadInputNotFound)
270+
Just i -> i
263271

264-
headOutValue = foldMap txOutValue $ txInfoOutputs txInfo
272+
headOutValue = txOutValue $ head $ txInfoOutputs txInfo
265273

266274
IncrementRedeemer{signature, snapshotNumber, increment} = redeemer
267275

268276
claimedDepositIsSpent =
269277
traceIfFalse $(errorCode DepositNotSpent) $
270-
depositRef == increment && spendsOutput txInfo (txOutRefId depositRef) (txOutRefIdx depositRef)
278+
depositRef == increment
271279

272280
checkSnapshotSignature =
273281
verifySnapshotSignature nextParties (nextHeadId, prevVersion, snapshotNumber, nextUtxoHash, depositHash, emptyHash) signature
@@ -623,6 +631,7 @@ makeContestationDeadline cperiod ScriptContext{scriptContextTxInfo} =
623631
_ -> traceError $(errorCode CloseNoUpperBoundDefined)
624632
{-# INLINEABLE makeContestationDeadline #-}
625633

634+
-- | This is safe only because usually Head transaction only consume one input.
626635
getHeadInput :: ScriptContext -> TxInInfo
627636
getHeadInput ctx = case findOwnInput ctx of
628637
Nothing -> traceError $(errorCode ScriptNotSpendingAHeadInput)

hydra-plutus/src/Hydra/Contract/HeadError.hs

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ data HeadError
5151
| FanoutNoLowerBoundDefined
5252
| FanoutUTxOToDecommitHashMismatch
5353
| DepositNotSpent
54+
| DepositInputNotFound
55+
| HeadInputNotFound
5456

5557
instance ToErrorCode HeadError where
5658
toErrorCode = \case
@@ -106,3 +108,5 @@ instance ToErrorCode HeadError where
106108
LowerBoundBeforeContestationDeadline -> "H43"
107109
FanoutNoLowerBoundDefined -> "H44"
108110
DepositNotSpent -> "H45"
111+
DepositInputNotFound -> "H46"
112+
HeadInputNotFound -> "H47"

hydra-tx/src/Hydra/Tx/Increment.hs

+10-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap
5959
& setTxMetadata (TxMetadataInEra $ mkHydraHeadV1TxName "IncrementTx")
6060
where
6161
headRedeemer =
62-
toScriptData $ Head.Increment Head.IncrementRedeemer{signature = toPlutusSignatures sigs, snapshotNumber = fromIntegral number, increment = toPlutusTxOutRef depositIn}
62+
toScriptData $
63+
Head.Increment
64+
Head.IncrementRedeemer
65+
{ signature = toPlutusSignatures sigs
66+
, snapshotNumber = fromIntegral number
67+
, increment = toPlutusTxOutRef depositIn
68+
}
6369

6470
HeadParameters{parties, contestationPeriod} = headParameters
6571

@@ -90,12 +96,12 @@ incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap
9096
, version = toInteger version + 1
9197
}
9298

93-
depositedValue = txOutValue depositOut
99+
depositedValue = foldMap (txOutValue . snd) (UTxO.pairs (fromMaybe mempty utxoToCommit))
94100

95101
depositScript = fromPlutusScript @PlutusScriptV2 Deposit.validatorScript
96102

97103
-- NOTE: we expect always a single output from a deposit tx
98-
(depositIn, depositOut) = List.head $ UTxO.pairs depositScriptUTxO
104+
(depositIn, _) = List.head $ UTxO.pairs depositScriptUTxO
99105

100106
depositRedeemer = toScriptData $ Deposit.Claim $ headIdToCurrencySymbol headId
101107

@@ -104,4 +110,4 @@ incrementTx scriptRegistry vk headId headParameters (headInput, headOutput) snap
104110
ScriptWitness scriptWitnessInCtx $
105111
mkScriptWitness depositScript InlineScriptDatum depositRedeemer
106112

107-
Snapshot{utxo, version, number} = snapshot
113+
Snapshot{utxo, utxoToCommit, version, number} = snapshot

hydra-tx/test/Hydra/Tx/Contract/Deposit.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ module Hydra.Tx.Contract.Deposit where
33
import Hydra.Cardano.Api
44
import Hydra.Prelude
55

6-
import Data.Time (UTCTime (..), secondsToDiffTime)
7-
import Data.Time.Calendar (fromGregorian)
86
import Hydra.Tx (mkHeadId)
97
import Hydra.Tx.BlueprintTx (CommitBlueprintTx (..))
108
import Hydra.Tx.Deposit (depositTx)
9+
import System.IO.Unsafe (unsafePerformIO)
1110
import Test.Hydra.Tx.Fixture (testNetworkId, testPolicyId)
1211
import Test.Hydra.Tx.Gen (genUTxOAdaOnlyOfSize)
1312

@@ -23,7 +22,8 @@ healthyDepositTx =
2322
depositDeadline
2423

2524
depositDeadline :: UTCTime
26-
depositDeadline = UTCTime (fromGregorian 2024 15 0) (secondsToDiffTime 0)
25+
depositDeadline = unsafePerformIO getCurrentTime
26+
{-# NOINLINE depositDeadline #-}
2727

2828
healthyDepositUTxO :: UTxO
29-
healthyDepositUTxO = genUTxOAdaOnlyOfSize 5 `generateWith` 42
29+
healthyDepositUTxO = genUTxOAdaOnlyOfSize 1 `generateWith` 42

hydra-tx/test/Hydra/Tx/Contract/Increment.hs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Hydra.Tx.Snapshot (Snapshot (..), SnapshotNumber, SnapshotVersion)
4141
import Hydra.Tx.Utils (adaOnly)
4242
import PlutusLedgerApi.V2 qualified as Plutus
4343
import PlutusTx.Builtins (toBuiltin)
44-
import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, slotLength, systemStart, testHeadId, testNetworkId, testPolicyId)
44+
import Test.Hydra.Tx.Fixture (aliceSk, bobSk, carolSk, slotLength, systemStart, testNetworkId, testPolicyId)
4545
import Test.Hydra.Tx.Gen (genForParty, genScriptRegistry, genUTxOSized, genValue, genVerificationKey)
4646
import Test.QuickCheck (arbitrarySizedNatural, elements, oneof, suchThat)
4747
import Test.QuickCheck.Instances ()
@@ -169,9 +169,9 @@ genIncrementMutation (tx, utxo) =
169169
txOutDatum $
170170
flip modifyInlineDatum (toTxContext depositOut) $ \case
171171
DepositDatum (headCS', depositDatumDeadline, commits) ->
172-
DepositDatum (headCS', Plutus.POSIXTime $ Plutus.getPOSIXTime depositDatumDeadline - 1, commits)
172+
DepositDatum (headCS', Plutus.POSIXTime $ Plutus.getPOSIXTime depositDatumDeadline - 1000, commits)
173173
let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript
174-
pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (headIdToCurrencySymbol testHeadId))
174+
pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (toPlutusCurrencySymbol testPolicyId))
175175
, SomeMutation (pure $ toErrorCode WrongHeadIdInDepositDatum) DepositMutateHeadId <$> do
176176
otherHeadId <- arbitrary
177177
let datum =
@@ -180,7 +180,7 @@ genIncrementMutation (tx, utxo) =
180180
DepositDatum (_headCS, depositDatumDeadline, commits) ->
181181
DepositDatum (otherHeadId, depositDatumDeadline, commits)
182182
let newOutput = toCtxUTxOTxOut $ TxOut addr val datum rscript
183-
pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (headIdToCurrencySymbol testHeadId))
183+
pure $ ChangeInput depositIn newOutput (Just $ toScriptData $ Claim (toPlutusCurrencySymbol testPolicyId))
184184
, SomeMutation (pure $ toErrorCode ChangedParameters) IncrementMutateParties <$> do
185185
mutatedParties <- arbitrary `suchThat` (/= healthyOnChainParties)
186186
pure $ ChangeOutput 0 $ modifyInlineDatum (replaceParties mutatedParties) headTxOut
@@ -202,7 +202,7 @@ genIncrementMutation (tx, utxo) =
202202
, SomeMutation (pure $ toErrorCode SignerIsNotAParticipant) AlterRequiredSigner <$> do
203203
newSigner <- verificationKeyHash <$> genVerificationKey `suchThat` (/= somePartyCardanoVerificationKey)
204204
pure $ ChangeRequiredSigners [newSigner]
205-
, SomeMutation (pure $ toErrorCode DepositNotSpent) IncrementDifferentClaimRedeemer . ChangeHeadRedeemer <$> do
205+
, SomeMutation (pure $ toErrorCode DepositInputNotFound) IncrementDifferentClaimRedeemer . ChangeHeadRedeemer <$> do
206206
invalidDepositRef <- genTxIn
207207
pure $
208208
Head.Increment

0 commit comments

Comments
 (0)