Skip to content

Commit

Permalink
Remove multicast reqSn step on decrementTx (#1536)
Browse files Browse the repository at this point in the history
<!-- Describe your change here -->

This PR reduces the number of network messages in the presence of
decrementTx, by avoiding unnecessary snapshot signature round-trips
between peers.
> Removed **multicast reqSn** step **on** *decrementTx from chain*.

Since it is triggered by a chain observation, we expect/assume everyone
will eventually observe it and continue cooperating.
 
---

<!-- Consider each and tick it off one way or the other -->
* [x] CHANGELOG updated or not needed
* [x] Documentation updated or not needed
* [x] Haddocks updated or not needed
* [x] No new TODOs introduced or explained herafter
  • Loading branch information
ffakenz authored Jul 30, 2024
1 parent e1745f2 commit a2cc96d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 33 deletions.
26 changes: 4 additions & 22 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -828,14 +828,13 @@ onOpenNetworkReqDec env ledger ttl openState decommitTx =
-- __Transition__: 'OpenState' → 'OpenState'
onOpenChainDecrementTx ::
IsTx tx =>
Environment ->
OpenState tx ->
-- | New open state version
SnapshotVersion ->
-- | Outputs removed by the decrement
[TxOutType tx] ->
Outcome tx
onOpenChainDecrementTx Environment{party} openState newVersion distributedTxOuts =
onOpenChainDecrementTx openState newVersion distributedTxOuts =
-- Spec: if outputs(txω) = 𝑈ω
case decommitTx of
Nothing -> Error $ AssertionFailed "decrement observed but no decommit pending"
Expand All @@ -845,28 +844,11 @@ onOpenChainDecrementTx Environment{party} openState newVersion distributedTxOuts
-- v ← v
newState DecommitFinalized{newVersion}
<> cause (ClientEffect $ ServerOutput.DecommitFinalized{headId, decommitTxId = txId tx})
-- Spec: if ŝ = ̅S.s ∧ leader(̅S.s + 1) = i
-- multicast (reqSn, v, ̅S.s + 1, T̂ , txω )
& maybeRequestSnapshot
| otherwise -> Error $ AssertionFailed "decrement not matching pending decommit"
where
maybeRequestSnapshot outcome =
if seenSn == confirmedSn && isLeader parameters party nextSn
then
outcome
<> newState SnapshotRequestDecided{snapshotNumber = nextSn}
<> cause (NetworkEffect $ ReqSn newVersion nextSn (txId <$> localTxs) Nothing)
else outcome

OpenState{parameters, coordinatedHeadState, headId} = openState

CoordinatedHeadState{confirmedSnapshot, localTxs, decommitTx, seenSnapshot} = coordinatedHeadState

seenSn = seenSnapshotNumber seenSnapshot

Snapshot{number = confirmedSn} = getSnapshot confirmedSnapshot
OpenState{coordinatedHeadState, headId} = openState

nextSn = confirmedSn + 1
CoordinatedHeadState{decommitTx} = coordinatedHeadState

isLeader :: HeadParameters -> Party -> SnapshotNumber -> Bool
isLeader HeadParameters{parties} p sn =
Expand Down Expand Up @@ -1119,7 +1101,7 @@ update env ledger st ev = case (st, ev) of
(Open openState@OpenState{headId = ourHeadId}, ChainInput Observation{observedTx = OnDecrementTx{headId, newVersion, distributedOutputs}})
-- TODO: What happens if observed decrement tx get's rolled back?
| ourHeadId == headId ->
onOpenChainDecrementTx env openState newVersion distributedOutputs
onOpenChainDecrementTx openState newVersion distributedOutputs
| otherwise ->
Error NotOurHead{ourHeadId, otherHeadId = headId}
-- Closed
Expand Down
8 changes: 0 additions & 8 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,6 @@ spec =
let reqSn = ReqSn{snapshotVersion = 0, snapshotNumber = 1, transactionIds = [], decommitTx = Just decommitTx'}
s1 `hasEffect` NetworkEffect reqSn

it "emits snapshot onDecrementTx with cleared decommitTx" $ do
let decommitTx = SimpleTx 1 mempty (utxoRef 1)
s0 = inOpenState' threeParties coordinatedHeadState{decommitTx = Just decommitTx}
leaderEnv = aliceEnv
o <- runHeadLogic leaderEnv ledger s0 $ do
step (observeTx OnDecrementTx{headId = testHeadId, newVersion = 1, distributedOutputs = [1]})
o `hasEffect` NetworkEffect (ReqSn 1 1 [] Nothing)

describe "Tracks Transaction Ids" $ do
it "keeps transactions in allTxs given it receives a ReqTx" $ do
let s0 = inOpenState threeParties
Expand Down
3 changes: 0 additions & 3 deletions spec/fig_offchain_prot.tex
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@
\If{$\mathsf{outputs}(\tx_{\omega}) = U_{\omega}$}{
$\tx_{\omega} \gets \bot$ \;
$\hatv \gets v$ \;
\If{$\hats = \bar{\mc S}.s \land \hpLdr(\bar{\mc S}.s + 1) = i$}{
\Multi{} $(\hpRS,\hatv,\bar{\mc S}.s+1,\hatmT, \tx_{\omega})$ \;
}
}
}

Expand Down

0 comments on commit a2cc96d

Please sign in to comment.