Skip to content

Commit 7c02763

Browse files
committed
Add depositDeadline to Environment and usages in hydra-node
1 parent 1da008b commit 7c02763

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

docs/docs/dev/commit_to_a_Head.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ up and made available inside of L2 by posting a **increment** transaction. This
6464
also happens automatically but here we want to describe this process and bring
6565
it closer to Hydra users.
6666

67-
It is worthwhile mentioning that deposit deadline is double the value used for
68-
contestation period. This gives the users control by specifying the
69-
contestation period it in the arguments to `hydra-node` executable.
70-
7167
::::info
72-
Deadline information is present in the `CommitRecorded` API server output.
68+
Deposit deadline is specified as argument to `hydra-node` executable eg.
69+
`--deposit-deadline "100s"`. Deadline information is present in the
70+
`CommitRecorded` API server output.
7371
::::
7472

7573

docs/docs/dev/incremental-commits-and-decommits.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ The deposit transaction contains a deadline - time window in which we expect
5959
the hydra-node to be able to observe this deposit and issue a _increment_
6060
transaction that will do the heavy lifting and bring the specified input on L2.
6161

62-
Currently, _contestation period_ value is used to specify a deposit deadline
63-
but this should be made available as a separate argument to hydra-node since it
64-
heavily depends on the network we are running on.
62+
Deposit deadline value is specified as the `hydra-node` option eg.
63+
`--deposit-deadline "100s"`
6564

6665
Once a hydra-node observes a deposit transaction it will record the deposit as
6766
pending into the local state. There can be many pending deposits but the new

hydra-node/src/Hydra/API/HTTPServer.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Network.Wai (
3939
rawPathInfo,
4040
responseLBS,
4141
)
42+
import Hydra.Tx.DepositDeadline (depositToNominalDiffTime)
4243

4344
newtype DraftCommitTxResponse tx = DraftCommitTxResponse
4445
{ commitTx :: tx
@@ -216,10 +217,7 @@ handleDraftCommitUtxo env directChain getCommitInfo body = do
216217
CannotCommit -> pure $ responseLBS status500 [] (Aeson.encode (FailedToDraftTxNotInitializing :: PostTxError tx))
217218
where
218219
deposit headId commitBlueprint = do
219-
-- NOTE: We double the contestation period and use it for the deadline
220-
-- value in order to give enough time for the increment to be valid in
221-
-- terms of deadline.
222-
deadline <- addUTCTime (toNominalDiffTime contestationPeriod * 2) <$> getCurrentTime
220+
deadline <- addUTCTime (depositToNominalDiffTime depositDeadline) <$> getCurrentTime
223221
draftDepositTx headId commitBlueprint deadline <&> \case
224222
Left e -> responseLBS status400 [] (Aeson.encode $ toJSON e)
225223
Right depositTx -> okJSON $ DraftCommitTxResponse depositTx
@@ -237,7 +235,7 @@ handleDraftCommitUtxo env directChain getCommitInfo body = do
237235
Right commitTx ->
238236
okJSON $ DraftCommitTxResponse commitTx
239237
Chain{draftCommitTx, draftDepositTx} = directChain
240-
Environment{contestationPeriod} = env
238+
Environment{depositDeadline} = env
241239

242240
-- | Handle request to recover a pending deposit.
243241
handleRecoverCommitUtxo ::

hydra-node/test/Hydra/BehaviorSpec.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Hydra.Node.InputQueue (InputQueue (enqueue))
5151
import Hydra.NodeSpec (createPersistenceInMemory)
5252
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod), toNominalDiffTime)
5353
import Hydra.Tx.Crypto (HydraKey, aggregate, sign)
54+
import Hydra.Tx.DepositDeadline (DepositDeadline (UnsafeDepositDeadline))
5455
import Hydra.Tx.Environment (Environment (..))
5556
import Hydra.Tx.IsTx (IsTx (..))
5657
import Hydra.Tx.Party (Party (..), deriveParty, getParty)
@@ -1152,6 +1153,9 @@ toOnChainTx now = \case
11521153
testContestationPeriod :: ContestationPeriod
11531154
testContestationPeriod = UnsafeContestationPeriod 10
11541155

1156+
testDepositDeadline :: DepositDeadline
1157+
testDepositDeadline = UnsafeDepositDeadline 10
1158+
11551159
nothingHappensFor ::
11561160
(MonadTimer m, MonadThrow m, IsChainState tx) =>
11571161
TestHydraClient tx m ->
@@ -1171,7 +1175,7 @@ withHydraNode signingKey otherParties chain action = do
11711175
outputs <- atomically newTQueue
11721176
outputHistory <- newTVarIO mempty
11731177
let initialChainState = SimpleChainState{slot = ChainSlot 0}
1174-
node <- createHydraNode traceInIOSim simpleLedger initialChainState signingKey otherParties outputs outputHistory chain testContestationPeriod
1178+
node <- createHydraNode traceInIOSim simpleLedger initialChainState signingKey otherParties outputs outputHistory chain testContestationPeriod testDepositDeadline
11751179
withAsync (runHydraNode node) $ \_ ->
11761180
action (createTestHydraClient outputs outputHistory node)
11771181

@@ -1201,8 +1205,9 @@ createHydraNode ::
12011205
TVar m [ServerOutput tx] ->
12021206
SimulatedChainNetwork tx m ->
12031207
ContestationPeriod ->
1208+
DepositDeadline ->
12041209
m (HydraNode tx m)
1205-
createHydraNode tracer ledger chainState signingKey otherParties outputs outputHistory chain cp = do
1210+
createHydraNode tracer ledger chainState signingKey otherParties outputs outputHistory chain cp depositDeadline = do
12061211
persistence <- createPersistenceInMemory
12071212
(eventSource, eventSink) <- eventPairFromPersistenceIncremental persistence
12081213
node <- connectNode chain =<< hydrate tracer env ledger chainState eventSource [eventSink]
@@ -1223,6 +1228,7 @@ createHydraNode tracer ledger chainState signingKey otherParties outputs outputH
12231228
, otherParties
12241229
, contestationPeriod = cp
12251230
, participants
1231+
, depositDeadline
12261232
}
12271233
party = deriveParty signingKey
12281234

