Skip to content

Commit

Permalink
Add Deposit deadline option (#1798)
Browse files Browse the repository at this point in the history
We were re-using `contestation-period` value as a deposit deadline. This
PR adds a separate argument to specify deposit deadline.

---

<!-- Consider each and tick it off one way or the other -->
* [x] CHANGELOG updated or not needed
* [x] Documentation updated or not needed
* [x] Haddocks updated or not needed
* [x] No new TODOs introduced or explained herafter
  • Loading branch information
v0d1ch authored Jan 23, 2025
2 parents c1c759b + 933010d commit f339ed1
Show file tree
Hide file tree
Showing 27 changed files with 363 additions and 197 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ changes.
with the community members building on Hydra. This feature means you can commit funds to a Head while it is running.
TODO: Implement missing spec changes.

- There is a new `--deposit-deadline` argument to hydra-node that determines the maximum time for the hydra-node to detect a deposit.
After this time has passed users can recover a deposit in case it wasn't observed previously.

- **BREAKING** hydra-node accepts multiple `hydra-scripts-tx-id` as a comma-seperated list, as the outcome of changes in the Hydra scripts publishing.

- Tested with `cardano-node 10.1.2` and `cardano-cli 10.1.1.0`.
Expand Down
8 changes: 3 additions & 5 deletions docs/docs/dev/commit_to_a_Head.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ up and made available inside of L2 by posting a **increment** transaction. This
also happens automatically but here we want to describe this process and bring
it closer to Hydra users.

It is worthwhile mentioning that deposit deadline is double the value used for
contestation period. This gives the users control by specifying the
contestation period it in the arguments to `hydra-node` executable.

::::info
Deadline information is present in the `CommitRecorded` API server output.
Deposit deadline is specified as argument to `hydra-node` executable eg.
`--deposit-deadline "100s"`. Deadline information is present in the
`CommitRecorded` API server output.
::::


Expand Down
5 changes: 2 additions & 3 deletions docs/docs/dev/incremental-commits-and-decommits.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ The deposit transaction contains a deadline - time window in which we expect
the hydra-node to be able to observe this deposit and issue a _increment_
transaction that will do the heavy lifting and bring the specified input on L2.

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

Once a hydra-node observes a deposit transaction it will record the deposit as
pending into the local state. There can be many pending deposits but the new
Expand Down
4 changes: 3 additions & 1 deletion hydra-cluster/bench/Bench/EndToEnd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Hydra.Network (Host)
import Hydra.Tx (HeadId, txId)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod))
import Hydra.Tx.Crypto (generateSigningKey)
import Hydra.Tx.DepositDeadline (DepositDeadline (UnsafeDepositDeadline))
import HydraNode (
HydraClient,
HydraNodeLog,
Expand Down Expand Up @@ -89,7 +90,8 @@ bench startingNodeId timeoutSeconds workDir dataset = do
putStrLn $ "Starting hydra cluster in " <> workDir
let hydraTracer = contramap FromHydraNode tracer
let contestationPeriod = UnsafeContestationPeriod 10
withHydraCluster hydraTracer workDir nodeSocket startingNodeId cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod $ \clients -> do
let depositDeadline = UnsafeDepositDeadline 10
withHydraCluster hydraTracer workDir nodeSocket startingNodeId cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod depositDeadline $ \clients -> do
waitForNodesConnected hydraTracer 20 clients
scenario hydraTracer node workDir dataset clients

Expand Down
4 changes: 4 additions & 0 deletions hydra-cluster/src/Hydra/Cluster/Fixture.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Hydra.Cardano.Api qualified as Api
import Hydra.Tx (Party, deriveParty)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (..))
import Hydra.Tx.Crypto (HydraKey, SigningKey, VerificationKey, generateSigningKey, getVerificationKey)
import Hydra.Tx.DepositDeadline (DepositDeadline (..))

alice, bob, carol :: Party
alice = deriveParty aliceSk
Expand All @@ -29,6 +30,9 @@ carolVk = getVerificationKey carolSk
cperiod :: ContestationPeriod
cperiod = UnsafeContestationPeriod 10

ddeadline :: DepositDeadline
ddeadline = UnsafeDepositDeadline 100

