6#include <chainparams.h>
12#include <validation.h>
31 return (tip) ?
TipBlock{tip->GetBlockHash(), tip->GetBlockTime(), tip->nHeight} :
38 const CScript& coinbase_out_script)
45 coinbase_tx.
vin.resize(1);
46 coinbase_tx.
vin[0].prevout.SetNull();
47 coinbase_tx.
vout.resize(2);
48 coinbase_tx.
vout[0].scriptPubKey = coinbase_out_script;
49 coinbase_tx.
vout[0].nValue = 49 *
COIN;
50 coinbase_tx.
vin[0].scriptSig =
CScript() << ++tip.tip_height <<
OP_0;
51 coinbase_tx.
vout[1].scriptPubKey = coinbase_out_script;
52 coinbase_tx.
vout[1].nValue = 1 *
COIN;
58 block.
nTime = ++tip.prev_block_time;
67 context.
chainman->ActiveChain().SetTip(*pindex);
86 SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
87 CWallet wallet{test_setup->m_node.chain.get(),
"", CreateMockableWalletDatabase()};
90 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
91 wallet.SetupDescriptorScriptPubKeyMans();
95 const auto dest{getNewDestination(
wallet, output_type)};
98 const auto& params =
Params();
100 unsigned int chain_size = 5000;
101 for (
unsigned int i = 0; i < chain_size; ++i) {
116 filter_coins.
max_count = preset_inputs->num_of_internal_inputs;
119 for (
int i=0; i < preset_inputs->num_of_internal_inputs; i++) {
120 const auto& coin{res.coins.at(output_type)[i]};
121 target += coin.txout.nValue;
122 coin_control.
Select(coin.outpoint);
128 std::vector<wallet::CRecipient> recipients = {{dest, target,
true}};
132 const auto& tx_res = CreateTransaction(
wallet, recipients, std::nullopt, coin_control);
141 SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
142 CWallet wallet{test_setup->m_node.chain.get(),
"", CreateMockableWalletDatabase()};
145 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
146 wallet.SetupDescriptorScriptPubKeyMans();
150 std::vector<CScript> dest_wallet;
151 dest_wallet.reserve(output_type.size());
152 for (
auto type : output_type) {
157 const auto& params =
Params();
158 unsigned int chain_size = 1000;
159 for (
unsigned int i = 0; i < chain_size / dest_wallet.size(); ++i) {
160 for (
const auto& dest : dest_wallet) {
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
#define BENCHMARK(n, priority_level)
const CChainParams & Params()
Return the currently selected parameters.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const CBlock & GenesisBlock() const
Serialized script, used inside transaction inputs and outputs.
Main entry point to nanobench's benchmarking facility.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Bench & epochIterations(uint64_t numIters) noexcept
Sets exactly the number of iterations for each epoch.
PreselectedInput & Select(const COutPoint &outpoint)
Lock-in the given output for spending.
bool m_allow_other_inputs
If true, the selection process can add extra unselected inputs from the wallet while requires all sel...
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex *index, const CBlock *data)
Return data from block index.
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
CoinsResult AvailableCoins(const CWallet &wallet, const CCoinControl *coinControl, std::optional< CFeeRate > feerate, const CoinFilterParams ¶ms)
Populate the CoinsResult struct with vectors of available COutputs, organized by OutputType.
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
A mutable version of CTransaction.
std::vector< CTxOut > vout
NodeContext struct containing references to chain state and connection state.
std::unique_ptr< ChainstateManager > chainman
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
static void WalletCreateTxUsePresetInputsAndCoinSelection(benchmark::Bench &bench)
static void WalletAvailableCoins(benchmark::Bench &bench)
TipBlock getTip(const CChainParams ¶ms, const node::NodeContext &context)
void generateFakeBlock(const CChainParams ¶ms, const node::NodeContext &context, CWallet &wallet, const CScript &coinbase_out_script)
static void WalletCreateTx(benchmark::Bench &bench, const OutputType output_type, bool allow_other_inputs, std::optional< PreSelectInputs > preset_inputs)
static void AvailableCoins(benchmark::Bench &bench, const std::vector< OutputType > &output_type)
static void WalletCreateTxUseOnlyPresetInputs(benchmark::Bench &bench)