Skip to content

Commit c3e111a

Browse files
committed
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.
1 parent 9ad7cd2 commit c3e111a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/script/interpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ enum
139139

140140
// Making unknown public key versions (in BIP 342 scripts) non-standard
141141
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE = (1U << 20),
142+
143+
// Constants to point to the highest flag in use. Add new flags above this line.
144+
//
145+
SCRIPT_VERIFY_END_MARKER
142146
};
143147

144148
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);

src/test/txvalidationcache_tests.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
109109
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
110110
{
111111
PrecomputedTransactionData txdata;
112-
// If we add many more flags, this loop can get too expensive, but we can
113-
// rewrite in the future to randomly pick a set of flags to evaluate.
114-
for (uint32_t test_flags=0; test_flags < (1U << 16); test_flags += 1) {
112+
113+
FastRandomContext insecure_rand(true);
114+
115+
for (int count = 0; count < 10000; ++count) {
115116
TxValidationState state;
117+
118+
// Randomly selects flag combinations
119+
uint32_t test_flags = (uint32_t) insecure_rand.randrange((SCRIPT_VERIFY_END_MARKER - 1) << 1);
120+
116121
// Filter out incompatible flag choices
117122
if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) {
118123
// CLEANSTACK requires P2SH and WITNESS, see VerifyScript() in

0 commit comments

Comments
 (0)