-- NOTE: This is hard-coded and needs to correspond to the initial funds set in
-- the genesis-shelley.json file.
availableInitialFunds :: Num a => a
Expand Down
78 changes: 51 additions & 27 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import Hydra.Logging (Tracer, traceWith)
import Hydra.Options (DirectChainConfig (..), networkId, startChainFrom)
import Hydra.Tx (HeadId, IsTx (balance), Party, txId)
import Hydra.Tx.ContestationPeriod (ContestationPeriod (UnsafeContestationPeriod), fromNominalDiffTime)
import Hydra.Tx.DepositDeadline (DepositDeadline (..))
import Hydra.Tx.Utils (dummyValidatorScript, verificationKeyToOnChainId)
import HydraNode (
HydraClient (..),
Expand Down Expand Up @@ -162,12 +163,13 @@ restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
seedFromFaucet_ cardanoNode bobCardanoVk 100_000_000 (contramap FromFaucet tracer)

let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId

bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId

let hydraTracer = contramap FromHydraNode tracer
Expand All @@ -192,16 +194,17 @@ restartedNodeCanObserveCommitTx tracer workDir cardanoNode hydraScriptsTxId = do
testPreventResumeReconfiguredPeer :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [TxId] -> IO ()
testPreventResumeReconfiguredPeer tracer workDir cardanoNode hydraScriptsTxId = do
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId

aliceChainConfigWithoutBob <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> setNetworkId networkId

bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId

let hydraTracer = contramap FromHydraNode tracer
Expand Down Expand Up @@ -237,8 +240,9 @@ restartedNodeCanAbort :: Tracer IO EndToEndLog -> FilePath -> RunningNode -> [Tx
restartedNodeCanAbort tracer workDir cardanoNode hydraScriptsTxId = do
refuelIfNeeded tracer cardanoNode Alice 100_000_000
let contestationPeriod = UnsafeContestationPeriod 2
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
-- we delibelately do not start from a chain point here to highlight the
-- need for persistence
<&> modifyConfig (\config -> config{networkId, startChainFrom = Nothing})
Expand Down Expand Up @@ -279,8 +283,9 @@ singlePartyHeadFullLifeCycle tracer workDir node hydraScriptsTxId =
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
contestationPeriod <- fromNominalDiffTime $ 10 * blockTime
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
-- Initialize & open head
Expand Down Expand Up @@ -335,8 +340,9 @@ singlePartyOpenAHead tracer workDir node hydraScriptsTxId callback =
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})

(walletVk, walletSk) <- generate genKeyPair
Expand Down Expand Up @@ -374,7 +380,9 @@ singlePartyCommitsFromExternal tracer workDir node hydraScriptsTxId =
)
$ do
refuelIfNeeded tracer node Alice 25_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -417,7 +425,9 @@ singlePartyUsesScriptOnL2 tracer workDir node hydraScriptsTxId =
)
$ do
refuelIfNeeded tracer node Alice 250_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 1
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 1
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -551,7 +561,9 @@ singlePartyCommitsScriptBlueprint ::
singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
(_, walletSk) <- keysFor AliceFunds
Expand Down Expand Up @@ -638,7 +650,9 @@ persistenceCanLoadWithEmptyCommit ::
persistenceCanLoadWithEmptyCommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
headId <- withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -678,7 +692,9 @@ singlePartyCommitsFromExternalTxBlueprint ::
singlePartyCommitsFromExternalTxBlueprint tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 20_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
(someExternalVk, someExternalSk) <- generate genKeyPair
Expand Down Expand Up @@ -739,8 +755,9 @@ canCloseWithLongContestationPeriod tracer workDir node hydraScriptsTxId = do
-- Start hydra-node on chain tip
tip <- queryTip networkId nodeSocket
let oneWeek = UnsafeContestationPeriod (60 * 60 * 24 * 7)
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] oneWeek depositDeadline
<&> modifyConfig (\config -> config{networkId, startChainFrom = Just tip})
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
Expand Down Expand Up @@ -774,7 +791,9 @@ canSubmitTransactionThroughAPI ::
canSubmitTransactionThroughAPI tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 25_000_000
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] $ UnsafeContestationPeriod 100
let contestationPeriod = UnsafeContestationPeriod 100
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
let hydraNodeId = 1
let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir hydraNodeId aliceSk [] [hydraNodeId] $ \_ -> do
Expand Down Expand Up @@ -828,8 +847,9 @@ threeNodesNoErrorsOnOpen tracer tmpDir node@RunningNode{nodeSocket} hydraScripts
hydraKeys = [aliceSk, bobSk, carolSk]

let contestationPeriod = UnsafeContestationPeriod 2
let depositDeadline = UnsafeDepositDeadline 50
let hydraTracer = contramap FromHydraNode tracer
withHydraCluster hydraTracer tmpDir nodeSocket 1 cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod $ \clients -> do
withHydraCluster hydraTracer tmpDir nodeSocket 1 cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod depositDeadline $ \clients -> do
let leader = head clients
waitForNodesConnected hydraTracer 20 clients

