Skip to content

Commit

Permalink
Add headId to OnChainTx
Browse files Browse the repository at this point in the history
This was the last step to make all e2e tests green (two heads on the
same network turned out to be flaky).
  • Loading branch information
v0d1ch committed Dec 8, 2023
1 parent ce00931 commit 6b5f8c4
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 19 deletions.
12 changes: 6 additions & 6 deletions hydra-cluster/test/Test/DirectChainSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ spec = around (showLogsOnFailure "DirectChainSpec") $ do

externalCommit node aliceChain aliceExternalSk aliceHeadId aliceUTxO

aliceChain `observesInTime` OnCommitTx alice aliceUTxO
bobChain `observesInTime` OnCommitTx alice aliceUTxO
aliceChain `observesInTime` OnCommitTx aliceHeadId alice aliceUTxO
bobChain `observesInTime` OnCommitTx bobHeadId alice aliceUTxO

postTx $ AbortTx{utxo = aliceUTxO, headSeed = aliceHeadSeed}
--
Expand Down Expand Up @@ -226,7 +226,7 @@ spec = around (showLogsOnFailure "DirectChainSpec") $ do
newAliceUTxO <- seedFromFaucet node aliceExternalVk 1_000_000 (contramap FromFaucet tracer)

externalCommit node aliceChain aliceExternalSk headId newAliceUTxO
aliceChain `observesInTime` OnCommitTx alice newAliceUTxO
aliceChain `observesInTime` OnCommitTx headId alice newAliceUTxO

it "can commit empty UTxO" $ \tracer -> do
withTempDir "hydra-cluster" $ \tmp -> do
Expand All @@ -247,7 +247,7 @@ spec = around (showLogsOnFailure "DirectChainSpec") $ do

(_, aliceExternalSk) <- generate genKeyPair
externalCommit node aliceChain aliceExternalSk headId mempty
aliceChain `observesInTime` OnCommitTx alice mempty
aliceChain `observesInTime` OnCommitTx headId alice mempty

it "can open, close & fanout a Head" $ \tracer -> do
withTempDir "hydra-cluster" $ \tmp -> do
Expand All @@ -269,7 +269,7 @@ spec = around (showLogsOnFailure "DirectChainSpec") $ do
(headId, headSeed) <- aliceChain `observesInTimeSatisfying` hasInitTxWith headParameters participants

externalCommit node aliceChain aliceExternalSk headId someUTxO
aliceChain `observesInTime` OnCommitTx alice someUTxO
aliceChain `observesInTime` OnCommitTx headId alice someUTxO

postTx $ CollectComTx someUTxO headId headParameters
aliceChain `observesInTime` OnCollectComTx{headId}
Expand Down Expand Up @@ -397,7 +397,7 @@ spec = around (showLogsOnFailure "DirectChainSpec") $ do
headId <- fst <$> aliceChain `observesInTimeSatisfying` hasInitTxWith headParameters participants

externalCommit node aliceChain aliceExternalSk headId someUTxO
aliceChain `observesInTime` OnCommitTx alice someUTxO
aliceChain `observesInTime` OnCommitTx headId alice someUTxO

