Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DirectChainSpec flakiness #493

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ changes.
+ Generate a pair of Hydra keys
+ Output the marker datum hash

- Added some sample Terraform-based configuration files to spin up GCP and AWS Hydra node

#### Fixed

- Prevent transactions from being resubmitted for application over and over [#485](https://github.com/input-output-hk/hydra-poc/issues/485)
- Fix flakiness in tests involving the Cardano chain [#492](https://github.com/input-output-hk/hydra-poc/issues/492)

## [0.7.0] - 2022-08-23

- **BREAKING** Switch to `BabbageEra` and `PlutusV2`.
Expand Down
6 changes: 5 additions & 1 deletion hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Era = BabbageEra
type UTxO = UTxO' (TxOut CtxUTxO Era)

-- | Newtype with phantom types mostly required to work around the poor interface
-- of 'Ledger.UTXO'and provide 'Monoid' and 'Foldable' instances to make utxo
-- of 'Ledger.UTXO' and provide 'Monoid' and 'Foldable' instances to make utxo
-- manipulation bareable.
newtype UTxO' out = UTxO
{ toMap :: Map TxIn out
Expand All @@ -38,6 +38,10 @@ newtype UTxO' out = UTxO
instance Traversable UTxO' where
traverse fn (UTxO m) = UTxO <$> traverse fn m

-- | Checks some `UTxO` is contained in some other `UTxO`.
contains :: Eq out => UTxO' out -> UTxO' out -> Bool
contains (UTxO m) (UTxO m') = m' `Map.isSubmapOf` m

-- | Create a 'UTxO' from a list of 'TxIn' and 'out' pairs.
fromPairs :: [(TxIn, out)] -> UTxO' out
fromPairs = UTxO . Map.fromList
Expand Down
1 change: 0 additions & 1 deletion hydra-cluster/src/CardanoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ sign signingKey body =
[makeShelleyKeyWitness body (WitnessPaymentKey signingKey)]
body

-- TODO: This should return a 'UTxO' (from Hydra.Ledger.Cardano)
waitForPayment ::
NetworkId ->
FilePath ->
Expand Down
20 changes: 17 additions & 3 deletions hydra-cluster/test/Test/DirectChainSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Test.DirectChainSpec where
import Hydra.Prelude
import Test.Hydra.Prelude

import Cardano.Api.UTxO (contains)
import CardanoClient (
QueryPoint (QueryTip),
buildAddress,
Expand All @@ -20,6 +21,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as B8
import Hydra.Cardano.Api (
ChainPoint (..),
UTxO,
lovelaceToValue,
txOutValue,
unsafeDeserialiseFromRawBytesBase16,
Expand Down Expand Up @@ -102,14 +104,15 @@ spec = around showLogsOnFailure $ do
withIOManager $ \iocp -> do
seedFromFaucet_ node aliceCardanoVk 100_000_000 Fuel
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx} -> do
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx, getUTxO} -> do
withDirectChain nullTracer defaultNetworkId iocp nodeSocket bobKeys bob cardanoKeys Nothing hydraScriptsTxId (putMVar bobsCallback) $ \_ -> do
postTx $ InitTx $ HeadParameters cperiod [alice, bob, carol]
alicesCallback `observesInTime` OnInitTx cperiod [alice, bob, carol]
bobsCallback `observesInTime` OnInitTx cperiod [alice, bob, carol]

let aliceCommitment = 66_000_000
aliceUTxO <- seedFromFaucet node aliceCardanoVk aliceCommitment Normal
waitUntilHasUTxO getUTxO aliceUTxO
postTx $ CommitTx alice aliceUTxO

alicesCallback `observesInTime` OnCommitTx alice aliceUTxO
Expand Down Expand Up @@ -156,7 +159,7 @@ spec = around showLogsOnFailure $ do
withIOManager $ \iocp -> do
seedFromFaucet_ node aliceCardanoVk 100_000_000 Fuel
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx} -> do
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx, getUTxO} -> do
postTx $ InitTx $ HeadParameters cperiod [alice]
alicesCallback `observesInTime` OnInitTx cperiod [alice]

Expand All @@ -172,6 +175,7 @@ spec = around showLogsOnFailure $ do
_ -> False

aliceUTxO <- seedFromFaucet node aliceCardanoVk 1_000_000 Normal
waitUntilHasUTxO getUTxO aliceUTxO
postTx $ CommitTx alice aliceUTxO
alicesCallback `observesInTime` OnCommitTx alice aliceUTxO

Expand Down Expand Up @@ -200,11 +204,12 @@ spec = around showLogsOnFailure $ do
withIOManager $ \iocp -> do
seedFromFaucet_ node aliceCardanoVk 100_000_000 Fuel
hydraScriptsTxId <- publishHydraScriptsAs node Faucet
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx} -> do
withDirectChain (contramap (FromDirectChain "alice") tracer) defaultNetworkId iocp nodeSocket aliceKeys alice cardanoKeys Nothing hydraScriptsTxId (putMVar alicesCallback) $ \Chain{postTx, getUTxO} -> do
postTx $ InitTx $ HeadParameters cperiod [alice]
alicesCallback `observesInTime` OnInitTx cperiod [alice]

someUTxO <- seedFromFaucet node aliceCardanoVk 1_000_000 Normal
waitUntilHasUTxO getUTxO someUTxO
postTx $ CommitTx alice someUTxO
alicesCallback `observesInTime` OnCommitTx alice someUTxO

Expand Down Expand Up @@ -304,6 +309,15 @@ spec = around showLogsOnFailure $ do
(removeTrailingNewline (encodeUtf8 hydraScriptsTxIdStr))
failAfter 5 $ void $ queryScriptRegistry networkId nodeSocket hydraScriptsTxId

waitUntilHasUTxO :: IO UTxO -> UTxO -> IO ()
waitUntilHasUTxO getUTxO utxo = go
where
go = do
knownUTxO <- getUTxO
unless (knownUTxO `contains` utxo) $ do
threadDelay 1
go

data TestClusterLog
= FromNode NodeLog
| FromDirectChain Text DirectChainLog
Expand Down
96 changes: 31 additions & 65 deletions hydra-node/golden/Event SimpleTx.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,91 +2,57 @@
"samples": [
{
"chainEvent": {
"contents": {
"contestationPeriod": 2592000,
"parties": [],
"tag": "OnInitTx"
},
"tag": "Observation"
"contents": "1864-04-28T23:16:21.931579670592Z",
"tag": "Tick"
},
"tag": "OnChainEvent"
},
{
"clientInput": {
"tag": "Abort"
},
"tag": "ClientEvent"
},
{
"postChainTx": {
"confirmedSnapshot": {
"signatures": {
"multiSignature": [
"8bbd3a3952143162d6e0802ee851e4f7524c2e9218e354b6684397d8461be506ef99fab7ac19098bcbbd3417926418504d65dc276fca139b4e91e886eef9300e",
"414397fb545cf1a26ad70f98ba09c0c762a387b592b68e32685ac2a047d5ecc15ded6e6c56be83835c6afdb507e337aa5f02aae561ee1ec03114319c3f416f03",
"a8e63123ce9066a8e254b1414f1271c2fefcfbe14e697d29d9e99b42db79a758ae217362023e399d7a8763a4e2a5f9afac88f10452e5e52f52c758c1f47c7c00",
"1cb1fc09b7d3312f8cd0dc2b229b2edc865ba0332aa6258dddfe3c87ab523f708f3fb13bd62faf141c62e35d8ec890c10bb29ddac8d25666877e298e40524508",
"51c0c7670e124a74193eb386233631df49a480dfda4d4e1c89b89e7e619c9f96a3ffe910568cde02dd700ffb6e9f0ad2eefccf239deb972d0b23cea2f8a5fa08",
"b639fea4088d622cfb16fa307134ed99f5ed911268a5726e32f392555f6eecedf7be0d412bde3c1a45df1b87dee36ff9c2f16f4c7246eef625b05fd2add18c03"
]
},
"snapshot": {
"confirmedTransactions": [],
"snapshotNumber": 16,
"utxo": [
-30,
-25,
-19,
-12,
-1,
3,
16
]
},
"tag": "ConfirmedSnapshot"
},
"tag": "ContestTx"
},
"postTxError": {
"headUTxO": [
-30,
"tag": "CollectComTx",
"utxo": [
-29,
-27,
-24,
-22,
-18,
-8,
-3,
-13,
-1,
0,
2,
8,
24
],
"input": "nL\u000e𰅲aEX𪏨\u0016Z",
"tag": "CannotSpendInput",
"walletUTxO": [
-3,
-2,
5,
13,
23,
26
1,
6,
14,
16,
23
]
},
"postTxError": {
"tag": "NoPaymentInput"
},
"tag": "PostTxError"
},
{
"clientInput": {
"tag": "Fanout"
"message": {
"peer": {
"hostname": "0.0.118.152",
"port": 22295
},
"tag": "Disconnected"
},
"tag": "ClientEvent"
"tag": "NetworkEvent",
"ttl": 18
},
{
"clientInput": {
"tag": "Abort"
"tag": "Close"
},
"tag": "ClientEvent"
},
{
"chainEvent": {
"contents": "1864-04-18T07:18:47.523454077472Z",
"tag": "Tick"
},
"tag": "OnChainEvent"
}
],
"seed": 589608564
"seed": -732045436
}
Loading