Skip to content

Commit 01ce547

Browse files
authored
Fanout fix (#2105)
Make sure we can fanout if we have a decommit or commit that is in progress.
2 parents 4d7f5f0 + 06a23fe commit 01ce547

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,15 +1268,21 @@ onClosedClientFanout closedState =
12681268
{ postChainTx =
12691269
FanoutTx
12701270
{ utxo
1271-
, utxoToCommit =
1272-
-- NOTE: note that logic is flipped in the commit and decommit case here.
1273-
if toInteger snapshotVersion == max (toInteger version - 1) 0
1274-
then utxoToCommit
1275-
else Nothing
1276-
, utxoToDecommit =
1277-
if toInteger snapshotVersion == max (toInteger version - 1) 0
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 =
1278+
if snapshotVersion == version
12781279
then Nothing
1279-
else utxoToDecommit
1280+
else utxoToCommit
1281+
, -- For decommit, if it hasn't happened, we _must_ fan it out.
1282+
utxoToDecommit =
1283+
if snapshotVersion == version
1284+
then utxoToDecommit
1285+
else Nothing
12801286
, headSeed
12811287
, contestationDeadline
12821288
}

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)