Skip to content

Commit 9657e17

Browse files
authored
Fix observation of deposits to be settled (#1978)
This is will be the last PR related to deposits that also fixes the "deposit used too early" problem identified in course of #1951 and related discussions. With all the prior work already done in #1969, #1974 and the refactorings of #1977 this was fairly straight forward. :alarm_clock: Breaking change on the network as I needed to change the `ReqSn` message. :alarm_clock: Needed to substantially increase the `defaultTTL` of re-enqueing inputs. This is needed because the `ReqSn` handling will wait for the deposit to become active (passes the `--deposit-period`) and needs to act on the `ReqSn` only then. This is problematic because the input queue is not (yet?) persisted and restarting the node will lose that state -> the deposit will become active, but an `AckSn` would not be sent. See #1999 for a follow-up to address this. :alarm_clock: The fact that we observe a `SlotNo` in `DepositObservation` requires a `TimeHandle` to convert it further to a `UTCTime` (in `convertObservation`). As the `hydra-chain-observer` does not have a `TimeHandle`, I decided to switch to using `HeadObservation` (the type from `hydra-tx`) instead of `OnChainTx` (the type from `hydra-node`) for the chain observer / `hydra-explorer` interface. This results in quite a lot of (backwards compatible) changes and this companion PR: cardano-scaling/hydra-explorer#47 TODO: - [x] spec changes cardano-scaling/hydra-formal-specification#18 - [x] make chain observers not break the explorer API --- * [x] CHANGELOG updated * [x] Documentation updated * [x] Haddocks updated or not needed * [ ] No new TODOs introduced or explained herafter - Two new TODOs in `Hydra.HeadLogic.onOpenNetworkReqSn` on things we're not sure that are needed or even missing from the implementation (not critical, but just inconsistent)
2 parents 091c1eb + b910ccc commit 9657e17

File tree

95 files changed

+1024
-2078
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1024
-2078
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ changes.
3838

3939
- Add `UDP` and `S3` examples for `EventSource` and `EventSink` implementations to `hydra-node:examples`.
4040

41+
- Switch `hydra-chain-observer` to use `HeadObservation` when reporting observations to `hydra-explorer`.
42+
- Most observation types got changed quite a lot to match the previously used `OnChainTx`.
43+
- This introduces `ToJSON` and `FromJSON` instances on all observation types.
44+
- `CollectComObservation` and `ContestObservation` are made compatible with their `OnChainTx` counterparts.
45+
4146
## [0.21.0] - 2025-04-28
4247

4348
- New metric for counting the number of active peers: `hydra_head_peers_connected`

docs/docs/dev/protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ As indicated on the transaction trace example above, a successful incremental co
115115

116116
For `incrementTx`, the input is governed by the deposit validator which ensures funds can only be spent into the destined head before the **deposit deadline** (by anyone using a `recoverTx` after the deadline). Hence, any rollbacks _before_ this deadline can be mitigated by re-submitting the same (or a new) `incrementTx`. It is vital though, that the deadline is _far enough_ in the future to not be prone to yet more chain re-organization and run out of time mitigating eventually. As the deposit deadline is only relevant for the pessimistic case, we can pick fairly *high values* without affecting user experience. For example: **1 week**, equating to roughly 5x the worst case settlement time of Cardano.
117117

118-
For `depositTx`, the inputs may very well be spent by an attacker and an honest `hydra-node` should be cautious in observing a deposit as settled before signing a snapshot that authorizes addition of those funds to the L2 state. To mitigate this, a **deposit period** analogous to the contestation period of close/contest phase is introduced. A valid deposit must record in its datum when it was created and when the deadline shall be (see [specification](./specification.md)). An honest `hydra-node` will only consider deposits that are **older** than the deposit period and when the deadline is **further out** than the deposit period. While the deposit period will delay all increments by at least that time, a `hydra-node` can configure the risk it is willing to take using this period. For example: **1 hour** means that roughly after 180 blocks on `mainnet` we would only see a rollback including the `depositTx` with `0.01%` likelihood, assuming a `15%` adversarial stake fairly conservative grinding power. See [this excellent explanation and calculator](https://aiken-lang.org/fundamentals/what-i-wish-i-knew#transaction-latency-vs-finality) in the Aiken docs.
118+
For `depositTx`, the inputs may very well be spent by an attacker and an honest `hydra-node` should be cautious in observing a deposit as settled before signing a snapshot that authorizes addition of those funds to the L2 state. To mitigate this, a **deposit period** analogous to the contestation period of close/contest phase is introduced. A valid deposit must have an upper validity to indicate when it was created (at latest) and record the deposit deadline in the output datum (see [specification](./specification.md)). An honest `hydra-node` will only consider deposits that are **older** than the deposit period and when the deadline is **further out** than the deposit period. While the deposit period will delay all increments by at least that time, a `hydra-node` can configure the risk it is willing to take using this period. For example: **1 hour** means that roughly after 180 blocks on `mainnet` we would only see a rollback including the `depositTx` with `0.01%` likelihood, assuming a `15%` adversarial stake fairly conservative grinding power. See [this excellent explanation and calculator](https://aiken-lang.org/fundamentals/what-i-wish-i-knew#transaction-latency-vs-finality) in the Aiken docs.
119119

120120
In summary, a deposit may only be picked up while `Active` in the following deposit life cycle:
121121
```mermaid

docs/docs/known-issues.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Note that, as with any adjustments of this kind, it is good practice to make a b
5757

5858
There is a hard-coded limit on the **mainnet** where only up to 100 ada can be committed into the Hydra head. This is a safety precaution and will be increased as more experience is gained in running Hydra heads on the mainnet.
5959

60+
### Deposit periods
61+
62+
The `--deposit-period` allows an individual `hydra-node` operator to decide how long they want a deposit to have settled at least. However, differences bigger than [`defaultTTL * waitDelay`](https://hydra.family/head-protocol/haddock/hydra-node/Hydra-Node.html#v:waitDelay) (currently 10 minutes) result in non-approved snapshots. This is due to the way the `HeadLogic` is implemented and snapshot requests are not retried currently. See [hydra#1999](https://github.com/cardano-scaling/hydra/issues/1999) for more context.
63+
6064
### Known bugs
6165

6266
Refer to the project repository issue tracker for [known issues](https://github.com/cardano-scaling/hydra/issues?q=is%3Aissue+is%3Aopen+label%3A%22bug+%3Abug%3A%22). If you discover any security-relevant problems, please follow our [security policy](https://github.com/cardano-scaling/hydra?tab=security-ov-file#readme).

flake.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
flake-parts.url = "github:hercules-ci/flake-parts";
1010
haskellNix.url = "github:input-output-hk/haskell.nix";
1111
hydra-coding-standards.url = "github:cardano-scaling/hydra-coding-standards/0.6.0";
12-
hydra-spec.url = "github:cardano-scaling/hydra-formal-specification";
12+
hydra-spec.url = "github:cardano-scaling/hydra-formal-specification/7f78e005b95ff3b9c55995632ceb3d6ab96a305e";
1313
iohk-nix.url = "github:input-output-hk/iohk-nix";
1414
lint-utils = {
1515
url = "github:homotopic/lint-utils";
Lines changed: 69 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,81 @@
11
{
22
"samples": [
33
{
4-
"blockNo": 11469835,
5-
"observedTx": {
6-
"deadline": "1864-06-07T08:06:42.493553678687Z",
7-
"depositTxId": "cb3bd69dbdb1b186f456066dfdcb6942e25de088f8bac5155d5f0d0c6836cb55",
8-
"deposited": {
9-
"00e4220b1f6f0c0cbe5375fd4a7c4ccc2ab0a4df73be4a8b2de51afecc098190#27": {
10-
"address": "addr_test1xpe9revx3r3nyvesq2rsszjhs3hykh026a8f45kdhy7fnwuqrkdyr4ngzc7xvw8wv6lt24qedx54l7qh05zrx0trvy9sjp7tug",
11-
"datum": null,
12-
"datumhash": "ecb9e67e345ddab2824d4d18403dba908b5ffdf08d66b1e4c9e6f45d9055cc12",
13-
"inlineDatum": null,
14-
"inlineDatumRaw": null,
15-
"referenceScript": {
16-
"script": {
17-
"cborHex": "450100002261",
18-
"description": "",
19-
"type": "PlutusScriptV3"
20-
},
21-
"scriptLanguage": "PlutusScriptLanguage PlutusScriptV3"
22-
},
23-
"value": {
24-
"8f461954fe2f18fee1dca233f358907e643ff839ed1f995e4bf325e3": {
25-
"64": 7602771646321794659,
26-
"f3001dfd19e7119c811c93": 1
27-
},
28-
"lovelace": 1
29-
}
30-
},
31-
"0160cab70697cdc3d59b04f1ee4a48f9b977aa573d9b1eb0b58aa44178892f1a#77": {
32-
"address": "addr_test1zqkuk8y8nkkzt08rx8jthcu670hurcz4y44g09uyssqx4y35kx923u9ms2ymt9ln6muc48ur8hcc5da33ksdnxgqy8ks5e2q6d",
33-
"datum": null,
34-
"datumhash": null,
35-
"inlineDatum": null,
36-
"inlineDatumRaw": null,
37-
"referenceScript": {
38-
"script": {
39-
"cborHex": "82041a00c4769f",
40-
"description": "",
41-
"type": "SimpleScript"
42-
},
43-
"scriptLanguage": "SimpleScriptLanguage"
44-
},
45-
"value": {
46-
"467f58932b54910584a0e8ea25a225e06a14530b2e96e938c53a3f22": {
47-
"d4a24b250a826dfd67": 1
48-
},
49-
"b0c53e2bf180858da4b64eb5598c5615bba7d723d2b604a83b7f9165": {
50-
"45bc": 6950542976713988590
51-
},
52-
"lovelace": 1
53-
}
54-
},
55-
"205aad9a84f08c2c39bea75b56b6a292482eed9430f95266c017e17109289241#18": {
56-
"address": "addr1wysct49x3zvw2aqttyathyjeh94mnn5e036uvl8wczq4ucssurfgu",
57-
"datum": null,
58-
"datumhash": "41699a1b5ab494ad34ae06734441d91cde5b1c22e0dc3d7d1ae8fe354877829a",
59-
"inlineDatum": null,
60-
"inlineDatumRaw": null,
61-
"referenceScript": null,
62-
"value": {
63-
"bd82fd480c48606751a750bbb56857c7d8d14e9c42b9da4ad18a8344": {
64-
"b8f0a9752d49f7c5346b65394c": 9059562413771623800
65-
},
66-
"lovelace": 4888527008992087298
67-
}
68-
},
69-
"340541827a6964433d390ae77b218135b06d516d2779fee11a691400d06f248c#77": {
70-
"address": "addr_test1xz29p2afmkvpcnu0neqepllx8w7ezjy0gcf2rqps9ed2383tjw4fkgyfcmsd4rck73dm9yx6pgx04x6quu74zxs0zfuqx3v97y",
71-
"datum": null,
72-
"datumhash": "fba45ffbc4e0ba2b2de7d662b4bf9547ddabcca761cd557d42eadc1476105adb",
73-
"inlineDatum": null,
74-
"inlineDatumRaw": null,
75-
"referenceScript": null,
76-
"value": {
77-
"071862ec91fe3bcab0125507d0f0a8f641b9d1b2d3a93a9f4fb30874": {
78-
"7651940ce20d4fd595d3c301d254d5ec": 2
79-
},
80-
"lovelace": 3697185391807425489
81-
}
82-
},
83-
"aed125f47711f51948b200f86c40dbc08bfd8c82946453b9d829aac7460fd5fe#59": {
84-
"address": "addr_test1zpjm03wtrxn2kmlc2hfqnucswgalpl5emr3dn6v78drsvt9rvnc2m6lu84jmx7gf249g0y4s5402p0ls3cfafakcjt9spwqd53",
85-
"datum": null,
86-
"datumhash": null,
87-
"inlineDatum": null,
88-
"inlineDatumRaw": null,
89-
"referenceScript": {
90-
"script": {
91-
"cborHex": "82041a00b08312",
92-
"description": "",
93-
"type": "SimpleScript"
94-
},
95-
"scriptLanguage": "SimpleScriptLanguage"
96-
},
97-
"value": {
98-
"245d5a7a06fe18358242e81281cd5ba9e6abe4efc54e7b659f25abae": {
99-
"36": 1
100-
},
101-
"379906b6ad2a409ad4c356dcbdb563287cc12bc06104bd6ff5a9c358": {
102-
"742203a9b7": 6650088383203647906
103-
},
104-
"lovelace": 1717393874581216599
105-
}
106-
},
107-
"cd89c81431678548e49cfb53a8a93c140a455ea16eaad6a9f385946f3f35f647#11": {
108-
"address": "EqGAuA8vHnP2tcg9NLMo64AbFGVivS1Q5EKvqV4UwMA7MjvMPGXF6wXHKMjNxkxvK5hqmwK26EQnCK7kcjAnUSDH2Pb64joPnhrQwy79RDxwAo4ua5pKC6J",
109-
"datum": null,
110-
"datumhash": "28064b361d5df6638f273df53ddbeccffbdcdc0eee5ff0aa2696eeff4658d29e",
111-
"inlineDatum": null,
112-
"inlineDatumRaw": null,
113-
"referenceScript": {
114-
"script": {
115-
"cborHex": "450100002261",
116-
"description": "",
117-
"type": "PlutusScriptV1"
118-
},
119-
"scriptLanguage": "PlutusScriptLanguage PlutusScriptV1"
120-
},
121-
"value": {
122-
"2db8410d969b6ad6b6969703c77ebf6c44061aa51c5d6ceba46557e2": {
123-
"bf924447fbca0ce54151066c3563bbe00e940f9c2f5872b28f": 4636055899833251354
124-
},
125-
"844022f0a8a3f0fb23a21ef23627434d01844a4ac3e9535d7b3d0839": {
126-
"335e7a6c23f6bbc95970fddae37f4746200f": 3155778062082065137
127-
},
128-
"lovelace": 342095614610669501
129-
}
130-
},
131-
"df288f89cefafe77b1df583b43ac934fb59abcbdf0f9d9d17995f802f4af9ea1#16": {
132-
"address": "addr_test1zqmk4sfnwrtv0cjvrxzxsx8z8jd96qce53yhmq9evn5vvc9kstz5fldt7fjlcupzl82pf5vc2uf272kcx0z9jnc4quzqk53dep",
133-
"datum": null,
134-
"datumhash": "c0a249a7f76fd9ed9010c22ceacdbcb57afe033587a231fdb55090eb2d26ecbe",
135-
"inlineDatum": null,
136-
"inlineDatumRaw": null,
137-
"referenceScript": {
138-
"script": {
139-
"cborHex": "82041a009ae609",
140-
"description": "",
141-
"type": "SimpleScript"
142-
},
143-
"scriptLanguage": "SimpleScriptLanguage"
144-
},
145-
"value": {
146-
"2e12c5e499e0521b13837391beed1248a2e36117370662ee75918b56": {
147-
"dc4f6dd040c40d9d": 2
148-
},
149-
"lovelace": 2
150-
}
151-
},
152-
"f1485c1b1fc1b3a87923df98cbdccee5b1f8625b7a323f8e21998e88f61a4d7e#66": {
153-
"address": "addr1yxmllt04zy73manlaccqzyrmwxszunln5r3cc2lg5amwngh5w8d6usm8frqcyxhn8c509mxx9vap9v736p08ljmapxwqphrgwe",
154-
"datum": null,
155-
"inlineDatum": {
156-
"bytes": "1cc13314"
157-
},
158-
"inlineDatumRaw": "441cc13314",
159-
"inlineDatumhash": "c30e5cd4e6d44c62b9ece2bbbc7f838a04f81827ea68729946c35a454d460b38",
160-
"referenceScript": {
161-
"script": {
162-
"cborHex": "8303018183030282830302828200581c4ebe8a90aa1c1cfb00734b58e0164d2f7ecbb561a41207d487a041838200581cb567cf2ecc5dbb61cf4aa7ab3b9b87d58bd00a00d316a090ef37b24e820280",
163-
"description": "",
164-
"type": "SimpleScript"
165-
},
166-
"scriptLanguage": "SimpleScriptLanguage"
167-
},
168-
"value": {
169-
"2d725128406dc832eb74c4709aca0512499b3c7b17e00d7cb2e6d1b1": {
170-
"f9db4c27a84c8e4731d70e340f90ebeaa8e6f5dc": 3177464044637024899
171-
},
172-
"lovelace": 1752824964841714386
4+
"blockNo": 15245101,
5+
"observed": {
6+
"headId": "3f51ac8f4724ce5162c1ce41f46865d3",
7+
"headParameters": {
8+
"contestationPeriod": 51044,
9+
"parties": [
10+
{
11+
"vkey": "af01f5d43a1d781dca705fcd6b1c2d9d99791babe8b17353954f8320990e6dad"
12+
},
13+
{
14+
"vkey": "abd9e774baf40973eee76d4ebc06c7c693c0a612cdb96ebbda2bc1a0455af78d"
15+
},
16+
{
17+
"vkey": "f5b48d69d2b0439c298773d1a833e31cb06486515c3b5e784f9a187eb0343c4a"
18+
},
19+
{
20+
"vkey": "59b244c59d98e5891e2e0fc5f6606248374c5a1e03b46d7eccf44e06e22023f4"
21+
},
22+
{
23+
"vkey": "6bc15ad0b420d830ca7d2b5287683e559155b8168970c21232e34377164cbf1a"
24+
},
25+
{
26+
"vkey": "e118601c836aa5f9df4631c78a389e4a548a0c14b51d43a2bafeac2ad329cf03"
27+
},
28+
{
29+
"vkey": "27720b3f095a077fc45177b3f06aad07bcec4d913333d79f97e30f5785fe2045"
30+
},
31+
{
32+
"vkey": "3a6fa9901dde2c20da535b6eb183d4cbb04e416384404ddaff2b08ff33fc9ee5"
33+
},
34+
{
35+
"vkey": "b815d504872e5fd0be4cc2dee35ba4158491ef2bea83bd8e641ff88296d64a45"
36+
},
37+
{
38+
"vkey": "b1f07c22e620bd46452d81164d5b99479521d6c14d71b872c7ad154fc5386c00"
39+
},
40+
{
41+
"vkey": "649d06e159ef401c8944161231d086cb70031ad702166064f7862f0ef328caab"
42+
},
43+
{
44+
"vkey": "4fefcda60d990e1744fe54480282bc029653cddcda4dfc2bc23ce052d1ae0231"
45+
},
46+
{
47+
"vkey": "9f0fbf0ce94462652c62181c431f32c56254fa9148237e2ee88b49d70aef665e"
48+
},
49+
{
50+
"vkey": "4f91daee191794267a3f3d5f746caff4305e556edeaab5a68c8a4aa9edf7f602"
51+
},
52+
{
53+
"vkey": "4f13b34e603aa6a6af237ad3d3b21f54acf5593a2fbc376ae9bdbb21edae6e20"
54+
},
55+
{
56+
"vkey": "92882b1a63ae82a0981e5598e1c3acddf4a41ef6ec4fe717c2368bc49f84c598"
57+
},
58+
{
59+
"vkey": "92f9ec10fa24b466c9fdbff8f527c208ef36a21889bb10c26402d97a140c76de"
60+
},
61+
{
62+
"vkey": "96b7c016139a76c56e8d581ebcf9bcf771e0d343ff46bede5b2ade360544e021"
63+
},
64+
{
65+
"vkey": "19401dd03fe6cbf80f988ab9f128d9c2f3f02edf2db53304e5fa39f1d58e4cdc"
17366
}
174-
}
67+
]
17568
},
176-
"headId": "17507038bcf6e13ca806e36638f17b98",
177-
"tag": "OnDepositTx"
69+
"headSeed": "6fa42cd023c1150ea802ddd5fa803109",
70+
"participants": [],
71+
"tag": "Init"
17872
},
17973
"point": {
180-
"blockHash": "6f08131d3706e5f9c7719be6d7307054bc0fefc6ce927b00c1c267776d8645cf",
181-
"slot": 15339821,
74+
"blockHash": "f0ad5718bf7f009b93b18a88ceb67da99f03535dfc598930202adaa866f0e623",
75+
"slot": 13417101,
18276
"tag": "ChainPoint"
18377
}
18478
}
18579
],
186-
"seed": 1091611222
80+
"seed": -1638257477
18781
}

0 commit comments

Comments
 (0)