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 chain state persistency #1049

Merged
merged 22 commits into from
Sep 8, 2023
Merged

Conversation

ffakenz
Copy link
Contributor

@ffakenz ffakenz commented Aug 30, 2023

🪚 Remove previous attribute from ChainStateAt.

🪚 Since ChainStateType is not recursive anymore, the HeadState now keeps a non-empty list of ChainStateType instead.

🪚 This means, now the HeadLogic has to collect the new ChainStateType during 'aggregate'.

🪚 Finally, the LocalChainState now has to maintain a non-empty list instead in order to implement 'rollback'.

🪚 As a consequence, now the persistent state is more lightweight and easier to read and work with.


  • CHANGELOG updated or not needed
  • Documentation updated or not needed
  • Haddocks updated or not needed
  • No new TODOs introduced or explained herafter

@ffakenz ffakenz self-assigned this Aug 30, 2023
@ffakenz ffakenz changed the title Refactor chain state persistence Refactor chain state persistency Aug 30, 2023
@ffakenz ffakenz marked this pull request as ready for review August 30, 2023 12:30
@ffakenz ffakenz force-pushed the refactor-chain-state-persistence branch 3 times, most recently from ec4da37 to cba1aab Compare August 30, 2023 19:27
@github-actions
Copy link

github-actions bot commented Aug 30, 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-09-08 10:54:49.744790202 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 3ffaf6b87df35cb01a52eb23032b8f0b1a2a3ad3acf0930abc9c833a 4150
νCommit e4c32d6dc83b2917aa7805571f30437ad98b6d20d821d34d45943755 2093
νHead 8a43c1c4d5cb60c212e7aa540932f311cb914a1b6104f0f36a2aaaf0 8845
μHead efd460b736e8155861e909d6507760b24a5c28717591c6e98c26b104* 4187
  • The minting policy hash is only usable for comparison. As the script is parameterized, the actual script is unique per Head.

Cost of Init Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 4778 11.82 4.65 0.49
2 4985 14.46 5.67 0.53
3 5190 16.87 6.58 0.56
5 5600 21.43 8.31 0.63
10 6623 33.37 12.85 0.80
37 12162 98.57 37.66 1.75

Cost of Commit Transaction

This is using ada-only outputs for better comparability.

UTxO Tx size % max Mem % max CPU Min fee ₳
1 599 12.67 4.97 0.31
2 787 16.49 6.69 0.37
3 972 20.28 8.39 0.42
5 1351 28.46 12.01 0.53
10 2283 51.35 21.96 0.82
18 3787 95.26 40.52 1.38

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 815 24.07 9.57 0.45
2 114 1143 38.52 15.40 0.62
3 170 1456 51.90 21.00 0.79
4 228 1784 73.63 29.76 1.04
5 283 2096 91.05 37.07 1.25

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 689 19.26 8.84 0.40
2 910 21.03 10.44 0.44
3 948 20.12 9.06 0.42
5 1552 25.35 14.68 0.53
10 2590 34.64 22.75 0.71
50 10848 98.49 81.92 2.01

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 722 22.75 10.15 0.44
2 928 24.40 11.62 0.47
3 1164 27.15 13.66 0.52
5 1573 30.70 16.75 0.59
10 2696 40.93 25.32 0.78
43 9234 98.57 75.30 1.90

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 5023 21.53 9.26 0.61
2 5532 36.71 15.98 0.81
3 5931 55.05 24.07 1.03
4 6346 76.47 33.51 1.29

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 4808 9.06 3.81 0.46
5 1 57 4836 10.37 4.61 0.48
5 5 284 4986 15.36 7.69 0.55
5 10 570 5163 22.18 11.79 0.64
5 20 1140 5524 35.14 19.72 0.82
5 30 1706 5881 47.91 27.56 0.99
5 40 2277 6246 61.31 35.67 1.18
5 50 2847 6602 74.19 43.56 1.35
5 69 3929 7286 99.69 58.99 1.70

@ffakenz ffakenz force-pushed the refactor-chain-state-persistence branch 3 times, most recently from 5536802 to be45db0 Compare August 31, 2023 09:40
@github-actions
Copy link

github-actions bot commented Aug 31, 2023

Test Results

358 tests  ±0   353 ✔️ ±0   23m 34s ⏱️ +56s
121 suites ±0       5 💤 ±0 
    6 files   ±0       0 ±0 

