[tests] improvements to slow unit tests #13050

pull lucash-dev wants to merge 8 commits into bitcoin:master from lucash-dev:slow-unit-tests-improvement changing 4 files +48 −34
  1. lucash-dev commented at 7:11 pm on April 21, 2018: contributor

    This PR speeds up a few unit tests, as a partial fix to issue #10026, with some optimizations and reducing some number of validations to sane levels:

    • checkinputs_test: reduced in about 50%.
    • CreateNewBlock_validity: reduced about 17%.
    • knapsack_solver_test: reduced about 30%.
    • test_CheckQueue_Correct_Random: about 80%

    More details in each commit.

    No changes should affect executable production code (though there is a change in interpreter.h, including a constant).

  2. fanquake added the label Tests on Apr 21, 2018
  3. laanwj commented at 9:19 am on April 24, 2018: member
    Travis issue was an intermittent issue, it’s passing now.
  4. lucash-dev renamed this:
    [WIP] [tests] improvements to slow unit tests
    [tests] improvements to slow unit tests
    on May 13, 2018
  5. lucash-dev renamed this:
    [tests] improvements to slow unit tests
    [WIP] [tests] improvements to slow unit tests
    on May 13, 2018
  6. lucash-dev renamed this:
    [WIP] [tests] improvements to slow unit tests
    [tests] improvements to slow unit tests
    on May 15, 2018
  7. in src/test/transaction_tests.cpp:453 in 851df67c72 outdated
    448@@ -449,10 +449,17 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
    449         mtx.vout[i].scriptPubKey = CScript() << OP_1;
    450     }
    451 
    452+    // create a single CTransaction to be used in generating all signatures
    453+    CTransaction txToConst(mtx);
    


    MarcoFalke commented at 2:24 pm on May 30, 2018:
    Just noting that this is redundant (and not required after #13309)
  8. lucash-dev commented at 2:14 am on May 31, 2018: contributor
    Reversed commit that was redundant with #13309 .
  9. laanwj referenced this in commit 36fc8052f6 on May 31, 2018
  10. speed up of test_big_witness_transaction by reusing of CTransaction.
    test_big_witness_transaction was spending most of time converting CMutableTransaction to Transaction, which involves recalculating hashes. This means the time complexity for providing witnesses for the 4500 inputs had a O(n2) component. This change replaces the call to SignSignature (which always creates a new CTransaction) with calls to lower level functions ProduceSignature and UpdateTransaction, which allows for reuse of a single CTransaction. This reduces execution time in about 70%.
    29da2e9f02
  11. speed up of tx_validationcache_tests by reusing of CTransaction.
    This commit uses the a similar strategy as used for speeding up test_big_witness_transaction, that is, reusing the same CTransaction for several calls. Attains a speed up of about 15%.
    384bcd116c
  12. Reduced number of validations in `tx_validationcache_tests` to keep the run time reasonable.
    Following a suggestion in the comments, changed `ValidateCheckInputsForAllFlags` from testing all possible flag combinations to testing a random subset. Also created a new enum constant for the highest flag, so that this test doesn’t keep testing an incomplete subset in case a new flag is added.
    92b880d4be
  13. small optimization in CreateNewBlock_validity, reusing txs
    The two tests that check for the sigops limit with 1001 multisig transactions now reuse the same transactions, instead of creating the exact same two times.
    0d1a6ab4ca
  14. Speed up knapsack_solver_test by not recreating wallet 100 times.
    Moved the code for creating the wallet out of the 100-times repetition loop, for the most time-consuming tests.
    8cc436ffdb
  15. changed test_CheckQueue_Correct_Random to take reasonable time.
    test_CheckQueue_Correct_Random was taking too long a time, and concentrating most tests in ranges close to 100,000. Changed to a more evenly distribution between 0 and 100,000 and reduced to about 40 random amounts of checks.
    f4f2180760
  16. Revert "speed up of test_big_witness_transaction by reusing of CTransaction."
    This reverts commit 525b2f0117e0469a6154defd985019395b53dfb5.
    c10d3d5a8b
  17. Revert "small optimization in CreateNewBlock_validity, reusing txs"
    This reverts commit 0d1a6ab4cad23e147189302ce8d85794d698f1a7.
    614b354867
  18. in src/test/miner_tests.cpp:291 in 7c54ea04dd outdated
    289+        hash = cTx.GetHash();
    290         bool spendsCoinbase = i == 0; // only first tx spends coinbase
    291         // If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
    292-        mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
    293-        tx.vin[0].prevout.hash = hash;
    294+        mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(cTx));
    


    MarcoFalke commented at 9:52 am on May 31, 2018:
    I believe this will calculate all hashes again, which is why I removed this method, which is why this no longer compiles.

    lucash-dev commented at 5:36 pm on June 2, 2018:
    Actually in the original code it doesn’t since each CMutableTransaction is converted to a CTransaction just once, and then the hash is cached and copying the CTransaction just copies the cached hash. Removing the method that accepts CTransaction makes that optimization impossible. Anyway, since the method is no longer there, I’ll remove this commit and think of some other way of speeding up things in a separate PR.

    MarcoFalke commented at 6:32 pm on June 2, 2018:
    Yes, you are right. Feel free to reintroduce the method if you think it was helpful. However, I think if you keep a vector of CTransactionRef as multisig_txs instead your patch should work just fine?
  19. in src/test/txvalidationcache_tests.cpp:108 in 384bcd116c outdated
    104@@ -105,6 +105,8 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
    105 static void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache)
    106 {
    107     PrecomputedTransactionData txdata(tx);
    108+    CTransaction cTx(tx);
    


    MarcoFalke commented at 7:47 pm on June 5, 2018:

    in commit 384bcd116c7bdfbe7ed851a739a8d8c8809d4d12 ( speed up of tx_validationcache_tests by reusing of CTransaction), it seems you can instead just adjust the signature:

    0-static void ValidateCheckInputsForAllFlags(CMutableTransaction &tx, uint32_t failing_flags, bool add_to_cache)
    1+static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache)
    

    (Might need a rebase on master)

    Also, to I suggest splitting up the commits into separate pull request to make it easier to review and merge the changes independently. (You could start with this change, since it seems a clear and trivial win)


    lucash-dev commented at 4:26 am on June 6, 2018:
    Thanks for the suggestions, Marco. I will try them, and also split the PR.
  20. MarcoFalke commented at 7:48 pm on June 5, 2018: member
    :( GitHub is hiding my review again
  21. lucash-dev commented at 1:51 am on June 7, 2018: contributor
    Closing this PR as it will be split into smaller ones.
  22. lucash-dev closed this on Jun 7, 2018

  23. MarcoFalke referenced this in commit 3d3d8ae3a0 on Jun 7, 2018
  24. laanwj referenced this in commit e3fec3cfa8 on Sep 11, 2018
  25. UdjinM6 referenced this in commit 3d00f2c563 on Jun 19, 2021
  26. UdjinM6 referenced this in commit 8c8b51e5f5 on Jun 19, 2021
  27. UdjinM6 referenced this in commit 7a5b4f3aee on Jun 24, 2021
  28. UdjinM6 referenced this in commit d02a223c97 on Jun 24, 2021
  29. UdjinM6 referenced this in commit f7c2a3844d on Jun 26, 2021
  30. UdjinM6 referenced this in commit 5bb511dd46 on Jun 26, 2021
  31. UdjinM6 referenced this in commit 87c9b5c73e on Jun 26, 2021
  32. UdjinM6 referenced this in commit a13dee3fa7 on Jun 26, 2021
  33. PastaPastaPasta referenced this in commit 02b0442fda on Jun 27, 2021
  34. PastaPastaPasta referenced this in commit 7642625575 on Jun 28, 2021
  35. PastaPastaPasta referenced this in commit 9c23705d84 on Jun 28, 2021
  36. UdjinM6 referenced this in commit 3d4017d30d on Jun 28, 2021
  37. UdjinM6 referenced this in commit e52bf1371b on Jun 28, 2021
  38. PastaPastaPasta referenced this in commit a023431fbc on Jun 29, 2021
  39. Munkybooty referenced this in commit 5b5a76e4eb on Jul 7, 2021
  40. Munkybooty referenced this in commit c2d9621ec7 on Jul 8, 2021
  41. Munkybooty referenced this in commit e427d09b5e on Jul 9, 2021
  42. Munkybooty referenced this in commit 3e388c6c91 on Jul 11, 2021
  43. MarcoFalke referenced this in commit fd557ceb88 on Jul 24, 2021
  44. sidhujag referenced this in commit 52375cf41a on Jul 28, 2021
  45. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me