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

Speed up TransactionSpec.signTransaction. #3211

Merged
merged 6 commits into from
Mar 31, 2022

Conversation

jonathanknowles
Copy link
Contributor

@jonathanknowles jonathanknowles commented Mar 31, 2022

Issue Number

ADP-1485

Summary

This PR:

  • adjusts checkSubsetOf to use set-based lookups instead of repeated list traversals.
  • adjusts signTransaction properties to only test 10 examples per property, rather than 100.

This results in a substantial reduction in total time required to run the signTransaction tests:

Before:  530 ± 10 seconds (over 4 runs)
After:    48 ±  2 seconds (over 4 runs)

Additional Improvements

This PR also:

  • introduces function spec_forAllEras to eliminate some repetition in the signTransaction spec .
  • makes the output of signTransaction property tests more readable, so that the name of each property is written once as a section header, rather than being repeated for every single era. (The individual eras are still as subsections.)
Cardano.Wallet.Shelley.Transaction                                                         
  Sign transaction                                                                                                                                                                        signTransaction adds reward account witness when necessary    
      ByronEra                                                                             
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra (2144ms)
        +++ OK, passed 10 tests.
      AllegraEra (2143ms)
        +++ OK, passed 10 tests.
      MaryEra (2142ms)
        +++ OK, passed 10 tests.
      AlonzoEra (2142ms)
        +++ OK, passed 10 tests.
    signTransaction adds extra key witnesses when necessary
      ByronEra
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra
        +++ OK, passed 10 tests (100% feature not supported in ShelleyEra).
      AllegraEra
        +++ OK, passed 10 tests (100% feature not supported in AllegraEra).
      MaryEra
        +++ OK, passed 10 tests (100% feature not supported in MaryEra).
      AlonzoEra (686ms)
        +++ OK, passed 10 tests.

This commit attempts to tidy up parts of `TransactionSpec` where the
style has diverged greatly from our agreed-upon team coding style.

In particular, this commit tries to restore:

  - 80 column lines
  -  4 column indents

It doesn't fix everything, but at least it's now easily viewable on an
80-column-wide editor window.
This also slightly improves the readability of the test suite output, so
that the name of each property is written as a section header, rather
than being repeated for all eras.
…rsals.

With rough benchmarking, this makes tests run around 15% faster.
These properties take a long time to run (over 10 minutes in total), so
we can get by (for the moment) by testing fewer examples.

We remove some calls to `checkCoverage` where there are no corresponding
calls to `cover`, as this interferes with the action of `withMaxSuccess`.
@jonathanknowles
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Mar 31, 2022
3211: Speed up `TransactionSpec.signTransaction`. r=jonathanknowles a=jonathanknowles

## Issue Number

ADP-1485

## Summary

This PR:

- adjusts `checkSubsetOf` to use set-based lookups instead of repeated list traversals.
- adjusts `signTransaction` properties to only test 10 examples per property, rather than 100.

This results in a substantial reduction in total time required to run the `signTransaction` tests:

```
Before:  530 ± 10 seconds (over 4 runs)
After:    48 ±  2 seconds (over 4 runs)
```

## Additional Improvements

This PR also:

- introduces function `spec_forAllEras` to eliminate some repetition in the `signTransaction` spec .
- makes the output of `signTransaction` property tests more readable, so that the name of each property is written once as a section header, rather than being repeated for every single era. (The individual eras are still as subsections.)

```hs
Cardano.Wallet.Shelley.Transaction                                                         
  Sign transaction                                                                                                                                                                        signTransaction adds reward account witness when necessary    
      ByronEra                                                                             
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra (2144ms)
        +++ OK, passed 10 tests.
      AllegraEra (2143ms)
        +++ OK, passed 10 tests.
      MaryEra (2142ms)
        +++ OK, passed 10 tests.
      AlonzoEra (2142ms)
        +++ OK, passed 10 tests.
    signTransaction adds extra key witnesses when necessary
      ByronEra
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra
        +++ OK, passed 10 tests (100% feature not supported in ShelleyEra).
      AllegraEra
        +++ OK, passed 10 tests (100% feature not supported in AllegraEra).
      MaryEra
        +++ OK, passed 10 tests (100% feature not supported in MaryEra).
      AlonzoEra (686ms)
        +++ OK, passed 10 tests.
```

Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 31, 2022

Build failed:

Test failure:

Failures:

  test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs:2225:13:
  1) Cardano.Wallet.Shelley.Transaction.balanceTransaction, when passed unresolved inputs, may fail
       *** Gave up! Passed only 99 tests; 7 discarded tests (14% unknown txins).

  To rerun use: --match "/Cardano.Wallet.Shelley.Transaction/balanceTransaction/when passed unresolved inputs/may fail/"

Randomized with seed 1053383965

This exact failure is also reproducible in master (at commit 57635e1). So it's not related to this PR.

#3183 / ADP-1590

@jonathanknowles
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Mar 31, 2022
3211: Speed up `TransactionSpec.signTransaction`. r=jonathanknowles a=jonathanknowles

## Issue Number

ADP-1485

## Summary

This PR:

- adjusts `checkSubsetOf` to use set-based lookups instead of repeated list traversals.
- adjusts `signTransaction` properties to only test 10 examples per property, rather than 100.

This results in a substantial reduction in total time required to run the `signTransaction` tests:

```
Before:  530 ± 10 seconds (over 4 runs)
After:    48 ±  2 seconds (over 4 runs)
```

## Additional Improvements

This PR also:

- introduces function `spec_forAllEras` to eliminate some repetition in the `signTransaction` spec .
- makes the output of `signTransaction` property tests more readable, so that the name of each property is written once as a section header, rather than being repeated for every single era. (The individual eras are still as subsections.)

```hs
Cardano.Wallet.Shelley.Transaction                                                         
  Sign transaction                                                                                                                                                                        signTransaction adds reward account witness when necessary    
      ByronEra                                                                             
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra (2144ms)
        +++ OK, passed 10 tests.
      AllegraEra (2143ms)
        +++ OK, passed 10 tests.
      MaryEra (2142ms)
        +++ OK, passed 10 tests.
      AlonzoEra (2142ms)
        +++ OK, passed 10 tests.
    signTransaction adds extra key witnesses when necessary
      ByronEra
        +++ OK, passed 10 tests (100% feature not supported in ByronEra).
      ShelleyEra
        +++ OK, passed 10 tests (100% feature not supported in ShelleyEra).
      AllegraEra
        +++ OK, passed 10 tests (100% feature not supported in AllegraEra).
      MaryEra
        +++ OK, passed 10 tests (100% feature not supported in MaryEra).
      AlonzoEra (686ms)
        +++ OK, passed 10 tests.
```

Co-authored-by: Jonathan Knowles <jonathan.knowles@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 31, 2022

Build failed:

  src/Test/Integration/Scenario/API/Shelley/StakePools.hs:554:5:
  1) API Specifications, SHELLEY_STAKE_POOLS, STAKE_POOLS_JOIN_01 - Can rejoin another stakepool
       uncaught exception: IOException of type UserError
       user error (next delegation should contain exactly one element)

  To rerun use: --match "/API Specifications/SHELLEY_STAKE_POOLS/STAKE_POOLS_JOIN_01 - Can rejoin another stakepool/"

Randomized with seed 2095126825

#2497

@Anviking
Copy link
Member

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 31, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 566f1f2 into master Mar 31, 2022
@iohk-bors iohk-bors bot deleted the jonathanknowles/adjust-sign-transaction-tests branch March 31, 2022 10:40
WilliamKingNoel-Bot pushed a commit that referenced this pull request Mar 31, 2022
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