Results for commit fe14efe. ± Comparison against base commit 2340ad5.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@v0d1ch v0d1ch left a comment

Choose a reason for hiding this comment

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

🎉

hydra-node/src/Hydra/Chain/Direct/Handlers.hs Outdated Show resolved Hide resolved
@ch1bo ch1bo self-requested a review September 1, 2023 09:46
@ffakenz ffakenz force-pushed the refactor-chain-state-persistence branch 3 times, most recently from 5167136 to 2debe86 Compare September 2, 2023 11:51
Copy link
Contributor

@pgrange pgrange left a comment

Choose a reason for hiding this comment

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

Before, the chainState was really abstract to the HeadLogic but that came with the overhead of having to store the full chainState history with every chain originated event. I'm not sure how heavy this overhead was but I can see how this PR removes it and that's cool.

So now, we do not store the chainState full history every time but it comes with the HeadlLogic having to know about the fact that there is a notion of chainState history and the headLogic know has to deal with it and, for instance, call this pushNewState function.

That's a shame the HeadLogic has to have this knowledge but I understand that there is a trade-off here and I'm fine with this way of dealing with it 👍

@ch1bo ch1bo self-assigned this Sep 4, 2023
@ffakenz ffakenz requested review from v0d1ch and pgrange September 4, 2023 11:11
@ffakenz ffakenz force-pushed the refactor-chain-state-persistence branch 5 times, most recently from f521683 to 49528af Compare September 4, 2023 14:07
Copy link
Member

@ch1bo ch1bo left a comment

Choose a reason for hiding this comment

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

I like the direction this is going. The fact that we do not need the full history on every chain event is great.

I do have two major points though, which are worth looking into.

As we are refactoring here, I feel like we should be pushing further and directly to a better situation. Details below 👇

hydra-node/src/Hydra/Chain.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Chain/Direct/State.hs Show resolved Hide resolved
@ch1bo ch1bo removed their assignment Sep 5, 2023
@ffakenz ffakenz force-pushed the refactor-chain-state-persistence branch 3 times, most recently from cb00516 to cf7a42a Compare September 6, 2023 08:20
@ch1bo ch1bo force-pushed the refactor-chain-state-persistence branch from caf99d3 to 5e5c466 Compare September 7, 2023 09:40
@ch1bo ch1bo assigned ch1bo and unassigned ffakenz Sep 8, 2023
@ch1bo ch1bo force-pushed the refactor-chain-state-persistence branch from baedbb6 to 354ead8 Compare September 8, 2023 10:33
Since ChainStateType is not recursive anymore, the HeadState now keeps a
non-empty list of ChainStateType instead.

This means, now the HeadLogic has to collect the new ChainStateType during
'aggregate'.

Finally, the LocalChainState now has to maintain a non-empty list instead
in order to implement 'rollback'.
Introduce 'history' handle to get all chain changed events.
Note: in the future we might want to change the interface to be a stream.

This new handle was needed in order to be able to resume the LocalChainState.
We were aggregating wrong the Rollback observation by appending the rolledBack
point to the previous history, but we needed to override it instead.
Add helper functions to avoid scattering the code all over the place.
Also made some renaming to keep things cohesive
This removes the need to keep the entire history as part of the HeadState,
keeping the persistence size at minimum.
Instead, we made a generic rollbackHistory function, that uses the chainStateSlot
to know until which point in time to rollback from history.

This brings the benefit of making ChainRolledBack very lightweight, reducing the
persistence size.
This avoids the need to expose the underlying structure of it.
The fact that the golden tests are only removing previous and still pass,
is proof that this is in fact a backward compatible change.
Make it depend on the type family instead of the concrete instance.

Also remove unused imports and minor formatting changes.
This removes the need of passing the initial chain state around and
allows us to use the LocalChainState handle on the BehaviorSpec.
@ch1bo ch1bo force-pushed the refactor-chain-state-persistence branch from 354ead8 to fe14efe Compare September 8, 2023 10:38
@ch1bo ch1bo merged commit 6026c0a into master Sep 8, 2023
@ch1bo ch1bo deleted the refactor-chain-state-persistence branch September 8, 2023 13:17
@ch1bo ch1bo added this to the 0.13.0 milestone Sep 20, 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