Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental decommit #1344

Merged
merged 303 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
303 commits
Select commit Hold shift + click to select a range
c3b28ca
TxTrace: increase number of positive actions
ch1bo Apr 11, 2024
6b7679b
TxTrace: Model Augmented snapshots
ch1bo Apr 11, 2024
5b460f8
TxTrace: identify expected failing fanout
ch1bo Apr 11, 2024
1de5780
TxTrace: Refactor into a short-cutting PostconditionM'
ch1bo Apr 12, 2024
15936e8
TxTrace: keep construction errors in TxResult
ch1bo Apr 17, 2024
1dbacce
Fix the failing close with initial snapshot
v0d1ch Apr 25, 2024
904981f
TxTrace: Add decommit utxo to the snapshot
v0d1ch Apr 25, 2024
c374db1
TxTrace: re-sign the decommit snapshot
v0d1ch May 10, 2024
618abf2
TxTrace: Do not remove decommit outputs
v0d1ch May 10, 2024
65961aa
Fix golden files
v0d1ch May 13, 2024
af12bb8
Simplify getting the snapshotNumber in closeTx
v0d1ch May 14, 2024
bbc528a
TxTrace: Produce decommit snapshots directly
v0d1ch May 14, 2024
9c15140
TxTrace: Add decommit value to the head UTxO
v0d1ch May 14, 2024
5303a82
Add utxoToDecommit to FanoutTx
v0d1ch May 15, 2024
ce85177
TxTrace: Not add value to make decrement pass
ch1bo May 16, 2024
481bcfd
TxTrace: Remove Augmented Snapshot and alter the model
v0d1ch May 20, 2024
6e8c2da
TxTrace: Add modelUTxO to the snapshot
v0d1ch May 21, 2024
b5aac16
TxTrace: Produce a valid model without accounting for decrements
v0d1ch May 21, 2024
93aac56
TxTrace: Track decommit UTxO in ModelUTxO
v0d1ch May 21, 2024
5a00323
TxTrace: Remove utxoTeDecrement from the Model
v0d1ch May 22, 2024
2b13a59
TxTrace: Generate Decrement and Contest actions using existing head utxo
v0d1ch May 22, 2024
334044f
TxTrace: If there is no utxo in the snapshot don't populate
v0d1ch May 22, 2024
9e7826a
TxTrace: precondition checks
v0d1ch May 22, 2024
247b566
Rebase: fix compilation
v0d1ch May 23, 2024
fb299c1
TxTrace: Remove validFailingActions and revert conditions in the
v0d1ch May 23, 2024
c3ada87
TxTrace: Generate separatelly values for utxo and utxo to decommit
v0d1ch May 23, 2024
cd44d69
Fix bug related to intial utxo hash for the decommit values
v0d1ch May 23, 2024
17bf331
TxTrace: Re-add validFailingAction and introduce more arbitrary values
v0d1ch May 23, 2024
b9c2f77
Refactor performTx and TxResult + some documentation
ch1bo May 23, 2024
896ddb9
Remove some preconditions to see more radical failures
ch1bo May 23, 2024
cc63e06
Add more information on expected validation failures
ch1bo May 23, 2024
4c752c5
Fix starting real world utxo to included "A" equivalent
ch1bo May 23, 2024
2090ede
Exercise more negative actions (by just trying all which don't fulfill
ch1bo May 23, 2024
77eb248
Fix how the model snapshot is interpreted into a confirmed in case of…
ffakenz May 24, 2024
8a80d74
Discard decrements that attempts to take more value than it is in the…
ffakenz May 24, 2024
3408d69
Increase frequency of negative Decrement actions being produced
ffakenz May 24, 2024
462add8
Add more interested cases to cover
ffakenz May 24, 2024
e682c59
Discard Stops
ffakenz May 24, 2024
57b6526
Add realWorldModelUTxO preserves addition property
ffakenz May 24, 2024
fbee521
TxTrace: Alter the ModelUTxO to use Map instead of Set
v0d1ch May 27, 2024
778bcb1
TxTrace: initially start with some funds
v0d1ch May 27, 2024
e00d9e8
Slightly expand the ModelUTxO alphabet and exercise more decommits
ch1bo May 28, 2024
b5695ab
Lax the precondition for Decrement
ffakenz May 28, 2024
3b20dc8
WIP
v0d1ch May 28, 2024
53d3d89
Close Mutation: Set utxoToDecommit to some value
v0d1ch May 29, 2024
4eab11d
Fanout Mutation: Set utxoToDecommit in the fanout snapshot
v0d1ch May 29, 2024
2dd3b0e
Fanout Mutation: Alter the fanout redeemer
v0d1ch May 29, 2024
a926632
Remove PartySignatureVerificationFailed since it is not used
v0d1ch May 29, 2024
dad05a9
Contest Mutation: Add utxoToDecommit to the contest snapshot
v0d1ch May 29, 2024
048458d
Optimize datum extraction to reduce execution costs
v0d1ch May 30, 2024
b2561a7
Reject decrements with empty utxo to decommit
ffakenz May 30, 2024
28addcb
Improve BehaviorSpec
v0d1ch May 30, 2024
b11277b
TxSpec: Mutate working decrement snapshots
v0d1ch May 30, 2024
f1a1af1
TxSpec: Assert valid sequence of actions work
v0d1ch Jun 3, 2024
6b68ef9
TxSpec: WIP
v0d1ch Jun 3, 2024
4d80d8b
Enhance interesting transaction traces
ffakenz Jun 4, 2024
dcc112f
TxSpec: Mutate snapshots and utxo to produce expected errors
v0d1ch Jun 3, 2024
2100487
Dry how to generate model snapshots
ffakenz Jun 4, 2024
b2082d0
Minor dry on balanceUTxOInHead
ffakenz Jun 4, 2024
4a8bdd6
TxSpec: Make sequence of valid txs work
v0d1ch Jun 5, 2024
f5d9c9c
TxSpec: Re-enable all error cases
v0d1ch Jun 5, 2024
dd3a29c
TxSpec: No need for property tests and suchThat
v0d1ch Jun 5, 2024
070d221
TxSpec: Remove labels as they are not very useful
v0d1ch Jun 5, 2024
8b48552
TxSpec: Simplify and do property checks in individual txs
v0d1ch Jun 5, 2024
41c3c7e
TxSpec: Refactor actions
v0d1ch Jun 5, 2024
c96b50a
Distinguish between missing snapshot and null snapshot errors
locallycompact Jun 5, 2024
4960b0a
Ignore decrements without something to decommit
ffakenz Jun 6, 2024
4d7d352
Remove keys with 0 values from someUTxOToDecrement
ffakenz Jun 6, 2024
0875897
Keep track of decommitUTxOInHead
ffakenz Jun 6, 2024
e743b49
Apply same ignore logic to contest
ffakenz Jun 6, 2024
f41ed1a
Enhance hasManyDecommits rule
ffakenz Jun 6, 2024
54de73e
Remove the has many decommits coverage for close and fanout
ffakenz Jun 6, 2024
0f31a74
TxSpec: Test multiple chained actions with altered snapshots
v0d1ch Jun 6, 2024
8fc4cbc
TxSpec: Build combinators
v0d1ch Jun 6, 2024
c7a080c
TxSpec: Use Bool instead of Property
v0d1ch Jun 7, 2024
20aa483
Fix LoggingSpec test
v0d1ch Jun 7, 2024
30b78e9
Fix StateSpec test by not generating empty commits
v0d1ch Jun 10, 2024
884cd59
Fix golden files
v0d1ch Jun 10, 2024
7d3f850
Plutus scripts
v0d1ch Jun 11, 2024
a90c318
Format
v0d1ch Jun 11, 2024
80fa4b2
Remove pretty-simple
v0d1ch Jun 11, 2024
5bc806b
Make splitUTxO pure
v0d1ch Jun 11, 2024
aafe4a5
Use utxoToDecommit in a snapshot in DirectChainSpec
v0d1ch Jun 11, 2024
d1bfd9b
Delete quickstart
v0d1ch Jun 12, 2024
0e0a497
Improve splitUTxO
v0d1ch Jun 12, 2024
c6e42d9
Add Decrement transaction to tx-cost benchmark
v0d1ch Jun 12, 2024
c141120
Use something to decommit in the snapshot DirectChainSpec
v0d1ch Jun 12, 2024
53d7312
Add splitUTxO property test
v0d1ch Jun 12, 2024
a81c155
Arbitrary Snapshot should have something to decommit
v0d1ch Jun 14, 2024
4a54d9b
Document Snapshot CDDL
v0d1ch Jun 14, 2024
0779ef7
Add changelog entry
v0d1ch Jun 16, 2024
93ed6d6
Move decommit tutorial to how-to section
ffakenz Jun 17, 2024
1b8606c
Expose a bug when decommitting
v0d1ch Jun 17, 2024
b1e7766
Fix how-to tutorial: do not sign decommit-tx with alice key
ffakenz Jun 18, 2024
db3a5c6
Add Version: Introduce version to the HeadState
v0d1ch Jun 18, 2024
e38ed8f
Add Version: Introduce version to Snapshot
v0d1ch Jun 18, 2024
cd88730
Add Version: Require version in local state and confirmed snapshot to
v0d1ch Jun 19, 2024
42a0792
Add Version: Start with version 0 and only bump on observed decommit
v0d1ch Jun 19, 2024
0cff14f
Add Version: Add missing version in Snapshot toJSON and toCBOR
v0d1ch Jun 19, 2024
29c8d4c
Add Version: Default to version 0 in tests to pass validation
v0d1ch Jun 19, 2024
7b8dfe3
Add Version: Remove required version match check
v0d1ch Jun 19, 2024
2c0bc18
Add Version: Model the snapshot version into TxTrace
v0d1ch Jun 19, 2024
eb02a49
Add Version: Bump execution costs for now
v0d1ch Jun 19, 2024
047a5a7
Add Version: Add off-chain version to CloseTx
v0d1ch Jun 19, 2024
ad01998
Add Version: Add closeUTxOToDecommit to CloseTx
v0d1ch Jun 20, 2024
87beeaf
Add Version: Add utxoToDecommitHash to Close redeemer
v0d1ch Jun 20, 2024
3d2ab14
Add Version: Add version to the Closed off-chain state
v0d1ch Jun 20, 2024
ffa3c14
Add Version: Mutate number of decommit outputs on Fanout
v0d1ch Jun 21, 2024
2b5e394
Add Version: If we never update the version all transitions should still
v0d1ch Jun 21, 2024
8b78455
Introduced newtype for snapshot version instead of plain natural.
ffakenz Jun 22, 2024
4287345
Move snapshot version into coordinated head state in open state
ffakenz Jun 22, 2024
0923b85
Minor fix on how the balance utxo occurs in TxTraceSpec
ffakenz Jun 22, 2024
b7d001c
Add Version: Optimize head contract using PlutusTx.Plugin
v0d1ch Jun 22, 2024
9175bb2
Add Version: Introduce optimisations to other contracts
v0d1ch Jun 22, 2024
7828311
Remove unnecessary long comment from Head script
ffakenz Jun 22, 2024
c7bd354
Introduce new HeadError for IncorrectVersion.
ffakenz Jun 22, 2024
afbd944
Add mutation check over decrement to very it increases the version nu…
ffakenz Jun 23, 2024
bdec5fb
Add Version: Make version check in close more readable
v0d1ch Jun 24, 2024
b46ce8a
Add Version: Fix the decommit mutation for lucky seed
v0d1ch Jun 24, 2024
5414955
Add Version: Make Close isHealthy check pass
v0d1ch Jun 24, 2024
a5e2f73
Add minor doc comments
ffakenz Jun 24, 2024
1af4984
Propose new head logic specs
ffakenz Jun 24, 2024
420823a
Fix logging spec errors
v0d1ch Jun 25, 2024
09ac25c
Add e2e spec to check: can close with a decommit in flight
ffakenz Jun 25, 2024
741ea44
Reorder check close in head script so mutations fail for the right re…
ffakenz Jun 25, 2024
12641ef
Minor refactor: split close mutations according to their type
ffakenz Jun 25, 2024
77b6fc1
Refactor CloseCurrent more - All Close mutations pass now
v0d1ch Jun 25, 2024
b93c088
Draft close outdated mutation specs
ffakenz Jun 25, 2024
68f54c3
Minor refactor on close mutations
ffakenz Jun 26, 2024
b33fca0
Fix checkClose for the version check
v0d1ch Jun 26, 2024
c933440
Fix StateSpec for decommit and close
v0d1ch Jun 26, 2024
cc4e4ec
Fix TxSpec for chained transactions
v0d1ch Jun 26, 2024
e4bd4d2
Fix "can only contest once" with proper version
v0d1ch Jun 26, 2024
7d8fda3
Fix the golden files
v0d1ch Jun 26, 2024
8cdcb65
Improve CloseOutdated mutations
v0d1ch Jun 26, 2024
251dbcb
CloseOutdated: Change decommit hash in the redeemer
v0d1ch Jun 27, 2024
eaa708b
CloseOutdated: Change the signatures in the redeemer
v0d1ch Jun 27, 2024
37752b0
Refactor close current to follow the spec more
ffakenz Jun 27, 2024
5c2ce08
Remove unrelevant mutation from CloseCurrent
v0d1ch Jun 27, 2024
0ea9bd0
Add check to verify the version is preserved btw open and close states
ffakenz Jun 28, 2024
431613c
Gain some sanity
v0d1ch Jun 28, 2024
93bfad5
Finish mutation test for outdated close
ffakenz Jun 28, 2024
7838ed5
Introduce contest current mutations
ffakenz Jun 28, 2024
2391ad0
Add contest redeemer type
ffakenz Jun 28, 2024
bd3e4eb
Add some notes to explain outstandings in head validator
v0d1ch Jul 1, 2024
123be21
Add snapshot version to ReqSn
ffakenz Jul 1, 2024
b287fd4
Minor fix to direct chain spec
ffakenz Jul 1, 2024
70bee7d
Align on reqDec to spec
ffakenz Jul 1, 2024
79e9277
Align on reqSn to spec
ffakenz Jul 1, 2024
6082577
Align on reqSn to spec
ffakenz Jul 1, 2024
6d13885
Align reqSn with spec
ffakenz Jul 1, 2024
866088a
Add "OffChain" version to TxTrace
v0d1ch Jul 1, 2024
5933015
TxTrace: Bump snapshot version after successful decrement
v0d1ch Jul 2, 2024
3c03cb3
Align on decrementTx from chain with spec
ffakenz Jul 2, 2024
985725d
Fix initial snapshot close in mock chain.
v0d1ch Jul 2, 2024
3417b56
Spot gaps btw onOpenNetworkAckSn and spec
ffakenz Jul 2, 2024
b20af26
Add spec comments onOpenClientClose according to latest spec changes
ffakenz Jul 2, 2024
d2ca841
Spec: revert unnecessary change in overview.tex
v0d1ch Jul 2, 2024
6a749e6
Refactor common healthy fixtures
locallycompact Jul 2, 2024
c8dce39
Match on snapshot number being zero to detemine if we are in initial
v0d1ch Jul 3, 2024
859a0f0
Make CloseInitial tx healthy again
v0d1ch Jul 3, 2024
f1b61fe
Make CloseOutdated work again
v0d1ch Jul 3, 2024
3254676
Format
v0d1ch Jul 3, 2024
f68ecca
Align offchain protocol to spec and documment missing gaps
ffakenz Jul 3, 2024
33597d2
Spec: use m' instead of n for the fanout redeemer outputs
v0d1ch Jul 3, 2024
692e805
Fanout mutations
v0d1ch Jul 3, 2024
2e9014b
Fix the logs schema errors
v0d1ch Jul 3, 2024
154b3a9
Fix TxTraceSpec
v0d1ch Jul 3, 2024
126af25
Fix the scripts
v0d1ch Jul 3, 2024
24e6146
Spec: Update contestTx.pdf
v0d1ch Jul 4, 2024
d7c9886
Align on close and context tx to spec and documment missing gaps
ffakenz Jul 4, 2024
b6115ee
Spec: Update fanoutTx.pdf
v0d1ch Jul 4, 2024
687dd0f
Spec: Small fix for the number of decommit outputs in fanout tx
v0d1ch Jul 4, 2024
41e53d4
E2E: Add one more decommit to test multiple decommits
v0d1ch Jul 4, 2024
3624f47
Update submodule conway.genesis files
v0d1ch Jul 4, 2024
739e44b
Improve decommit tutorial instructions
v0d1ch Jul 4, 2024
7b0077b
Comment out failing coverage tests
v0d1ch Jul 8, 2024
6ddfd4e
Not update cardano-configurations submodule
ch1bo Jul 9, 2024
b5279c8
Drop unused incrementTx figure from spec
ch1bo Jul 9, 2024
60bb84e
Revert fanout m' renaming
ch1bo Jul 9, 2024
bcd1c88
Rename tx cost benchmark decommit -> decrement
ch1bo Jul 9, 2024
6bcd3c9
Don't use splitUTxO and use version 0 in tx-cost benchmark
ch1bo Jul 9, 2024
9a1be57
Move sequence diagram into dedicated docs page
ch1bo Jul 10, 2024
0eb0b65
Must not change version in close/contest
ch1bo Jul 10, 2024
e49d361
Limit size of generated contesters to reasonable values
ch1bo Jul 10, 2024
61055d6
Broaden version mutation for collect
ch1bo Jul 10, 2024
4552483
Broaden version mutation for decrement
ch1bo Jul 10, 2024
8ae30ee
Introduce CloseRedeemer and ContestRedeemer
ch1bo Jul 10, 2024
a19b096
Use redeemers in tx construction
ch1bo Jul 10, 2024
394214c
Use redeemers in mutation tests
ch1bo Jul 10, 2024
be27ff5
Remove a now invalid mutation test
ch1bo Jul 10, 2024
7ecd329
Fix close transaction to use last open state version in output
ch1bo Jul 11, 2024
35addf6
Add newVersion to OnDecrementTx and fix off-chain protocol
ch1bo Jul 11, 2024
844e3b5
Observe distributed outputs from decrementTx
ch1bo Jul 11, 2024
4a5b24d
Remove snapshot number from open state and introduce sub-types
ch1bo Jul 11, 2024
6dc6e1e
Do not expect decrements with snapshot number 0 to fail
ch1bo Jul 11, 2024
7a5b00f
Use sub-types for decrement/close in head validator
ch1bo Jul 11, 2024
5e41a83
Remove redundant strictness annotations in Head script
ch1bo Jul 11, 2024
c0628a0
Rename and re-number head errors
ch1bo Jul 11, 2024
7da3f4b
Emit snapshot with cleared decommitTx onDecrementTx
ch1bo Jul 11, 2024
afe1b05
Sub-type closedDatum and make deltaHash a Maybe
ch1bo Jul 11, 2024
2462602
Re-order Snapshot fields and align signable representation with spec
ch1bo Jul 12, 2024
dc028d8
Add TODO about preventing empty decommits
ch1bo Jul 12, 2024
3d409c8
Change Decommit server outputs to be more in-line with TxValid/TxInvalid
ch1bo Jul 12, 2024
7ba100e
Regenerate golden files and make XXX comments mention Spec instead
ch1bo Jul 15, 2024
dcc8d9f
Fix contest off-chain
ch1bo Jul 15, 2024
4aa7f38
Document and re-order arguments of 'decrement'
ch1bo Jul 15, 2024
a78f52f
Remove unused Semigroup and Monoid of UTxOHash
ch1bo Jul 15, 2024
ecca46b
Simplify decommit how-to
ch1bo Jul 16, 2024
de95c54
Expand changelog entry
ch1bo Jul 16, 2024
4f99631
Remove decommitRequester
ch1bo Jul 16, 2024
6ed7427
Update haddocks and drop a redundant test
ch1bo Jul 16, 2024
b9a6d8a
Check decommit request against local ledger
ch1bo Jul 16, 2024
029fce2
Only request snapshot on ReqDec if no snapshot in flight
ch1bo Jul 16, 2024
3c10d26
Resolve some spec gap comments in head logic
ch1bo Jul 16, 2024
e81177d
Make AckSn processing emit a PartySignedSnapshot
ch1bo Jul 16, 2024
513ea30
Align HeadLogic closer with spec
ch1bo Jul 16, 2024
fdaf068
Combine requires when processing a ReqSn
ch1bo Jul 16, 2024
f7f6a4d
Add DecommitRecorded and DecommitFinalized to genStateChanged
ch1bo Jul 16, 2024
5192faf
Remove unused SnapshotOutcome data types (and module)
ch1bo Jul 16, 2024
a8541a6
Consolidate Wait outcomes for decommit request processing
ch1bo Jul 16, 2024
ab6fb21
Not assert starting state in HeadLogicSpec
ch1bo Jul 16, 2024
bfb7485
Remove redundant language pragmas
ch1bo Jul 16, 2024
a807ec0
Refactor CloseTx/close/closeTx and add docs to openVersion
ch1bo Jul 16, 2024
ec16356
Also refactore ContestTx/contest/contestTx to match close
ch1bo Jul 16, 2024
e9c2fb7
Also refactor DecrementTx/decrement/decrementTx to take a ConfirmedSn…
ch1bo Jul 16, 2024
627b0d2
Untangle some healthyXXX functions
ch1bo Jul 16, 2024
9fdc649
Add AssertionFailed logic error outcome and use it onDecrementTx
ch1bo Jul 17, 2024
2bbdc8a
Review and unmark red on-chain spec areas
ch1bo Jul 17, 2024
2601312
Clear gaps and red markup in offchain
ch1bo Jul 17, 2024
c813a88
Fix TxTraceSpec by modelling snapshot versions
ch1bo Jul 17, 2024
8243c8f
Model: genPayment to any hydra party
ch1bo Jul 18, 2024
2138af9
Revert changes on ObserveConfirmedTx
ch1bo Jul 18, 2024
b6d5c49
Small refactor in genOpenActions
ch1bo Jul 18, 2024
476de1d
Remove redundant e2e tests
ch1bo Jul 18, 2024
fca6839
Simplify aliceAddress calculation
ch1bo Jul 18, 2024
cb267c2
Simplify decommit e2e scenario to only one decommit
ch1bo Jul 18, 2024
ed02fdb
Further reduce complexity of decommit e2e test
ch1bo Jul 18, 2024
0536b8d
Rename a mutation enumeration to clarify
ch1bo Jul 18, 2024
33c0cbc
Drop redundant test in TxSpec
ch1bo Jul 19, 2024
d8b9bf7
Regenerate plutus scripts after rebase
ch1bo Jul 19, 2024
f261d37
Update genDecrement to also have sometimes empty commits
ch1bo Jul 19, 2024
6d81570
Fix warnings
ch1bo Jul 19, 2024
0915b5e
Property test and implement splitUTxO differently
ch1bo Jul 20, 2024
839e77f
Remove redundant Fanout mutation tests
ch1bo Jul 20, 2024
df51ee9
Start tuning TxTraceSpec
ch1bo Jul 20, 2024
e2867a5
Reduce discards of fanout
ch1bo Jul 20, 2024
98d950a
Fix logs.yaml with forgotten OnDecrementTx
ch1bo Jul 22, 2024
b4e3b33
Make model aware of outdated snapshots
ch1bo Jul 23, 2024
a70a781
Remove/demote TODO and XXXs
ch1bo Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ changes.
- Removed the check that prevented committing UTxOs from an internal `hydra-node` wallet.
- `SpendingNodeUtxoForbidden` error was removed.

- Add capability to move UTxO out of an open Head to the Cardano main chain:
- Submitting a decommit transaction to `POST /decommit` or as `Decommit` command through websocket, requests removal of this transactions' outputs from the head.
- When successful, `DecommitApproved` and `DecommitFinalized` indicate that all outputs are made available on the layer one.
- Invalid transactions are explained through a `DecommitInvalid` server output.

- Change `--start-chain-from` to always use the newer point when also a head state is known.

- Moved several pages from "core concepts" into the user manual and developer docs to futher improve user journey.
Expand Down
43 changes: 43 additions & 0 deletions docs/docs/dev/protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Protocol

Additional implementation-specific documentation for the Hydra Head protocol and extensions like incremental decommits.

### Incremental Decommits

```mermaid
sequenceDiagram
Alice->>HeadLogic: Decommit (decTx)
HeadLogic->>HeadLogic: canApply decTx
par broadcast
HeadLogic->>HeadLogic: ReqDec decTx
and
HeadLogic->>Node B: ReqDec decTx
end
HeadLogic -->> Alice: DecommitRequested
par Alice isLeader
HeadLogic->>HeadLogic: ReqSn decTx
and
HeadLogic->>Node B: ReqSn decTx
end
HeadLogic->>HeadLogic: canApply decTx, decUTxO = outputs(decTx)
HeadLogic->>HeadLogic: sig = sign snapshot incl. decUTxO
par broadcast
HeadLogic->>HeadLogic: AckSn sig
and
HeadLogic->>Node B: AckSn sig
end
Node B->>HeadLogic: AckSn sig
HeadLogic -->> Alice: SnapshotConfirmed
HeadLogic -->> Alice: DecommitApproved
HeadLogic ->> Chain: DecrementTx snapshot sig
Chain ->> HeadLogic: OnDecrementTx
HeadLogic -->> Alice: DecommitFinalized
```
2 changes: 1 addition & 1 deletion docs/docs/how-to/event-sinks-and-sources.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: 5
---

# Extend the node with event source and sinks
Expand Down
115 changes: 115 additions & 0 deletions docs/docs/how-to/incremental-decommit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
sidebar_position: 3
---

# Decommit funds

To take out some `UTxO` present in an open head and send it back to the layer one, you need to do a so-called `decommit`.

This how-to assumes that we are in a similar situation as in the [Getting Started](../getting-started) or [Testnet tutorial](../tutorial). Depending on who owns something in your head, you might need to update the instructions of this tutorial. In our example we decommit funds owned by Alice from their address:

```shell
export WALLET_SK=credentials/alice-funds.sk
export WALLET_ADDR=addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z
```

First, we need to find out which `UTxO` we can spend using our address:

```shell
curl localhost:4001/snapshot/utxo \
| jq "with_entries(select(.value.address == \"${WALLET_ADDR}\"))" \
> utxo.json
```

<details>
<summary> Example output</summary>

```json
{
"f6b004be1cf95dbd3d0abc3daceac40ef6401e502972a919e5e52564b9f5740b#0": {
"address": "addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z",
"datum": null,
"datumhash": null,
"inlineDatum": null,
"referenceScript": null,
"value": {
"lovelace": 50000000
}
},
"f6b004be1cf95dbd3d0abc3daceac40ef6401e502972a919e5e52564b9f5740b#1": {
"address": "addr_test1vp5cxztpc6hep9ds7fjgmle3l225tk8ske3rmwr9adu0m6qchmx5z",
"datum": null,
"datumhash": null,
"inlineDatum": null,
"referenceScript": null,
"value": {
"lovelace": 50000000
}
}
}
```

</details>

Now, the `decommit` command requires us to build a transaction that proves we can spend what we want to decommit. The outputs of this transaction will be the outputs that are also going to be made available on the main chain.

For example, to spend the first UTxO queried above in a transaction sending the same value to Alice's key (so she can spend it on the layer one later):

```shell
LOVELACE=$(jq -r 'to_entries[0].value.value.lovelace' < utxo.json)
cardano-cli transaction build-raw \
--tx-in $(jq -r 'to_entries[0].key' < utxo.json) \
--tx-out ${WALLET_ADDR}+${LOVELACE} \
--fee 0 \
--out-file decommit.json
```

You can inspect the transaction with

```shell
cardano-cli transaction view --tx-file decommit.json
```

As the transaction spends from Alices funds in the Hydra head, we also need to
sign it with her key:

```shell
cardano-cli transaction sign \
--tx-file decommit.json \
--signing-key-file ${WALLET_SK} \
--out-file alice-decommit-tx-signed.json
```

With the signed decommit transaction, now we can submit it to the `/decommit` endpoint:

```shell
curl -X POST 127.0.0.1:4001/decommit \
--data @alice-decommit-tx-signed.json
```

<details>
<summary>Alternative using websocket</summary>

We can also submit a `Decommit` client input using a websocket:
```shell
cat alice-decommit-tx-signed.json \
| jq -c '{tag: "Decommit", decommitTx: .}' \
| websocat "ws://127.0.0.1:4001?history=no"
```

</details>

If you haven't already, open a websocket session using `websocat ws://0.0.0.0:4001` now.

In the message history you will see a `DecommitRequested` message which
indicates a decommit is requested.

After some time, a `DecommitFinalized` can be observed which concludes the decommit process and after which the funds are available on the layer one.

To confirm, you can query the funds of the wallet on the layer one from a `cardano-node`:

```shell
cardano-cli query utxo \
--address ${WALLET_ADDR} \
--output-json | jq
```
2 changes: 1 addition & 1 deletion docs/docs/how-to/operating-hydra.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
---

# Operate a Hydra node
Expand Down
1 change: 1 addition & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = {
id: "dev/specification",
label: "Specification",
},
"dev/protocol",
{
type: "category",
link: { type: "doc", id: "dev/architecture/index" },
Expand Down
1 change: 1 addition & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fixities:
- infixr 0 $
- infixr 1 &
- infixl 3 <|>
- infixr 2 ||
- infixr 3 &&
- infixl 1 <&>
- infixl 4 <$>
Expand Down
8 changes: 8 additions & 0 deletions hydra-cardano-api/src/Cardano/Api/UTxO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ render (k, TxOut _ (txOutValueToValue -> v) _ _) =
min :: UTxO -> UTxO
min = UTxO . uncurry Map.singleton . Map.findMin . toMap

-- | Remove the right hand side from the left hand side.
difference :: UTxO' out -> UTxO' out -> UTxO' out
difference a b = UTxO $ Map.difference (toMap a) (toMap b)

-- | Infix version of 'difference'.
(\\) :: UTxO' out -> UTxO' out -> UTxO' out
a \\ b = difference a b

-- * Type Conversions

-- | Transforms a UTxO containing tx outs from any era into Babbage era.
Expand Down
2 changes: 2 additions & 0 deletions hydra-chain-observer/src/Hydra/ChainObserver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ data ChainObserverLog
| HeadInitTx {headId :: HeadId}
| HeadCommitTx {headId :: HeadId}
| HeadCollectComTx {headId :: HeadId}
| HeadDecrementTx {headId :: HeadId}
| HeadCloseTx {headId :: HeadId}
| HeadFanoutTx {headId :: HeadId}
| HeadAbortTx {headId :: HeadId}
Expand Down Expand Up @@ -205,6 +206,7 @@ chainSyncClient tracer networkId startingPoint observerHandler =
OnInitTx{headId} -> HeadInitTx{headId}
OnCommitTx{headId} -> HeadCommitTx{headId}
OnCollectComTx{headId} -> HeadCollectComTx{headId}
OnDecrementTx{headId} -> HeadDecrementTx{headId}
OnCloseTx{headId} -> HeadCloseTx{headId}
OnFanoutTx{headId} -> HeadFanoutTx{headId}
OnAbortTx{headId} -> HeadAbortTx{headId}
Expand Down
1 change: 1 addition & 0 deletions hydra-chain-observer/test/Hydra/ChainObserverSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ spec =
Just (Init{}) -> transition === Transition.Init
Just (Commit{}) -> transition === Transition.Commit
Just (CollectCom{}) -> transition === Transition.Collect
Just (Decrement{}) -> transition === Transition.Decrement
Just (Abort{}) -> transition === Transition.Abort
Just (Close{}) -> transition === Transition.Close
Just (Contest{}) -> transition === Transition.Contest
Expand Down
9 changes: 6 additions & 3 deletions hydra-cluster/src/CardanoClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ waitForPayments networkId socket amount addr =
selectPayments (UTxO utxo) =
Map.filter ((== amount) . selectLovelace . txOutValue) utxo

-- | Wait for transaction outputs with matching lovelace value and addresses of
-- the whole given UTxO
waitForUTxO ::
NetworkId ->
SocketPath ->
RunningNode ->
UTxO ->
IO ()
waitForUTxO networkId nodeSocket utxo =
waitForUTxO node utxo =
forM_ (snd <$> UTxO.pairs utxo) forEachUTxO
where
RunningNode{networkId, nodeSocket} = node

forEachUTxO :: TxOut CtxUTxO -> IO ()
forEachUTxO = \case
TxOut (ShelleyAddressInEra addr@ShelleyAddress{}) value _ _ -> do
Expand Down
Loading