Skip to content

Commit

Permalink
Add a small margin to remaining period to prevent tx to fail
Browse files Browse the repository at this point in the history
also compute wait time in ETE test with some ridiculous formula taking
into account contestation period, close grace time  and slot length!
  • Loading branch information
abailly-iohk committed May 23, 2022
1 parent cbecdd4 commit 6384a99
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions hydra-cluster/test/Test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}

module Test.EndToEndSpec where
Expand Down Expand Up @@ -34,7 +35,9 @@ import Hydra.Cardano.Api (
lovelaceToValue,
mkVkAddress,
serialiseAddress,
unSlotNo,
)
import Hydra.Chain.Direct (closeGraceTime)
import Hydra.Crypto (deriveVerificationKey, generateSigningKey)
import qualified Hydra.Crypto as Hydra
import Hydra.Ledger (txId)
Expand Down Expand Up @@ -273,7 +276,8 @@ initAndClose tracer clusterIx node@(RunningNode _ nodeSocket) = do
seedFromFaucet_ defaultNetworkId node bobCardanoVk 100_000_000 Fuel
seedFromFaucet_ defaultNetworkId node carolCardanoVk 100_000_000 Fuel

let contestationPeriod = 10 :: Natural
let contestationPeriod = 2

send n1 $ input "Init" ["contestationPeriod" .= contestationPeriod]
waitFor tracer 10 [n1, n2, n3] $
output "ReadyToCommit" ["parties" .= Set.fromList [alice, bob, carol]]
Expand Down Expand Up @@ -342,8 +346,8 @@ initAndClose tracer clusterIx node@(RunningNode _ nodeSocket) = do
guard $ snapshotNumber == toJSON expectedSnapshotNumber

-- NOTE: We expect the head to be finalized after the contestation period
-- and some three secs later
waitFor tracer (contestationPeriod + 3) [n1] $
-- and some three secs later, plus the closeGraceTime * slotLength
waitFor tracer (truncate $ contestationPeriod + (fromIntegral @_ @Double (unSlotNo closeGraceTime) * 0.1) + 3) [n1] $
output "HeadIsFinalized" ["utxo" .= newUTxO]

case fromJSON $ toJSON newUTxO of
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ chainSyncHandler tracer callback headState =
-- transformation into an `OnChainTx`
let event = case (onChainTx, reifyState nextState) of
(OnCloseTx{snapshotNumber}, TkClosed) ->
let remainingDiffTime = diffUTCTime (posixToUTCTime $ getContestationDeadline nextState) now
in OnCloseTx{snapshotNumber, remainingContestationPeriod = remainingDiffTime}
let remainingTimeWithBuffer = 1 + diffUTCTime (posixToUTCTime $ getContestationDeadline nextState) now
in OnCloseTx{snapshotNumber, remainingContestationPeriod = remainingTimeWithBuffer}
_ -> onChainTx
pure $ event : observed
Nothing ->
Expand Down

0 comments on commit 6384a99

Please sign in to comment.