postTx $ CollectComTx someUTxO headId headParameters
-- Head is open with someUTxO
Expand Down
3 changes: 3 additions & 0 deletions hydra-node/json-schemas/logs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,7 @@ definitions:
additionalProperties: false
required:
- tag
- headId
- party
- committed
description: >-
Expand All @@ -1766,6 +1767,8 @@ definitions:
tag:
type: string
enum: ["OnCommitTx"]
headId:
$ref: "api.yaml#/components/schemas/HeadId"
party:
$ref: "api.yaml#/components/schemas/Party"
committed:
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ data OnChainTx tx
, headParameters :: HeadParameters
, participants :: [OnChainId]
}
| OnCommitTx {party :: Party, committed :: UTxOType tx}
| OnCommitTx {headId :: HeadId, party :: Party, committed :: UTxOType tx}
| OnAbortTx {headId :: HeadId}
| OnCollectComTx {headId :: HeadId}
| OnCloseTx
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Chain/Direct/Handlers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ convertObservation = \case
}
Abort AbortObservation{headId} ->
pure OnAbortTx{headId}
Commit CommitObservation{party, committed} ->
pure OnCommitTx{party, committed}
Commit CommitObservation{headId, party, committed} ->
pure OnCommitTx{headId, party, committed}
CollectCom CollectComObservation{headId} ->
pure OnCollectComTx{headId}
Close CloseObservation{headId, snapshotNumber, threadOutput = ClosedThreadOutput{closedContestationDeadline}} ->
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Chain/Direct/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ observeCommit ctx st tx = do
observation <- observeCommitTx networkId utxo tx
let CommitObservation{commitOutput, party, committed, headId = commitHeadId} = observation
guard $ commitHeadId == headId
let event = OnCommitTx{party, committed}
let event = OnCommitTx{headId, party, committed}
let st' =
st
{ initialInitials =
Expand Down
5 changes: 3 additions & 2 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,9 @@ update env ledger st ev = case (st, ev) of
onIdleClientInit env
(Idle _, OnChainEvent Observation{observedTx = OnInitTx{headId, headSeed, headParameters, participants}, newChainState}) ->
onIdleChainInitTx env newChainState headId headSeed headParameters participants
(Initial initialState, OnChainEvent Observation{observedTx = OnCommitTx{party = pt, committed = utxo}, newChainState}) ->
onInitialChainCommitTx initialState newChainState pt utxo
(Initial initialState@InitialState{headId = ourHeadId}, OnChainEvent Observation{observedTx = OnCommitTx{headId, party = pt, committed = utxo}, newChainState})
| ourHeadId == headId -> onInitialChainCommitTx initialState newChainState pt utxo
| otherwise -> Error NotOurHead{ourHeadId, otherHeadId = headId}
(Initial initialState, ClientEvent Abort) ->
onInitialClientAbort initialState
(Initial initialState@InitialState{headId = ourHeadId}, OnChainEvent Observation{observedTx = OnCollectComTx{headId}, newChainState})
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/BehaviorSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ simulatedChainAndNetwork initialChainState = do
, tickThread
, rollbackAndForward = rollbackAndForward nodes history localChainState
, simulateCommit = \(party, committed) ->
createAndYieldEvent nodes history localChainState $ OnCommitTx{party, committed}
createAndYieldEvent nodes history localChainState $ OnCommitTx{headId = testHeadId, party, committed}
}
where
-- seconds
Expand Down
6 changes: 3 additions & 3 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ spec =
update bobEnv ledger s0 event `shouldBe` Error (InvalidEvent event s0)

it "everyone does collect on last commit after collect com" $ do
let aliceCommit = OnCommitTx alice (utxoRef 1)
bobCommit = OnCommitTx bob (utxoRef 2)
carolCommit = OnCommitTx carol (utxoRef 3)
let aliceCommit = OnCommitTx testHeadId alice (utxoRef 1)
bobCommit = OnCommitTx testHeadId bob (utxoRef 2)
carolCommit = OnCommitTx testHeadId carol (utxoRef 3)
waitingForLastCommit <-
runEvents bobEnv ledger (inInitialState threeParties) $ do
step (observeEventAtSlot 1 aliceCommit)
Expand Down
6 changes: 3 additions & 3 deletions hydra-node/test/Hydra/NodeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ isReqSn = \case
eventsToOpenHead :: [Event SimpleTx]
eventsToOpenHead =
[ observationEvent $ OnInitTx testHeadId testHeadSeed headParameters participants
, observationEvent $ OnCommitTx carol (utxoRef 3)
, observationEvent $ OnCommitTx bob (utxoRef 2)
, observationEvent $ OnCommitTx alice (utxoRef 1)
, observationEvent $ OnCommitTx testHeadId carol (utxoRef 3)
, observationEvent $ OnCommitTx testHeadId bob (utxoRef 2)
, observationEvent $ OnCommitTx testHeadId alice (utxoRef 1)
, observationEvent $ OnCollectComTx testHeadId
]
where
Expand Down

0 comments on commit 6b5f8c4

Please sign in to comment.