Skip to content

Commit

Permalink
Use Map for the local state of deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Oct 10, 2024
1 parent c3d22ac commit e06b36b
Show file tree
Hide file tree
Showing 6 changed files with 22,644 additions and 22,311 deletions.
1,601 changes: 1,021 additions & 580 deletions hydra-node/golden/ReasonablySized (TimedServerOutput (Tx ConwayEra)).json

Large diffs are not rendered by default.

19,467 changes: 9,714 additions & 9,753 deletions hydra-node/golden/ServerOutput/CommandFailed.json

Large diffs are not rendered by default.

23,861 changes: 11,896 additions & 11,965 deletions hydra-node/golden/StateChanged/CommitRecorded.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ onOpenNetworkAckSn Environment{party} openState otherParty snapshotSignature sn
else outcome

maybePostIncrementTx snapshot@Snapshot{utxoToCommit} signatures outcome =
case find (\(_, depositUTxO) -> Just depositUTxO == utxoToCommit) pendingDeposits of
case find (\(_, depositUTxO) -> Just depositUTxO == utxoToCommit) (Map.assocs pendingDeposits) of
Just (depositTxId, depositUTxO) ->
outcome
<> causes
Expand Down Expand Up @@ -740,16 +740,16 @@ onOpenClientRecover ::
TxIdType tx ->
Outcome tx
onOpenClientRecover headId currentSlot coordinatedHeadState recoverTxId =
case find (\(depositTxId, _) -> depositTxId == recoverTxId) pendingDeposits of
case Map.lookup recoverTxId pendingDeposits of
Nothing ->
Error $ RequireFailed RecoverNotMatchingDeposit
Just (depositTxId', _) ->
Just _ ->
causes
[ OnChainEffect
{ postChainTx =
RecoverTx
{ headId
, recoverTxId = depositTxId'
, recoverTxId = recoverTxId
, deadline = currentSlot
}
}
Expand Down Expand Up @@ -934,7 +934,7 @@ onOpenChainDepositTx headId env st deposited depositTxId _deadline =
-- TODO: We should check for deadline and only request snapshots that have deadline further in the future so
-- we don't end up with a snapshot that is already outdated.
waitOnUnresolvedDecommit $
newState CommitRecorded{pendingDeposits = [(depositTxId, deposited)], newLocalUTxO = localUTxO <> deposited}
newState CommitRecorded{pendingDeposits = Map.singleton depositTxId deposited, newLocalUTxO = localUTxO <> deposited}
<> cause (ClientEffect $ ServerOutput.CommitRecorded{headId, utxoToCommit = deposited, pendingDeposit = depositTxId})
<> if not snapshotInFlight && isLeader parameters party nextSn
then
Expand Down Expand Up @@ -969,9 +969,9 @@ onOpenChainRecoverTx ::
TxIdType tx ->
Outcome tx
onOpenChainRecoverTx headId st recoveredTxId =
case find (\(depositTxId, _) -> depositTxId == recoveredTxId) pendingDeposits of
case Map.lookup recoveredTxId pendingDeposits of
Nothing -> Error $ RequireFailed RecoverNotMatchingDeposit
Just (_, recoveredUTxO) ->
Just recoveredUTxO ->
newState CommitRecovered{recoveredUTxO, newLocalUTxO = localUTxO `withoutUTxO` recoveredUTxO, recoveredTxId}
<> cause
( ClientEffect
Expand Down Expand Up @@ -1000,7 +1000,7 @@ onOpenChainIncrementTx ::
TxIdType tx ->
Outcome tx
onOpenChainIncrementTx openState newVersion depositTxId =
case find (\(depositTxId', _) -> depositTxId' == depositTxId) pendingDeposits of
case Map.lookup depositTxId pendingDeposits of
Nothing -> Error $ AssertionFailed $ "Increment not matching pending deposit! TxId: " <> show depositTxId
Just _ ->
newState CommitFinalized{newVersion, depositTxId}
Expand Down Expand Up @@ -1408,7 +1408,7 @@ aggregate st = \case
{ coordinatedHeadState =
coordinatedHeadState
{ localUTxO = newLocalUTxO
, pendingDeposits = Map.toList . Map.fromList $ pendingDeposits <> existingDeposits
, pendingDeposits = pendingDeposits <> existingDeposits
}
}
where
Expand All @@ -1422,7 +1422,7 @@ aggregate st = \case
{ coordinatedHeadState =
coordinatedHeadState
{ localUTxO = newLocalUTxO
, pendingDeposits = filter (\(depositTxId, _) -> depositTxId /= recoveredTxId) existingDeposits
, pendingDeposits = Map.delete recoveredTxId existingDeposits
}
}
where
Expand Down Expand Up @@ -1595,7 +1595,7 @@ aggregate st = \case
os
{ coordinatedHeadState =
coordinatedHeadState
{ pendingDeposits = filter (\(depositTxId', _) -> depositTxId' /= depositTxId) existingDeposits
{ pendingDeposits = Map.delete depositTxId existingDeposits
, version = newVersion
}
}
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/HeadLogic/Outcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data StateChanged tx
{ tx :: tx
, newLocalUTxO :: UTxOType tx
}
| CommitRecorded {pendingDeposits :: [(TxIdType tx, UTxOType tx)], newLocalUTxO :: UTxOType tx}
| CommitRecorded {pendingDeposits :: Map (TxIdType tx) (UTxOType tx), newLocalUTxO :: UTxOType tx}
| CommitRecovered {recoveredUTxO :: UTxOType tx, newLocalUTxO :: UTxOType tx, recoveredTxId :: TxIdType tx}
| DecommitRecorded {decommitTx :: tx, newLocalUTxO :: UTxOType tx}
| SnapshotRequestDecided {snapshotNumber :: SnapshotNumber}
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/HeadLogic/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ data CoordinatedHeadState tx = CoordinatedHeadState
-- ^ The latest confirmed snapshot. Spec: S̅
, seenSnapshot :: SeenSnapshot tx
-- ^ Last seen snapshot and signatures accumulator. Spec: Û, ŝ and Σ̂
, pendingDeposits :: [(TxIdType tx, UTxOType tx)]
, pendingDeposits :: Map (TxIdType tx) (UTxOType tx)
-- ^ Pending deposit UTxO. Spec: Uα
, decommitTx :: Maybe tx
-- ^ Pending decommit transaction. Spec: txω
Expand Down

0 comments on commit e06b36b

Please sign in to comment.