hydra-node/test/Hydra/Model.hs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE DuplicateRecordFields #-}
22
{-# LANGUAGE UndecidableInstances #-}
33
{-# OPTIONS_GHC -Wno-orphans #-}
4+
{-# OPTIONS_GHC -Wno-unused-matches #-}
45

56
-- | A /Model/ of the Hydra head Protocol.
67
--
@@ -67,6 +68,7 @@ import Hydra.Model.Payment (CardanoSigningKey (..), Payment (..), applyTx, genAd
6768
import Hydra.Node (runHydraNode)
6869
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod))
6970
import Hydra.Tx.Crypto (HydraKey)
71+
import Hydra.Tx.DepositDeadline (DepositDeadline (UnsafeDepositDeadline))
7072
import Hydra.Tx.HeadParameters (HeadParameters (..))
7173
import Hydra.Tx.IsTx (IsTx (..))
7274
import Hydra.Tx.Party (Party (..), deriveParty)
@@ -147,6 +149,7 @@ instance StateModel WorldState where
147149
Seed ::
148150
{ seedKeys :: [(SigningKey HydraKey, CardanoSigningKey)]
149151
, seedContestationPeriod :: ContestationPeriod
152+
, seedDepositDeadline :: DepositDeadline
150153
, toCommit :: Uncommitted
151154
} ->
152155
Action WorldState ()
@@ -415,8 +418,9 @@ genSeed :: Gen (Action WorldState ())
415418
genSeed = do
416419
seedKeys <- resize maximumNumberOfParties partyKeys
417420
seedContestationPeriod <- genContestationPeriod
421+
seedDepositDeadline <- genDepositDeadline
418422
toCommit <- mconcat <$> mapM genToCommit seedKeys
419-
pure $ Seed{seedKeys, seedContestationPeriod, toCommit}
423+
pure $ Seed{seedKeys, seedContestationPeriod, seedDepositDeadline, toCommit}
420424

421425
genToCommit :: (SigningKey HydraKey, CardanoSigningKey) -> Gen (Map Party [(CardanoSigningKey, Value)])
422426
genToCommit (hk, ck) = do
@@ -428,6 +432,11 @@ genContestationPeriod = do
428432
n <- choose (1, 200)
429433
pure $ UnsafeContestationPeriod $ wordToNatural n
430434

435+
genDepositDeadline :: Gen DepositDeadline
436+
genDepositDeadline = do
437+
n <- choose (1, 200)
438+
pure $ UnsafeDepositDeadline $ wordToNatural n
439+
431440
genInit :: [(SigningKey HydraKey, b)] -> Gen (Action WorldState ())
432441
genInit hydraParties = do
433442
key <- fst <$> elements hydraParties
@@ -554,8 +563,8 @@ instance
554563

555564
perform st action lookup = do
556565
case action of
557-
Seed{seedKeys, seedContestationPeriod, toCommit} ->
558-
seedWorld seedKeys seedContestationPeriod toCommit
566+
Seed{seedKeys, seedContestationPeriod, seedDepositDeadline, toCommit} ->
567+
seedWorld seedKeys seedContestationPeriod seedDepositDeadline toCommit
559568
Commit party utxo ->
560569
performCommit (snd <$> hydraParties st) party utxo
561570
Decommit party tx ->
@@ -606,9 +615,10 @@ seedWorld ::
606615
) =>
607616
[(SigningKey HydraKey, CardanoSigningKey)] ->
608617
ContestationPeriod ->
618+
DepositDeadline ->
609619
Uncommitted ->
610620
RunMonad m ()
611-
seedWorld seedKeys seedCP futureCommits = do
621+
seedWorld seedKeys seedCP depositDeadline futureCommits = do
612622
tr <- gets logger
613623

614624
mockChain@SimulatedChainNetwork{tickThread} <-
@@ -624,7 +634,7 @@ seedWorld seedKeys seedCP futureCommits = do
624634
labelTQueueIO outputs ("outputs-" <> shortLabel hsk)
625635
outputHistory <- newTVarIO []
626636
labelTVarIO outputHistory ("history-" <> shortLabel hsk)
627-
node <- createHydraNode (contramap Node tr) ledger initialChainState hsk otherParties outputs outputHistory mockChain seedCP
637+
node <- createHydraNode (contramap Node tr) ledger initialChainState hsk otherParties outputs outputHistory mockChain seedCP depositDeadline
628638
let testClient = createTestHydraClient outputs outputHistory node
629639
nodeThread <- async $ labelThisThread ("node-" <> shortLabel hsk) >> runHydraNode node
630640
link nodeThread

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Hydra.Prelude
44

55
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
66
import Hydra.Tx.Crypto (HydraKey, SigningKey)
7+
import Hydra.Tx.DepositDeadline (DepositDeadline)
78
import Hydra.Tx.OnChainId (OnChainId)
89
import Hydra.Tx.Party (HasParty (..), Party, deriveParty)
910

@@ -17,6 +18,7 @@ data Environment = Environment
1718
, -- XXX: Improve naming
1819
participants :: [OnChainId]
1920
, contestationPeriod :: ContestationPeriod
21+
, depositDeadline :: DepositDeadline
2022
}
2123
deriving stock (Show, Eq)
2224

@@ -26,13 +28,15 @@ instance Arbitrary Environment where
2628
otherParties <- arbitrary
2729
participants <- arbitrary
2830
contestationPeriod <- arbitrary
31+
depositDeadline <- arbitrary
2932
pure $
3033
Environment
3134
{ signingKey
3235
, party = deriveParty signingKey
3336
, otherParties
3437
, contestationPeriod
3538
, participants
39+
, depositDeadline
3640
}
3741

3842
instance HasParty Environment where

hydra-tx/testlib/Test/Hydra/Tx/Fixture.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Hydra.Tx.HeadParameters (HeadParameters (..))
4040
import Hydra.Tx.OnChainId (AsType (..), OnChainId)
4141
import Hydra.Tx.Party (deriveParty)
4242
import System.IO.Unsafe (unsafePerformIO)
43+
import Hydra.Tx.DepositDeadline (DepositDeadline(..))
4344

4445
-- | Our beloved alice, bob, and carol.
4546
alice, bob, carol :: Party
@@ -83,6 +84,7 @@ testEnvironment =
8384
, signingKey = aliceSk
8485
, otherParties = [bob, carol]
8586
, contestationPeriod = cperiod
87+
, depositDeadline = UnsafeDepositDeadline 20
8688
, participants = deriveOnChainId <$> [alice, bob, carol]
8789
}
8890

0 commit comments

Comments
 (0)