Skip to content

Commit c16e945

Browse files
committed
Reduce AckSn spam (#2146)
Ignores valid `AckSn` messages in case we have seen the acknowledged snapshot already as confirmed. This was discovered when running so-called "mirror nodes" where a counter-party runs multiple `hydra-node` instances with the same set of keys. --- * [x] CHANGELOG updated * [x] Documentation update not needed * [x] Haddocks update not needed * [x] No new TODOs introduced
1 parent 312a617 commit c16e945

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

hydra-node/hydra-node.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: hydra-node
3-
version: 0.22.2
3+
version: 0.22.4
44
synopsis: The Hydra node
55
author: IOG
66
copyright: 2022 IOG

hydra-node/src/Hydra/HeadLogic.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
647647

648648
waitOnSeenSnapshot continue =
649649
case seenSnapshot of
650+
-- NOTE: Ignore any redundant AckSn for snapshots we have already seen as
651+
-- confirmed. This is for example happening if a party runs multiple
652+
-- instances of hydra-node using the same keys.
653+
LastSeenSnapshot{lastSeen}
654+
| sn <= lastSeen -> noop
650655
SeenSnapshot snapshot sigs
651656
| seenSn == sn -> continue snapshot sigs
652657
_ -> wait WaitOnSeenSnapshot

hydra-node/test/Hydra/HeadLogicSpec.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import Hydra.HeadLogic (
4646
WaitReason (..),
4747
aggregateState,
4848
cause,
49+
noop,
4950
update,
5051
)
5152
import Hydra.HeadLogic.State (SeenSnapshot (..), getHeadParameters)
@@ -63,7 +64,7 @@ import Hydra.Tx.Crypto (aggregate, generateSigningKey, sign)
6364
import Hydra.Tx.Crypto qualified as Crypto
6465
import Hydra.Tx.HeadParameters (HeadParameters (..))
6566
import Hydra.Tx.IsTx (IsTx (..))
66-
import Hydra.Tx.Party (Party (..))
67+
import Hydra.Tx.Party (Party (..), deriveParty)
6768
import Hydra.Tx.Snapshot (ConfirmedSnapshot (..), Snapshot (..), SnapshotNumber, SnapshotVersion, getSnapshot)
6869
import Test.Hydra.Node.Fixture qualified as Fixture
6970
import Test.Hydra.Tx.Fixture (alice, aliceSk, bob, bobSk, carol, carolSk, deriveOnChainId, testHeadId, testHeadSeed)
@@ -397,6 +398,21 @@ spec =
397398
Error (RequireFailed SnapshotAlreadySigned{receivedSignature}) -> receivedSignature == carol
398399
_ -> False
399400

401+
it "ignores valid AckSn if snapshot already confirmed" $ do
402+
let reqSn = receiveMessage $ ReqSn 0 1 [] Nothing Nothing
403+
snapshot1 = Snapshot testHeadId 0 1 [] mempty Nothing Nothing
404+
ackFrom sk = receiveMessageFrom (deriveParty sk) $ AckSn (sign sk snapshot1) 1
405+
406+
s0 <- runHeadLogic bobEnv ledger (inOpenState threeParties) $ do
407+
step reqSn
408+
step (ackFrom carolSk)
409+
step (ackFrom bobSk)
410+
step (ackFrom aliceSk)
411+
getState
412+
413+
update bobEnv ledger s0 (ackFrom carolSk)
414+
`shouldBe` noop
415+
400416
it "rejects snapshot request with transaction not applicable to previous snapshot" $ do
401417
let reqTx42 = receiveMessage $ ReqTx (SimpleTx 42 mempty (utxoRef 1))
402418
reqTx1 = receiveMessage $ ReqTx (SimpleTx 1 (utxoRef 1) (utxoRef 2))

0 commit comments

Comments
 (0)