Skip to content

Commit

Permalink
Add more comments that order of transaction is important
Browse files Browse the repository at this point in the history
  • Loading branch information
ch1bo committed Aug 15, 2024
1 parent c76d03c commit 40580fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ onOpenNetworkReqTx env ledger st ttl tx =
RequestedSnapshot{} -> True
SeenSnapshot{} -> True

-- NOTE: Order of transactions is important here. See also
-- 'pruneTransactions'.
localTxs' = localTxs <> [tx]

-- | Process a snapshot request ('ReqSn') from party.
Expand Down Expand Up @@ -514,7 +516,10 @@ onOpenNetworkReqSn env ledger st otherParty sv sn requestedTxIds mDecommitTx =
Right u -> cont u

pruneTransactions utxo = do
-- NOTE: Using foldl' is important to apply transacations in the right order.
-- NOTE: Using foldl' is important to apply transacations in the correct
-- order. That is, left-associative as new transactions are first validated
-- and then appended to `localTxs` (when aggregating
-- 'TransactionAppliedToLocalUTxO').
foldl' go ([], utxo) localTxs
where
go (txs, u) tx =
Expand Down Expand Up @@ -1209,7 +1214,9 @@ aggregate st = \case
{ coordinatedHeadState =
coordinatedHeadState
{ localUTxO = newLocalUTxO
, localTxs = localTxs <> [tx]
, -- NOTE: Order of transactions is important here. See also
-- 'pruneTransactions'.
localTxs = localTxs <> [tx]
}
}
where
Expand Down
4 changes: 3 additions & 1 deletion hydra-node/src/Hydra/HeadLogic/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ data CoordinatedHeadState tx = CoordinatedHeadState
-- ^ The latest UTxO resulting from applying 'localTxs' to
-- 'confirmedSnapshot'. Spec: L̂
, localTxs :: [tx]
-- ^ List of transactions applied locally and pending inclusion in a snapshot. Spec: T̂
-- ^ List of transactions applied locally and pending inclusion in a snapshot.
-- Ordering in this list is important as transactions are added in order of
-- application. Spec: T̂
, allTxs :: Map.Map (TxIdType tx) tx
-- ^ Map containing all the transactions ever seen by this node and not yet
-- included in a snapshot. Spec: Tall
Expand Down

0 comments on commit 40580fd

Please sign in to comment.