Skip to content

Commit 06a23fe

Browse files
committed
Fix up the tests; document the flow a little
1 parent 94af00d commit 06a23fe

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ changes.
1414

1515
- Add `Environment` to `Greetings` message, enabling clients to access runtime settings.
1616

17+
- Bugfix for incorrect logic around fanning out with decommit/commit in progress
18+
1719
## [0.22.2] - 2025.06.30
1820

1921
* Fix wrong hydra-script-tx-ids in networks.json

hydra-node/src/Hydra/HeadLogic.hs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,19 +1268,21 @@ onClosedClientFanout closedState =
12681268
{ postChainTx =
12691269
FanoutTx
12701270
{ utxo
1271-
-- XXX: Perhaps move this check down so it can be more readily
1272-
-- tested.
1273-
-- Here we check that to include in the fanout; if the versions
1274-
-- are the same, the utxoToCommit or utxoToDecommit has not been
1275-
-- used on chain yet; so we disregard, so we must not fan it out.
1276-
, utxoToCommit =
1271+
, -- XXX: Perhaps move this check down so it can be more readily
1272+
-- tested.
1273+
-- Commit:
1274+
-- Here we check that to include in the fanout; if the versions
1275+
-- are the same, the utxoToCommit has not been used on chain yet
1276+
-- so we disregard, so we must not fan it out.
1277+
utxoToCommit =
12771278
if snapshotVersion == version
1278-
then Nothing
1279-
else utxoToCommit
1280-
, utxoToDecommit =
1279+
then Nothing
1280+
else utxoToCommit
1281+
, -- For decommit, if it hasn't happened, we _must_ fan it out.
1282+
utxoToDecommit =
12811283
if snapshotVersion == version
1282-
then utxoToDecommit
1283-
else Nothing
1284+
then utxoToDecommit
1285+
else Nothing
12841286
, headSeed
12851287
, contestationDeadline
12861288
}

hydra-node/test/Hydra/BehaviorSpec.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,32 +780,27 @@ spec = parallel $ do
780780

781781
waitUntil [n1, n2] $ DecommitFinalized{headId = testHeadId, distributedUTxO = utxoRef 42}
782782

783-
it "can close with decommit in flight" $
783+
it "can fanout with decommit in flight" $
784784
shouldRunInSim $ do
785785
withSimulatedChainAndNetwork $ \chain ->
786786
withHydraNode aliceSk [bob] chain $ \n1 -> do
787787
withHydraNode bobSk [alice] chain $ \n2 -> do
788788
openHead2 chain n1 n2
789789
let decommitTx = SimpleTx 1 (utxoRef 2) (utxoRef 42)
790790
send n2 (Decommit{decommitTx})
791+
-- Close while the decommit is still in flight
791792
send n1 Close
792-
-- XXX: Can't assert DecommitFinalized here as it is not
793-
-- emitted because an incorrect simulation of the chain here.
794-
-- The OnDecrementTx only reaches the nodes HeadLogic after
795-
-- the OnCloseTx. This is impossible using a proper chain so
796-
-- we don't assert it here.
797-
-- waitUntil [n1, n2] $ DecommitFinalized{headId = testHeadId, distributedUTxO = utxoRef 42}
798793
waitUntil [n1, n2] $ ReadyToFanout{headId = testHeadId}
799794
send n1 Fanout
800-
waitUntil [n1, n2] $ HeadIsFinalized{headId = testHeadId, utxo = utxoRefs [1]}
795+
waitUntil [n1, n2] $ HeadIsFinalized{headId = testHeadId, utxo = utxoRefs [1, 42]}
801796

802-
it "fanout utxo is correct after a decommit" $
797+
it "can fanout after a decommit" $
803798
shouldRunInSim $ do
804799
withSimulatedChainAndNetwork $ \chain ->
805800
withHydraNode aliceSk [bob] chain $ \n1 -> do
806801
withHydraNode bobSk [alice] chain $ \n2 -> do
807802
openHead2 chain n1 n2
808-
let decommitTx = SimpleTx 1 (utxoRef 1) (utxoRef 42)
803+
let decommitTx = SimpleTx 1 (utxoRef 2) (utxoRef 42)
809804
send n2 (Decommit{decommitTx})
810805
waitUntil [n1, n2] $
811806
DecommitApproved
@@ -816,7 +811,7 @@ spec = parallel $ do
816811
send n1 Close
817812
waitUntil [n1, n2] $ ReadyToFanout{headId = testHeadId}
818813
send n1 Fanout
819-
waitUntil [n1, n2] $ HeadIsFinalized{headId = testHeadId, utxo = utxoRefs [2]}
814+
waitUntil [n1, n2] $ HeadIsFinalized{headId = testHeadId, utxo = utxoRefs [1]}
820815

821816
it "can fanout with empty utxo" $
822817
shouldRunInSim $ do

0 commit comments

Comments
 (0)