Expand Down Expand Up @@ -867,8 +887,10 @@ initWithWrongKeys workDir tracer node@RunningNode{nodeSocket} hydraScriptsTxId =
(aliceCardanoVk, _) <- keysFor Alice
(carolCardanoVk, _) <- keysFor Carol

aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Carol] (UnsafeContestationPeriod 2)
bobChainConfig <- chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] (UnsafeContestationPeriod 2)
let contestationPeriod = UnsafeContestationPeriod 2
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <- chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Carol] contestationPeriod depositDeadline
bobChainConfig <- chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline

let hydraTracer = contramap FromHydraNode tracer
withHydraNode hydraTracer aliceChainConfig workDir 3 aliceSk [bobVk] [3, 4] $ \n1 -> do
Expand Down Expand Up @@ -900,14 +922,13 @@ canCommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Bob) $ do
refuelIfNeeded tracer node Alice 30_000_000
refuelIfNeeded tracer node Bob 30_000_000
-- NOTE: it is important to provide _large_ enough contestation period so that
-- increment tx can be submitted before the deadline
let contestationPeriod = UnsafeContestationPeriod 20
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -998,11 +1019,12 @@ canRecoverDeposit tracer workDir node hydraScriptsTxId =
-- NOTE: this value is also used to determine the deposit deadline
let deadline = 5
let contestationPeriod = UnsafeContestationPeriod deadline
let depositDeadline = UnsafeDepositDeadline 5
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
headId <- withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -1092,11 +1114,12 @@ canSeePendingDeposits tracer workDir node hydraScriptsTxId =
refuelIfNeeded tracer node Bob 30_000_000
let deadline = 1
let contestationPeriod = UnsafeContestationPeriod deadline
let depositDeadline = UnsafeDepositDeadline 1
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [Bob] contestationPeriod depositDeadline
<&> setNetworkId networkId
bobChainConfig <-
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod
chainConfigFor Bob workDir nodeSocket hydraScriptsTxId [Alice] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [bobVk] [2] $ \n1 -> do
_ <- withHydraNode hydraTracer bobChainConfig workDir 2 bobSk [aliceVk] [1] $ \n2 -> do
Expand Down Expand Up @@ -1176,8 +1199,9 @@ canDecommit tracer workDir node hydraScriptsTxId =
(`finally` returnFundsToFaucet tracer node Alice) $ do
refuelIfNeeded tracer node Alice 30_000_000
let contestationPeriod = UnsafeContestationPeriod 1
let depositDeadline = UnsafeDepositDeadline 200
aliceChainConfig <-
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod
chainConfigFor Alice workDir nodeSocket hydraScriptsTxId [] contestationPeriod depositDeadline
<&> setNetworkId networkId
withHydraNode hydraTracer aliceChainConfig workDir 1 aliceSk [] [1] $ \n1 -> do
-- Initialize & open head
Expand Down
5 changes: 4 additions & 1 deletion hydra-cluster/src/Hydra/Cluster/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Hydra.Cardano.Api (
import Hydra.Cluster.Fixture (Actor, actorName, fundsOf)
import Hydra.Options (ChainConfig (..), DirectChainConfig (..), defaultDirectChainConfig)
import Hydra.Tx.ContestationPeriod (ContestationPeriod)
import Hydra.Tx.DepositDeadline (DepositDeadline)
import Paths_hydra_cluster qualified as Pkg
import System.FilePath ((<.>), (</>))
import Test.Hydra.Prelude (failure)
Expand Down Expand Up @@ -70,8 +71,9 @@ chainConfigFor ::
[TxId] ->
[Actor] ->
ContestationPeriod ->
DepositDeadline ->
IO ChainConfig
chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod = do
chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod depositDeadline = do
when (me `elem` them) $
failure $
show me <> " must not be in " <> show them
Expand All @@ -91,6 +93,7 @@ chainConfigFor me targetDir nodeSocket hydraScriptsTxId them contestationPeriod
, cardanoSigningKey = actorFilePath me "sk"
, cardanoVerificationKeys = [actorFilePath himOrHer "vk" | himOrHer <- them]
, contestationPeriod
, depositDeadline
}
where
actorFilePath actor fileType = targetDir </> actorFileName actor fileType
Expand Down
Loading

0 comments on commit f339ed1

Please sign in to comment.