Skip to content

Commit 8109f00

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#13533: [tests] Reduced number of validations in tx_validationcache_tests
c3e111a Reduced number of validations in `tx_validationcache_tests` to keep the run time reasonable. (lucash-dev) Pull request description: 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. Timing for `checkinputs_test`: ``` Before: 6.8s After: 3.7s ---------------- Saved: 3.1s (45%) ``` This PR was split from bitcoin#13050. Also see bitcoin#10026. ACKs for top commit: leonardojobim: tACK bitcoin@c3e111a. kallewoof: ACK c3e111a theStack: re-ACK c3e111a Tree-SHA512: bef49645bdd4f61ec73cc77a9f028b95d9856db9446d2e7fc9a48867a6f0e94c2c9f150cb771a30fe852db0efb0a1bd15d38b00d712651793ccb59ff6157a7b4
1 parent ad3086c commit 8109f00

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
@@ -101,6 +101,10 @@ enum : uint32_t {
101101
// Making OP_CODESEPARATOR and FindAndDelete fail
102102
//
103103
SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16),
104+
105+
// Constants to point to the highest flag in use. Add new flags above this line.
106+
//
107+
SCRIPT_VERIFY_END_MARKER
104108
};
105109

106110
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
@@ -108,10 +108,15 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
108108
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t failing_flags, bool add_to_cache) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
109109
{
110110
PrecomputedTransactionData txdata;
111-
// If we add many more flags, this loop can get too expensive, but we can
112-
// rewrite in the future to randomly pick a set of flags to evaluate.
113-
for (uint32_t test_flags=0; test_flags < (1U << 16); test_flags += 1) {
111+
112+
FastRandomContext insecure_rand(true);
113+
114+
for (int count = 0; count < 10000; ++count) {
114115
TxValidationState state;
116+
117+
// Randomly selects flag combinations
118+
uint32_t test_flags = (uint32_t) insecure_rand.randrange((SCRIPT_VERIFY_END_MARKER - 1) << 1);
119+
115120
// Filter out incompatible flag choices
116121
if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) {
117122
// CLEANSTACK requires P2SH, see VerifyScript() in

0 commit comments

Comments
 (0)