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

Refactor HeadLogic with types for each state #725

Merged
merged 20 commits into from
Feb 22, 2023
Merged

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Feb 16, 2023

🧹 Address some XXX in HeadLogic by creating actual types for OpenState et al. This make the interface between update and on... functions smaller and could be used to split the update into multiple cases (one for each state) later.

@ch1bo ch1bo changed the base branch from master to ch1bo/script-complexity February 16, 2023 12:19
@github-actions
Copy link

github-actions bot commented Feb 16, 2023

Test Results

276 tests   - 11   270 ✔️  - 11   14m 19s ⏱️ - 2m 29s
  94 suites  -   4       6 💤 ±  0 
    4 files    -   1       0 ±  0 

Results for commit 237fd61. ± Comparison against base commit 62384c9.

This pull request removes 11 tests.
Hydra.TUI.Options ‑ parses --cardano-signing-key option
Hydra.TUI.Options ‑ parses --connect option
Hydra.TUI.Options ‑ parses --network-id option
Hydra.TUI.Options ‑ parses --node-socket option
Hydra.TUI/end-to-end smoke tests ‑ display feedback long enough
Hydra.TUI/end-to-end smoke tests ‑ doesn't allow multiple initializations
Hydra.TUI/end-to-end smoke tests ‑ starts & renders
Hydra.TUI/end-to-end smoke tests ‑ supports the full Head life cycle
Hydra.TUI/end-to-end smoke tests ‑ supports the init & abort Head life cycle
Hydra.TUI/text rendering errors ‑ should show not enough fuel message and suggestion
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Feb 16, 2023

Transactions Costs

Sizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using arbitrary values and results are not fully deterministic and comparable to previous runs.

Metadata
Generated at 2023-02-22 08:23:12.14618225 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 7bb44e248f92ae5d2c4c744244b469d59a5bfa8a5d8ce9b6b27e5750 5530
νCommit 70c545fc894ada81ad46715bac1a11fa755b3e3a1d94f03254a4d397 2473
νHead c1fa50bb6fb1b7f84f4b103bcfb6f71eaeb4de93ddcab99729c122fb 9928

Cost of Init Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 5048 9.31 3.67 0.47
2 5254 13.08 5.17 0.52
3 5458 13.79 5.41 0.54
5 5867 18.19 7.11 0.61
10 6893 30.13 11.77 0.78
45 14069 98.72 38.18 1.84

Cost of Commit Transaction

Currently only one UTxO per commit allowed (this is about to change soon)

UTxO Tx size % max Mem % max CPU Min fee ₳
1 633 21.10 8.53 0.41

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 13137 21.77 8.71 0.97
2 114 13490 36.93 14.92 1.15
3 171 13843 54.24 22.09 1.36
4 229 14198 74.47 30.49 1.60
5 285 14548 97.16 39.97 1.86

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 10534 16.62 7.12 0.80
2 10733 18.46 8.24 0.83
3 10864 19.41 8.66 0.85
5 11228 22.52 10.50 0.90
10 12088 30.32 14.84 1.03
35 16254 66.11 34.86 1.65

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 10570 21.06 8.80 0.85
2 10727 23.16 9.84 0.88
3 10900 24.44 10.56 0.90
5 11257 28.88 12.89 0.97
10 12125 38.20 17.85 1.12
35 16257 81.02 40.07 1.81

Cost of Abort Transaction

Some variation because of random mixture of still initial and already committed outputs.

Parties Tx size % max Mem % max CPU Min fee ₳
1 15089 28.51 12.05 1.13
2 14987 37.16 15.43 1.22
3 15197 53.16 22.24 1.41
4 15935 88.04 37.93 1.84
5 15630 97.20 41.42 1.92

Cost of FanOut Transaction

Involves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.

Parties UTxO UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
5 0 0 15009 10.09 4.11 0.92
5 1 57 15041 11.62 4.99 0.94
5 5 283 15186 18.01 8.63 1.03
5 10 570 15368 25.64 13.04 1.13
5 20 1134 15723 40.61 21.73 1.33
5 30 1706 16087 56.46 30.79 1.54
5 38 2160 16372 68.33 37.70 1.69

@ch1bo ch1bo marked this pull request as ready for review February 17, 2023 07:20
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from 8c98b1f to cd7b021 Compare February 17, 2023 08:43
@ch1bo ch1bo force-pushed the ch1bo/script-complexity branch from 22587e5 to 5595e33 Compare February 17, 2023 08:43
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from cd7b021 to 134b12d Compare February 17, 2023 11:19
@ch1bo ch1bo changed the base branch from ch1bo/script-complexity to master February 17, 2023 11:19
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from 134b12d to 64d8151 Compare February 17, 2023 11:20
@ch1bo ch1bo requested review from v0d1ch, a user, ffakenz and pgrange February 17, 2023 11:20
@@ -1,7 +1,6 @@
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

NewState closedState $
notifyClient :
[ OnChainEffect
{ -- REVIEW: Was using "old" chainState before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using the newChainState here correct as we were using the previous one before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure yet, that's why I left this comment 🙂 It might have been an oversight and is more evident now

@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from 64d8151 to 762ecd4 Compare February 20, 2023 14:25
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the motivation behind this, but I would like to suggest we do not change the API: The additional level of indirection introduced by XXXState types do not make sense in the JSON schema.

hydra-node/json-schemas/logs.yaml Show resolved Hide resolved
hydra-node/test/Hydra/BehaviorSpec.hs Show resolved Hide resolved
hydra-node/test/Hydra/HeadLogicSpec.hs Show resolved Hide resolved
@ch1bo ch1bo self-assigned this Feb 21, 2023
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch 4 times, most recently from a895946 to 54004cc Compare February 21, 2023 19:46
ch1bo added 12 commits February 22, 2023 08:21
This also fixes an (in-flight of this branch) broken field access.

Also, the TODO seems not relevant anymore so I removed it.
This allowed us already to remove incomplete record updates from
HeadLogic module.
We could think of encoding the possible previous states for each state
type, but this would be a bit too much right now.

Instead, this commit is motivated to limit the length of state linked
lists we generate.
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from 54004cc to 6d4024f Compare February 22, 2023 07:22
We chose not to manually implement ToJSON/FromJSON instances for
HeadState just to keep backward compatibility on the logs JSON schema.

A manual instance would mean higher maintainability demands, whereas the
logs schema is not so important as for example the api schema.
@ch1bo ch1bo force-pushed the ch1bo/head-logic-refactor branch from 6d4024f to 237fd61 Compare February 22, 2023 08:15
@ch1bo ch1bo removed their assignment Feb 22, 2023
@ch1bo ch1bo merged commit 056da80 into master Feb 22, 2023
@ch1bo ch1bo deleted the ch1bo/head-logic-refactor branch February 22, 2023 08:42
@pgrange pgrange mentioned this pull request Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants