aboutsummaryrefslogtreecommitdiff
path: root/src/bench/verify_script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bench/verify_script.cpp')
-rw-r--r--src/bench/verify_script.cpp40
1 files changed, 3 insertions, 37 deletions
diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp
index 4891c57b3a..c9947f192e 100644
--- a/src/bench/verify_script.cpp
+++ b/src/bench/verify_script.cpp
@@ -10,44 +10,10 @@
#include <script/script.h>
#include <script/standard.h>
#include <streams.h>
+#include <test/lib/transaction_utils.h>
#include <array>
-// FIXME: Dedup with BuildCreditingTransaction in test/script_tests.cpp.
-static CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey)
-{
- CMutableTransaction txCredit;
- txCredit.nVersion = 1;
- txCredit.nLockTime = 0;
- txCredit.vin.resize(1);
- txCredit.vout.resize(1);
- txCredit.vin[0].prevout.SetNull();
- txCredit.vin[0].scriptSig = CScript() << CScriptNum(0) << CScriptNum(0);
- txCredit.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
- txCredit.vout[0].scriptPubKey = scriptPubKey;
- txCredit.vout[0].nValue = 1;
-
- return txCredit;
-}
-
-// FIXME: Dedup with BuildSpendingTransaction in test/script_tests.cpp.
-static CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMutableTransaction& txCredit)
-{
- CMutableTransaction txSpend;
- txSpend.nVersion = 1;
- txSpend.nLockTime = 0;
- txSpend.vin.resize(1);
- txSpend.vout.resize(1);
- txSpend.vin[0].prevout.hash = txCredit.GetHash();
- txSpend.vin[0].prevout.n = 0;
- txSpend.vin[0].scriptSig = scriptSig;
- txSpend.vin[0].nSequence = CTxIn::SEQUENCE_FINAL;
- txSpend.vout[0].scriptPubKey = CScript();
- txSpend.vout[0].nValue = txCredit.vout[0].nValue;
-
- return txSpend;
-}
-
// Microbenchmark for verification of a basic P2WPKH script. Can be easily
// modified to measure performance of other types of scripts.
static void VerifyScriptBench(benchmark::State& state)
@@ -71,8 +37,8 @@ static void VerifyScriptBench(benchmark::State& state)
CScript scriptPubKey = CScript() << witnessversion << ToByteVector(pubkeyHash);
CScript scriptSig;
CScript witScriptPubkey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(pubkeyHash) << OP_EQUALVERIFY << OP_CHECKSIG;
- const CMutableTransaction& txCredit = BuildCreditingTransaction(scriptPubKey);
- CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, txCredit);
+ const CMutableTransaction& txCredit = BuildCreditingTransaction(scriptPubKey, 1);
+ CMutableTransaction txSpend = BuildSpendingTransaction(scriptSig, CScriptWitness(), CTransaction(txCredit));
CScriptWitness& witness = txSpend.vin[0].scriptWitness;
witness.stack.emplace_back();
key.Sign(SignatureHash(witScriptPubkey, txSpend, 0, SIGHASH_ALL, txCredit.vout[0].nValue, SigVersion::WITNESS_V0), witness.stack.back());