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 offline-mode #1222

Merged
merged 26 commits into from
Dec 22, 2023
Merged

Refactor offline-mode #1222

merged 26 commits into from
Dec 22, 2023

Conversation

ch1bo
Copy link
Collaborator

@ch1bo ch1bo commented Dec 20, 2023

NOTE: The diff of this is big because it undoes a few unnecessary changes from #1118. See this diff for the actual changes of introducing offline-mode minimized by the refactoring of this branch.


  • 🎅 Adds command line option tests to retain interface.

  • 🎅 Defines a default for --node-id which makes the command line parser re-usable for offline-mode. There are other ways to do this, but all other options had defaults already.

  • 🎅 Avoids code duplication by modeling data ChainConfig = Offline .. | Direct ..

  • 🎅 Moves --hydra-scripts-tx-id into DirectChainConfig to simplify offline mode parameterization

  • 🎅 Simplifies conversion of ShelleyGenesis into Globals

  • 🎅 Extended tests about restarting offline mode nodes and simplify simulated head opening of offline mode.

  • 🎅 Simplify ticking logic and passed arguments to withOfflineChain by using projecting slot/time functions (factored from already existing code).


  • CHANGELOG updated or not needed
  • Documentation updated or not needed
  • Haddocks updated or not needed
  • No new TODOs introduced or explained herafter
    • Two XXXs about using cardano-api:internal functions. Should be resolved in a different PR / upstream.

@ch1bo ch1bo force-pushed the ch1bo/refactor-offline-mode branch from 079ccf5 to 5f2b7cf Compare December 20, 2023 07:29
Copy link

github-actions bot commented Dec 20, 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-22 17:52:49.463556885 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.35 3.99 0.46
2 4580 12.68 4.88 0.49
3 4774 14.68 5.63 0.52
5 5180 19.33 7.40 0.59
10 6182 30.39 11.59 0.75
41 12417 98.92 37.55 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 906 18.85 7.75 0.40
5 1279 26.90 11.27 0.51
10 2218 49.55 20.97 0.80
19 3903 99.43 41.75 1.43

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 480 21.78 8.51 0.41
2 114 590 32.43 12.82 0.53
3 171 700 44.85 17.89 0.67
4 226 810 60.00 24.06 0.84
5 283 920 79.38 31.91 1.06
6 339 1031 98.52 39.75 1.28

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 537 16.68 7.67 0.36
2 732 18.45 9.31 0.40
3 927 20.35 11.00 0.43
5 1296 23.81 14.22 0.50
10 2210 32.02 22.08 0.67
50 8903 98.25 83.31 1.94

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 565 20.22 8.95 0.40
2 742 22.26 10.67 0.44
3 931 24.20 12.37 0.48
5 1252 27.79 15.46 0.54
10 2109 37.31 23.79 0.72
43 7580 98.36 76.40 1.83

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 4316 18.98 8.17 0.55
2 4502 31.92 13.92 0.71
3 4658 47.38 20.80 0.89
4 4823 65.82 28.99 1.10
5 4986 87.29 38.51 1.35

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.05 3.37 0.42
5 1 57 4239 9.49 4.22 0.44
5 5 285 4376 14.40 7.27 0.51
5 10 570 4545 20.34 10.99 0.59
5 20 1139 4885 32.85 18.71 0.77
5 30 1709 5226 45.15 26.34 0.93
5 40 2277 5564 57.46 33.97 1.10
5 50 2839 5897 69.77 41.61 1.27
5 74 4209 6714 99.22 59.90 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-22 17:55:23.934216196 UTC

Baseline Scenario

Number of nodes 3
Number of txs 9000
Avg. Confirmation Time (ms) 24.075730456
P99 61.70004701000011ms
P95 32.95144549999999ms
P50 21.9815135ms
Number of Invalid txs 0

Baseline Scenario

Number of nodes 1
Number of txs 3000
Avg. Confirmation Time (ms) 4.428377134
P99 9.138614099999996ms
P95 6.066970099999997ms
P50 4.1473855ms
Number of Invalid txs 0

@ch1bo ch1bo force-pushed the ch1bo/refactor-offline-mode branch from 1f86e4f to e680ad0 Compare December 20, 2023 08:11
@ch1bo ch1bo self-assigned this Dec 20, 2023
@ch1bo ch1bo force-pushed the ch1bo/refactor-offline-mode branch from e680ad0 to 580ecdc Compare December 20, 2023 11:43
Copy link

github-actions bot commented Dec 20, 2023

Test Results

388 tests  +7   383 ✅ +7   21m 18s ⏱️ +23s
132 suites +2     5 💤 ±0 
  5 files   ±0     0 ❌ ±0 

Results for commit 00427a5. ± Comparison against base commit b0c94e7.

