mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
refactor: test/bench: dedup Build{Crediting,Spending}Transaction()
prototypes used in src/test/script_tests.cpp: - CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue = 0); - CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit); prototypes used in bench/verify_script.cpp: - CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey); - CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CMutableTransaction& txCredit); The more generic versions from the script tests are moved into a new file pair transaction_utils.cpp/h and the calls are adapted accordingly in the verify_script benchmark (passing the nValue of 1 explicitely for BuildCreditingTransaction(), passing empty scriptWitness explicitely and converting txCredit parameter to CTransaction in BuildSpendingTransaction()).
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user