aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlucash-dev <lucash.dev@gmail.com>2018-06-24 18:11:41 -0700
committerlucash-dev <lucash.dev@gmail.com>2020-10-15 13:45:30 -0700
commitc3e111a7daf5800026dda4455c737de0412528f1 (patch)
tree44597b1f1511f941206751b7ec915b457ac44ff8
parent9ad7cd2887abf5f91495337a2458560de10b4f69 (diff)
downloadbitcoin-c3e111a7daf5800026dda4455c737de0412528f1.tar.xz
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.
-rw-r--r--src/script/interpreter.h4
-rw-r--r--src/test/txvalidationcache_tests.cpp11
2 files changed, 12 insertions, 3 deletions
diff --git a/src/script/interpreter.h b/src/script/interpreter.h
index c0c2b012c6..db4ebc49da 100644
--- a/src/script/interpreter.h
+++ b/src/script/interpreter.h
@@ -139,6 +139,10 @@ enum
// Making unknown public key versions (in BIP 342 scripts) non-standard
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20),
+
+ // Constants to point to the highest flag in use. Add new flags above this line.
+ //
+ SCRIPT_VERIFY_END_MARKER
};
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp
index bed2ba3608..a0d3330459 100644
--- a/src/test/txvalidationcache_tests.cpp
+++ b/src/test/txvalidationcache_tests.cpp
@@ -109,10 +109,15 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
{
PrecomputedTransactionData txdata;
- // If we add many more flags, this loop can get too expensive, but we can
- // rewrite in the future to randomly pick a set of flags to evaluate.
- for (uint32_t test_flags=0; test_flags < (1U << 16); test_flags += 1) {
+
+ FastRandomContext insecure_rand(true);
+
+ for (int count = 0; count < 10000; ++count) {
TxValidationState state;
+
+ // Randomly selects flag combinations
+ uint32_t test_flags = (uint32_t) insecure_rand.randrange((SCRIPT_VERIFY_END_MARKER - 1) << 1);
+
// Filter out incompatible flag choices
if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) {
// CLEANSTACK requires P2SH and WITNESS, see VerifyScript() in