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

Validate txs in model #1309

Merged
merged 14 commits into from
Feb 20, 2024
Merged

Validate txs in model #1309

merged 14 commits into from
Feb 20, 2024

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Feb 14, 2024

The 'evaluateTx' function used at the core of validating transactions in the MockChain can fail in two ways, once when translating the transaction and then each validator individually.

🔬 The MockChain now evaluates transactions on submission and only includes valid transactions in blocks.

🔬 This also fixes race conditions in MockChain when updating the chain variable versus invoking handlers.

🔬 Fixes the model in various ways to pass now the transaction checking. Mostly it was requiring every party to observe consequences of an action before having them act.

💡 One situation was very interesting: The tests were finding an issue when a commit transaction was actually observed by the sending node, but another node sending an abort was not yet valid, because they reimbursed value was not matching. i.e. the aborting node has not yet seen & processed the commit, but the chain included it already. This is actually something that can happen and a user would need to retry here. However we opted to just not model this and instead require every node to observe a commit before continuing.

🔬 Improved shrinking on generated actions. This should already reduce error situation complexity, but more work can be done here.

🔬 Some fixes on the test scenarios / dynamic logic properties.


  • CHANGELOG updated or not needed

  • Documentation updated or not needed

  • Haddocks updated or not needed

  • No new TODOs introduced or explained herafter

    • One XXX about reworking the MockChain to be more like a real chain (would be too big to be in scope, but this is something we really should do)
    • One XXX of adding slot validation to the used scriptLedger.

Copy link

github-actions bot commented Feb 14, 2024

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 2024-02-19 17:44:21.488652526 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 4432 10.25 3.95 0.46
2 4634 12.81 4.93 0.49
3 4834 14.92 5.73 0.52
5 5237 19.50 7.47 0.59
10 6242 30.30 11.55 0.75
41 12475 99.12 37.64 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 594 11.37 4.44 0.30
2 783 15.04 6.07 0.35
3 968 18.85 7.75 0.40
5 1336 26.90 11.27 0.51
10 2284 49.55 20.97 0.80
19 3961 99.43 41.75 1.43

Cost of CollectCom Transaction

Parties UTxO (bytes) Tx size % max Mem % max CPU Min fee ₳
1 57 544 21.82 8.53 0.41
2 114 658 34.26 13.49 0.55
3 171 764 46.05 18.33 0.69
4 226 874 59.20 23.77 0.84
5 283 984 80.38 32.25 1.08
6 337 1095 91.76 37.29 1.21

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 626 16.68 7.70 0.37
2 727 18.09 8.98 0.39
3 823 18.87 9.88 0.41
5 1275 23.16 13.71 0.49
10 1888 29.47 19.86 0.61
50 8092 92.09 78.23 1.81

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 639 20.22 8.97 0.41
2 754 21.76 10.31 0.43
3 931 23.87 12.05 0.47
5 1267 27.21 15.06 0.53
10 2086 36.22 22.89 0.70
47 7458 99.26 77.21 1.84

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 4305 19.07 8.20 0.55
2 4468 32.00 13.94 0.71
3 4582 46.30 20.25 0.87
4 4663 62.14 27.16 1.05
5 4696 70.19 30.44 1.14
6 4950 99.51 43.68 1.49

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 4265 7.42 3.10 0.42
5 1 57 4299 8.86 3.96 0.44
5 5 284 4434 13.35 6.83 0.50
5 10 570 4605 19.92 10.81 0.59
5 20 1137 4942 32.43 18.53 0.76
5 30 1708 5286 44.52 26.07 0.93
5 40 2275 5622 56.41 33.53 1.10
5 50 2840 5958 68.72 41.16 1.26
5 75 4269 6812 99.95 60.45 1.69

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 2024-02-19 17:46:41.038023204 UTC

Baseline Scenario

Number of nodes 3
Number of txs 9000
Avg. Confirmation Time (ms) 21.969569642
P99 114.76751814ms
P95 31.905349499999996ms
P50 18.82988ms
Number of Invalid txs 0