This pull request removes 3 and adds 10 tests. Note that renamed tests count towards both.
Hydra.Ledger.Cardano/Evaluate helpers ‑ slotNoFromUTCTime . slotNoToUTCTime === id
Hydra.Options/Hydra Node RunOptions ‑ parses --testned-magic option as a number
Hydra.Options/Hydra Node RunOptions ‑ parses with default node-id set
Hydra.Ledger.Cardano.Time ‑ roundtrip slotNoToUTCTime and slotNoFromUTCTime
Hydra.Ledger.Cardano.Time ‑ slotNoFromUTCTime works for any time
Hydra.Options/Hydra Node RunOptions ‑ parses --testnet-magic option as a number
Hydra.Options/Hydra Node RunOptions ‑ parses with default values
Hydra.Options/Hydra Node RunOptions ‑ switches to offline chain when using --initial-utxo
Hydra.Options/Hydra Node RunOptions/offline sub-command ‑ does parse --initial-utxo
Hydra.Options/Hydra Node RunOptions/offline sub-command ‑ does parse --ledger-genesis
Hydra.Options/Hydra Node RunOptions/offline sub-command ‑ does parse with defaults
Test.OfflineChain ‑ does not start on slot 0 with real genesis file
Test.OfflineChain ‑ does start on slot 0 with no genesis

♻️ This comment has been updated with latest results.

@ch1bo ch1bo force-pushed the ch1bo/refactor-offline-mode branch 4 times, most recently from 0d6ab99 to 2aecc74 Compare December 20, 2023 19:08
@ch1bo ch1bo marked this pull request as ready for review December 20, 2023 19:10
@ch1bo ch1bo changed the base branch from before-offline-mode to master December 20, 2023 19:10
@ch1bo ch1bo force-pushed the ch1bo/refactor-offline-mode branch from 2aecc74 to aa39f37 Compare December 20, 2023 19:12
@ch1bo ch1bo requested a review from a team December 20, 2023 19:16
@ch1bo
Copy link
Collaborator Author

ch1bo commented Dec 20, 2023

@cardenaso11 @rrruko @Quantumplation I can't request a review from you (I think I could, if I push this on your fork .. if you want?), but I would love your input on the clean up I did here.

@cardenaso11
Copy link
Contributor

@ch1bo sure thing!

@ch1bo ch1bo added this to the 0.15.0 milestone Dec 22, 2023
This is to ensure the refactor to be not breaking.
This was leading to a lot of duplication in the Hydra.Node.Run and
HydraNode modules. Instead we should be able to switch quite easily
between multiple `ChainConfig` variants.
This makes re-use of the `runOptionsParser` possible for "offline mode".

Also it simplifies the tests, of which two were even broken hidden by
the fact that a missing --node-id was the reason of a failing parse.
This emulates a sub-command, although the offline-mode would also just
be available directly on the command-line without sub-commands.
Also moved the ChainConfig schema away from the api schema as it was not
referenced there.
By extending the arbitrary instances, tests were checking that the
toArgs matches what can be parsed.
This does not change the command line interface, but makes end-to-end
tests of the offline chain not need to come up with this parameter.
This is now implemented using the cardano-api:internal lib and using
those defaults.

In general it is questionable if those 'globals' are actually used by the
cardano-ledger we embed (as we only use a subset of the ledger rules).
We should never use record fields as functions.
Both, 'run' and 'initEnvironment' need to switch on the configured chain
layer to do the plumbing correctly. Especially in the 'run' function
this avoids a lot of duplication.
This allows (and forces) us to be more specific in type signatures of
the two chain layers and other locations.
This was not entirely clear from the previous test and ensures we do not
break anything when simplifying the implementation.
This handle is not needed if we simulate an opening head in
initializeStateIfOffline.
This also removes redundant parameters about head id, head seed and
contestation period. All of them are irrelevant in offline mode and can
be hard-coded.
This is only needed when we are "opening" the head the first time
This is to ensure it works correctly before refactoring anything.
This now loads the given genesis file / uses the defaults just the same
as before, but does not require the additional 'globals' argument.
So far these functions have only be used with fixture system start /slot
lengths, but we can also use them in the withOfflineChain as it is
currently using a consensus interpreter with a never forking summary.
As we have been using a neverForksSummary, the interpreter would never
fail and the conversion is effectively the same as doing the math
directly. Hence, the newly factored out functions slotNoFromUTCTime and
slotNoToUTCTime should provide the same semantics and much more readable
code.
@v0d1ch v0d1ch merged commit f5b1e4f into master Dec 22, 2023
21 checks passed
@v0d1ch v0d1ch deleted the ch1bo/refactor-offline-mode branch December 22, 2023 20:05
@ch1bo ch1bo linked an issue Jan 16, 2024 that may be closed by this pull request
@abailly-iohk abailly-iohk mentioned this pull request Jan 17, 2024
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.

Offline mode
4 participants