Skip to content

Commit

Permalink
Align with the spec wait of cleaning allTxs
Browse files Browse the repository at this point in the history
Transactions included in a snapshot can be removed from allTxs.

Before, it was done when the snapshot was fully validated but, in
fact, as soon as we receiver a request for snapshot, we can not
unsee this snapshot so, anyway, we're commited to, either, integrate
these transactions in this snapshot and validate it or kill the
head liveness.
  • Loading branch information
pgrange committed Jul 20, 2023
1 parent 8225ff6 commit 36f2676
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
11 changes: 5 additions & 6 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,8 @@ onOpenNetworkReqSn env ledger st otherParty sn requestedTxIds =
(Effects [NetworkEffect $ AckSn snapshotSignature sn] `Combined`) $ do
-- Spec: TODO T̂ ← {tx | ∀tx ∈ T̂ , Û ◦ tx ≠ ⊥} and L̂ ← Û ◦ T̂
let (seenTxs', seenUTxO') = pruneTransactions u
-- Spec: T̂all ← {tx | ∀tx ∈ T̂all : tx ∉ Treq }
let allTxs' = foldr Map.delete allTxs requestedTxIds
NewState
( Open
st
Expand All @@ -773,6 +775,7 @@ onOpenNetworkReqSn env ledger st otherParty sn requestedTxIds =
{ seenSnapshot = SeenSnapshot nextSnapshot mempty
, seenTxs = seenTxs'
, seenUTxO = seenUTxO'
, allTxs = allTxs'
}
}
)
Expand Down Expand Up @@ -862,7 +865,7 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
-- Spec: require s ∈ {ŝ, ŝ + 1}
requireValidAckSn $ do
-- Spec: wait ŝ = s
waitOnSeenSnapshot $ \snapshot@Snapshot{confirmed} sigs -> do
waitOnSeenSnapshot $ \snapshot sigs -> do
-- Spec: (j,.) ∉ ̂Σ
requireNotSignedYet sigs $ do
let sigs' = Map.insert otherParty snapshotSignature sigs
Expand All @@ -871,8 +874,6 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
let multisig = aggregateInOrder sigs' parties
requireVerifiedMultisignature multisig snapshot $ do
let nextSn = sn + 1
-- Spec: T̂all ← {tx | ∀tx ∈ T̂all : tx ∉ Treq }
let allTxs' = foldr Map.delete allTxs confirmed
Effects [ClientEffect $ SnapshotConfirmed headId snapshot multisig]
`Combined` if isLeader parameters party nextSn && not (null seenTxs)
then
Expand All @@ -889,7 +890,6 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
{ lastSeen = sn
, requested = nextSn
}
, allTxs = allTxs'
}
)
`Combined` Effects [NetworkEffect (ReqSn nextSn (txId <$> seenTxs))]
Expand All @@ -903,7 +903,6 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
, signatures = multisig
}
, seenSnapshot = LastSeenSnapshot sn
, allTxs = allTxs'
}
)
where
Expand Down Expand Up @@ -960,7 +959,7 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
, headId
} = openState

CoordinatedHeadState{seenSnapshot, allTxs, seenTxs} = coordinatedHeadState
CoordinatedHeadState{seenSnapshot, seenTxs} = coordinatedHeadState

HeadParameters{parties} = parameters

Expand Down
19 changes: 1 addition & 18 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ spec =
(Open OpenState{coordinatedHeadState = CoordinatedHeadState{allTxs}}) -> txId t1 `member` allTxs
_ -> False

it "keeps transactions in allTxs given it receives a ReqSn" $ do
it "removes transactions in allTxs given it receives a ReqSn" $ do
let s0 = inOpenState threeParties ledger
t1 = SimpleTx 1 mempty (utxoRef 1)
reqSn = NetworkEvent defaultTTL alice $ ReqSn 1 [1]
Expand All @@ -143,23 +143,6 @@ spec =
s1 <- assertNewState $ update bobEnv ledger sa reqSn

s1 `shouldSatisfy` \case
(Open OpenState{coordinatedHeadState = CoordinatedHeadState{allTxs}}) -> txId t1 `member` allTxs
_ -> False

it "removes transactions from allTxs when included in a acked snapshot" $ do
let t1 = SimpleTx 1 mempty (utxoRef 1)
reqSn = NetworkEvent defaultTTL alice $ ReqSn 1 [1]
snapshot1 = Snapshot 1 (utxoRefs [1]) [1]
ackFrom sk vk = NetworkEvent defaultTTL vk $ AckSn (sign sk snapshot1) 1

sa <- runEvents bobEnv ledger (inOpenState threeParties ledger) $ do
step $ NetworkEvent defaultTTL alice $ ReqTx t1
step reqSn
step (ackFrom carolSk carol)
step (ackFrom aliceSk alice)
step (ackFrom bobSk bob)

sa `shouldSatisfy` \case
(Open OpenState{coordinatedHeadState = CoordinatedHeadState{allTxs}}) -> txId t1 `notMember` allTxs
_ -> False

Expand Down

0 comments on commit 36f2676

Please sign in to comment.