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

Stateless observation hydra node #1196

Merged
merged 149 commits into from
Dec 8, 2023

Conversation

v0d1ch
Copy link
Contributor

@v0d1ch v0d1ch commented Dec 5, 2023

TODO:

  • Make E2E tests green with multiple heads on a network
  • fromPlutusCurrencySymbol partial
  • FIXME in broken Greetings
  • FIXME on comparing observations in HandlersSpec.hs
  • Test observe functions with multiple Head UTxO
  • Actually get rid of Hydra.Chain.Direct.State module from production code (use it only to generate transactions and rename it)

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

@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch from fb1969d to 1bda91b Compare December 5, 2023 09:26
Copy link

github-actions bot commented Dec 5, 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-12-08 21:01:07.763378916 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 985245919fcc6c0c5cd116023cd2c947c43e80dcbb5075fe12433fbb 4072
νCommit 7cb20fa71eb4c563ca283566ebe0aa65859d96c3f8cba35c52c181fd 2043
νHead 7a36661f5c15e9f1783aeaab890812c59b7286cbbc6de762d3110772 8816
μHead 8b111ac12274e46314769295a1c5dcab1d260096fc469fd698065463* 3851
  • 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 4379 10.44 4.03 0.46
2 4576 12.55 4.83 0.49
3 4777 14.89 5.72 0.52
5 5180 19.22 7.35 0.59
10 6184 30.24 11.53 0.75
41 12422 99.15 37.65 1.77

Cost of Commit Transaction

This is using ada-only outputs for better comparability.

UTxO Tx size % max Mem % max CPU Min fee ₳
1 534 11.37 4.44 0.30
2 721 15.04 6.07 0.35
3 911 18.85 7.75 0.40
5 1282 26.90 11.27 0.51
10 2214 49.55 20.97 0.80
19 3904 99.43 41.75 1.43

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 484 21.12 8.27 0.40
2 114 590 32.31 12.77 0.53
3 169 700 46.93 18.64 0.69
4 227 810 62.94 25.15 0.88
5 281 920 74.51 30.12 1.01
6 337 1031 94.84 38.41 1.24

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 541 16.68 7.67 0.36
2 765 18.45 9.34 0.40
3 907 19.93 10.76 0.43
5 1270 23.61 14.06 0.50
10 2141 32.24 22.02 0.66
50 8676 96.29 82.31 1.90

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 576 20.22 8.96 0.40
2 738 21.93 10.47 0.44
3 924 24.28 12.40 0.48
5 1301 28.20 15.80 0.55
10 2182 37.83 24.05 0.73
43 7992 98.89 77.51 1.86

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 4309 18.98 8.16 0.55
2 4471 32.06 13.96 0.71
3 4559 42.29 18.31 0.82
4 4842 66.64 29.32 1.11
5 4917 80.70 35.40 1.27

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 4205 8.26 3.46 0.43
5 1 57 4240 9.28 4.13 0.44
5 5 285 4375 14.40 7.27 0.51
5 10 570 4546 20.34 10.99 0.59
5 20 1139 4885 32.85 18.71 0.77
5 30 1707 5224 44.94 26.25 0.93
5 40 2277 5565 57.25 33.88 1.10
5 50 2846 5904 69.77 41.61 1.27
5 74 4210 6715 99.34 59.96 1.68

End-To-End Benchmark Results

This page is intended to collect the latest end-to-end benchmarks results produced by Hydra's Continuous Integration system from the latest master code.

Please take those results with a grain of salt as they are currently produced from very limited cloud VMs and not controlled hardware. Instead of focusing on the absolute results, the emphasis should be on relative results, eg. how the timings for a scenario evolve as the code changes.

Generated at 2023-12-08 21:04:41.934947077 UTC

Baseline Scenario

Number of nodes 3
Number of txs 9000
Avg. Confirmation Time (ms) 23.447009153
P99 115.43640142000001ms
P95 33.225534399999994ms
P50 20.812751ms
Number of Invalid txs 0

Baseline Scenario

Number of nodes 1
Number of txs 3000
Avg. Confirmation Time (ms) 4.453277484
P99 7.309544409999993ms
P95 5.25924225ms
P50 4.339461999999999ms
Number of Invalid txs 0

