Skip to content

Commit

Permalink
Don't keep deposit script utxo in local state (#1692)
Browse files Browse the repository at this point in the history
### Why

This is a leftover from off-chain changes needed to implement #199

We kept in the local state a map of UTxO we already observed so this
simplifies the code around that since the observed UTxO is already to be
found in the chain state UTxO. Now we keep a list of `[(TxId, UTxO)]`
where UTxO is just there to check off-chain if the next snapshot is
snapshotting exactly what we saw already as (`utxoToCommit`).

### What

Remove the local map and fields in the observations for
increment/recover and rely completely on observed UTxO (`spendableUTxO`)

---

<!-- 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
v0d1ch authored Oct 10, 2024
2 parents 321167e + e06b36b commit 285de0c
Show file tree
Hide file tree
Showing 23 changed files with 63,356 additions and 37,609 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ changes.
Important to note is that on-chain security is not implemented and hydra-node in this
state is not releasable!
Missing off-chain items to implement as a series of next PR's:
- Use the observed UTxO to construct increment/recover
- Add documentation to explain the feature
- Implement tests scenarios outlined in the [incremental-commit] (https://github.com/cardano-scaling/hydra/issues/199) issue
- Remove Commit client input since it is unused
Expand Down
8 changes: 6 additions & 2 deletions hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ resolve k = Map.lookup k . toMap
pairs :: UTxO' out -> [(TxIn, out)]
pairs = Map.toList . toMap

-- | Find first 'UTxO' which satisfies given predicate.
-- | Find first 'UTxO' using the output in predicate.
find :: (out -> Bool) -> UTxO' out -> Maybe (TxIn, out)
find fn utxo = List.find (fn . snd) $ pairs utxo
find fn = findBy (fn . snd)

-- | Find first 'UTxO' using both input and output in predicate.
findBy :: ((TxIn, out) -> Bool) -> UTxO' out -> Maybe (TxIn, out)
findBy fn utxo = List.find fn $ pairs utxo

-- | Filter UTxO to only include 'out's satisfying given predicate.
filter :: (out -> Bool) -> UTxO' out -> UTxO' out
Expand Down
4 changes: 2 additions & 2 deletions hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ singlePartyCommitsScriptBlueprint tracer workDir node hydraScriptsTxId =
waitFor hydraTracer 10 [n1] $
output "CommitApproved" ["headId" .= headId, "utxoToCommit" .= scriptUTxO']
waitFor hydraTracer 10 [n1] $
output "CommitFinalized" ["headId" .= headId, "utxo" .= scriptUTxO', "theDeposit" .= getTxId (getTxBody tx)]
output "CommitFinalized" ["headId" .= headId, "theDeposit" .= getTxId (getTxBody tx)]

send n1 $ input "GetUTxO" []

Expand Down Expand Up @@ -731,7 +731,7 @@ canCommit tracer workDir node hydraScriptsTxId =
waitFor hydraTracer 10 [n1] $
output "CommitApproved" ["headId" .= headId, "utxoToCommit" .= commitUTxO]
waitFor hydraTracer 10 [n1] $
output "CommitFinalized" ["headId" .= headId, "utxo" .= commitUTxO, "theDeposit" .= getTxId (getTxBody tx)]
output "CommitFinalized" ["headId" .= headId, "theDeposit" .= getTxId (getTxBody tx)]

send n1 $ input "GetUTxO" []

Expand Down
17,393 changes: 17,393 additions & 0 deletions hydra-node/golden/ReasonablySized (ServerOutput (Tx ConwayEra)).json

Large diffs are not rendered by default.

Loading

0 comments on commit 285de0c

Please sign in to comment.