Baseline Scenario

Number of nodes 1
Number of txs 3000
Avg. Confirmation Time (ms) 3.737942815
P99 5.220594209999991ms
P95 4.3150974ms
P50 3.6499575ms
Number of Invalid txs 0

@ch1bo ch1bo self-assigned this Feb 14, 2024
@ch1bo ch1bo force-pushed the validate-txs-in-model branch 12 times, most recently from 4a05bcf to e1ebdbe Compare February 19, 2024 10:20
@v0d1ch v0d1ch force-pushed the validate-txs-in-model branch from 5acbc45 to 170b35d Compare February 19, 2024 11:12
Copy link

github-actions bot commented Feb 19, 2024

Test Results

416 tests  +1   409 ✅ +1   13m 23s ⏱️ +29s
139 suites ±0     7 💤 ±0 
  5 files   ±0     0 ❌ ±0 

Results for commit b0a91e2. ± Comparison against base commit 8c6e4bf.

♻️ This comment has been updated with latest results.

ch1bo and others added 6 commits February 19, 2024 14:33
The 'evaluateTx' function used at the core of validating transactions in
the MockChain can fail in two ways, once when translating the
transaction and then each validator individually.
No idea why, but this seems to shrink less and not invalidating a
precondition on one of the model tests.
We added a threadDelay in the performAbort and realised this fixed
one of the issues we had, pinpointing the fact that there's some race
conditions in the abort logic: It's perfectly possible that a party
Aborts while other parties Commited and the Abort fails.

We don't model this behaviour for now, but this could be done using
"Negative" actions
@v0d1ch v0d1ch force-pushed the validate-txs-in-model branch from 170b35d to f7c07b0 Compare February 19, 2024 13:34
@ch1bo ch1bo force-pushed the validate-txs-in-model branch from bc32477 to a3c8432 Compare February 19, 2024 17:01
@ch1bo ch1bo marked this pull request as ready for review February 19, 2024 17:15
ch1bo and others added 5 commits February 19, 2024 18:26
This will result in less spam on errors, at the cost of creating temp
files on each model test failure run.
We need to ensure that the mock chain ledger is already updated with the
blocks utxo before invoking the handlers as they might want to submit
transactions using this utxo right away.

This also uses throwSTM to actually throw an exception and not to error
when showing the trace.
Thel MockChain behaves quite different than the real cardano chain
interfaced through a cardano-node (see FIXME)
When we want to commit we need to take the utxo that was already
pre-seeded for our party and not just some arbitrary value not known
to our mock chain.
If two RollbackAndForward actions are generated next to each other
then submitTx fails. Waiting for a small amount of time to pass so
that the needed utxo is present fixes this problem.

Ideally the fix would be: Correctly implemented rollbacks in the mock
chain but perhaps this is enough for now.
There could be situations with race conditions when multiple
RollbackAndForward actions were generated by the model.

By using the correct "view" onto the chain, the mock chain can evaluate
transactions more consistently.
@ch1bo ch1bo force-pushed the validate-txs-in-model branch 2 times, most recently from 1878a26 to c28b4e5 Compare February 19, 2024 17:40
Moved and DRYed usage of scriptLedger and introduced function
'collectTransactions' to emulate the dropping transaction behavior as it
was already intended before (see comment).

As we are checking transactions now on submission and fail there, this
is not really needed, but it is more consistent to include only
transactions in the mock chain "blocks" which were valid at time of
evaluation.
@ch1bo ch1bo force-pushed the validate-txs-in-model branch from c28b4e5 to b0a91e2 Compare February 19, 2024 17:41
@ch1bo ch1bo requested a review from a team February 19, 2024 17:42
@ch1bo ch1bo removed their assignment Feb 19, 2024
@ch1bo ch1bo merged commit 39d0226 into master Feb 20, 2024
21 checks passed
@ch1bo ch1bo deleted the validate-txs-in-model branch February 20, 2024 08:34
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.

3 participants