@ch1bo ch1bo mentioned this pull request Dec 5, 2023
3 tasks
@ch1bo ch1bo linked an issue Dec 5, 2023 that may be closed by this pull request
3 tasks
@ch1bo ch1bo self-requested a review December 5, 2023 10:37
@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch from b448dca to e2c4e99 Compare December 5, 2023 15:00
Copy link
Collaborator

@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.

There are still some things to clean up. All in all, the change looks better than expected. I have left several suggestions, but plan to address them also myself.

There is also quite some refactoring potential and i will try to remove the Hydra.Chain.Direct.State module completely from the "production code". That is, only use it to generate transactions in tx-cost and the hydra-node test suite.

hydra-node/src/Hydra/Chain/Direct.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Chain/Direct/Tx.hs Outdated Show resolved Hide resolved
notifyClient = ClientEffect $ ServerOutput.Committed headId pt utxo

postCollectCom =
OnChainEffect
{ postChainTx = CollectComTx $ fold newCommitted
{ postChainTx = CollectComTx{headId, headParameters = parameters}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Odd that we had constructed the tx with expected commits before, but now we seemingly infer them from the spent UTxO. But on the other hand parameters were added here instead of inferring them from the spendable UTxO.

Also, the AbortTx does have the committed UTxO.. this is very inconsistent.

Must: be consistent in one or the other approach

hydra-cardano-api/src/Hydra/Cardano/Api/PolicyId.hs Outdated Show resolved Hide resolved
hydra-cluster/test/Test/DirectChainSpec.hs Outdated Show resolved Hide resolved
@@ -189,12 +197,12 @@ finalizeTx ::
MonadThrow m =>
TinyWallet m ->
ChainContext ->
ChainStateType Tx ->
UTxO.UTxO ->
UTxO.UTxO ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should: document which UTxO is which in haddock (it's an impossible to understand signature otherwise)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to separate it even?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we want to separate them, so to favor documentation... but you are correct; we can combine them all and have the function to take a single argument.

wdyt?

hydra-node/test/Hydra/Chain/Direct/StateSpec.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Chain/Direct/State.hs Outdated Show resolved Hide resolved
hydra-node/src/Hydra/Chain/Direct/State.hs Show resolved Hide resolved
hydra-node/src/Hydra/Chain/Direct/State.hs Outdated Show resolved Hide resolved
@ffakenz ffakenz force-pushed the ensemble/stateless-observation-hydra-node branch from b9438f8 to 715013d Compare December 5, 2023 18:26
@ch1bo ch1bo force-pushed the ensemble/stateless-observation-hydra-node branch from c5f3319 to 2399328 Compare December 6, 2023 07:27
@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch from 2316d04 to d99092c Compare December 6, 2023 09:34
@ch1bo ch1bo force-pushed the ensemble/stateless-observation-hydra-node branch from af7bbc4 to 232a5ad Compare December 6, 2023 17:09
@ffakenz ffakenz force-pushed the ensemble/stateless-observation-hydra-node branch 3 times, most recently from 251d97b to 1fd440c Compare December 6, 2023 19:34
@ch1bo ch1bo force-pushed the ensemble/stateless-observation-hydra-node branch from 5f9faa1 to 4713778 Compare December 7, 2023 14:04
@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch 2 times, most recently from 8788952 to b12a5a3 Compare December 7, 2023 17:21
@ch1bo ch1bo force-pushed the ensemble/stateless-observation-hydra-node branch 3 times, most recently from 002957b to 7299a5e Compare December 7, 2023 18:51
Copy link
Collaborator

@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 am happy with the changes now!

Ideally we would update the CHANGELOG and bump versions of packages accordingly.

Let's merge this!

Copy link

github-actions bot commented Dec 7, 2023

Test Results

377 tests  +5   372 ✔️ +5   21m 2s ⏱️ -49s
128 suites +2       5 💤 ±0 
    5 files   ±0       0 ±0 

Results for commit ead4dab. ± Comparison against base commit 06feee9.

This pull request removes 9 and adds 14 tests. Note that renamed tests count towards both.
Hydra.Chain.Direct.Handlers/chainSyncHanlder ‑ observes transactions onRollForward
Hydra.Chain.Direct.Handlers/chainSyncHanlder ‑ roll forward fails with outdated TimeHandle
Hydra.Chain.Direct.Handlers/chainSyncHanlder ‑ roll forward results in Tick events
Hydra.Chain.Direct.Handlers/chainSyncHanlder ‑ rollbacks state onRollBackward
Hydra.Chain.Direct.State/abort ‑ ignore aborts of other heads
Hydra.Chain.Direct.State/init ‑ is not observed if not invited
Hydra.Chain.Direct.Tx/collectComTx ‑ Ignore InitTx with wrong cardano keys
Hydra.Chain.Direct.Tx/collectComTx ‑ Ignore InitTx with wrong contestation period
Hydra.HeadLogic/Coordinated Head Protocol ‑ ignores closeTx for another head
Hydra.Behavior/Two participant Head ‑ ignores head initialization of other head
Hydra.Chain.Direct.Handlers/chainSyncHandler ‑ observes transactions onRollForward
Hydra.Chain.Direct.Handlers/chainSyncHandler ‑ roll forward fails with outdated TimeHandle
Hydra.Chain.Direct.Handlers/chainSyncHandler ‑ roll forward results in Tick events
Hydra.Chain.Direct.Handlers/chainSyncHandler ‑ rollbacks state onRollBackward
Hydra.Chain.Direct.State/abort ‑ can create valid abort transactions for any observed head
Hydra.Chain.Direct.Tx/HeadId (cardano) ‑ headIdToPolicyId . mkHeadId === id
Hydra.Chain.Direct.Tx/HeadSeed (cardano) ‑ headSeedToTxIn . txInToHeadSeed === id
Hydra.HeadLogic/Coordinated Head Protocol ‑ ignores abortTx of another head
Hydra.HeadLogic/Coordinated Head Protocol ‑ ignores closeTx of another head
…

♻️ This comment has been updated with latest results.

@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch from bf83efd to ce00931 Compare December 8, 2023 09:07
ch1bo and others added 27 commits December 8, 2023 18:36
As we removed those guards from the chain layer, it is important that
the logic layer is doing this filtering.
We were missing to check the headId from the observation with ours within the local state.
In order to avoid breaking changes in the Greetings output messages
introduce a new projection. This projection only gives you a HeadId
if the Head is in Initializing state.
This is needed to ignore OnInitTx because it was not using the right
on-chain keys.
We were only using observeRawInitTx and all checking of whether "its the
right head" needs to be in the logic layer now.

This commit does not yet migrate the test for this (which was in TxSpec)
This was done by the chain layer before, but needs to be done now by the
logic layer. This is the only usage of on-chain identities in the
off-chain Head protocol, but it still is required to retain semantics
from before.

This made initializing the Environment a bit hacky, as it is very
specific to the Cardano configuration.
Originally only needed for the observation side (OnInitTx), the
BehaviorSpec actually nudges us into also specifying the 'participants'
on the creation side (InitTx). This feels right, despite it requiring
quite a lot of changes in our test suites, because we can remove the
other cardano keys from the direct chain handle! At some point this will
enable us to open a head on-demand with any other participants.
This avoids a breaking change on the API, but keeps additional
information about parties and contestationPeriod. This is helpful as all
three things need to match.
We cannot use "derived" on chain identifiers in the Model tests, because
we are actually validating the transactions and need to sign them
correctly. Hence, the participation tokens need to be match the
verification keys used.
We must reset the headId when the head is open or aborted, but keep it
on all other server outputs.
This was correct originally, but got re-added incorrectly a few commits back
Avoid some diff to master and fix comments
While the DirectChainSpec tests would not need it, the EndToEnd
scenarios have a fulll hydra-node running where the chain context and
wallet still do load these files.
This was the last step to make all e2e tests green (two heads on the
same network turned out to be flaky).
@v0d1ch v0d1ch force-pushed the ensemble/stateless-observation-hydra-node branch from 6b5f8c4 to ead4dab Compare December 8, 2023 19:08
@v0d1ch v0d1ch merged commit 6e7b43a into master Dec 8, 2023
21 of 22 checks passed
@v0d1ch v0d1ch deleted the ensemble/stateless-observation-hydra-node branch December 8, 2023 21:27
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.

Stateless chain observation + tool
3 participants