* Creates a test block containing transactions with the following properties: * - Each transaction has the same number of inputs and outputs * - All Taproot inputs use simple key path spends (no script path spends) * - All signatures use SIGHASH_ALL (default sighash) * - Each transaction spends all outputs from the previous transaction */
| 34 | * - Each transaction spends all outputs from the previous transaction |
| 35 | */ |
| 36 | CBlock CreateTestBlock( |
| 37 | TestChain100Setup& test_setup, |
| 38 | const std::vector<CKey>& keys, |
| 39 | const std::vector<CTxOut>& outputs, |
| 40 | int num_txs = 1000) |
| 41 | { |
| 42 | Chainstate& chainstate{test_setup.m_node.chainman->ActiveChainstate()}; |
| 43 | |
| 44 | const WitnessV1Taproot coinbase_taproot{XOnlyPubKey(test_setup.coinbaseKey.GetPubKey())}; |
| 45 | |
| 46 | // Create the outputs that will be spent in the first transaction of the test block |
| 47 | // Doing this in a separate block excludes the validation of its inputs from the benchmark |
| 48 | auto& coinbase_to_spend{test_setup.m_coinbase_txns[0]}; |
| 49 | const auto [first_tx, _]{test_setup.CreateValidTransaction( |
| 50 | {coinbase_to_spend}, |
| 51 | {COutPoint(coinbase_to_spend->GetHash(), 0)}, |
| 52 | chainstate.m_chain.Height() + 1, keys, outputs, {}, {})}; |
| 53 | const CScript coinbase_spk{GetScriptForDestination(coinbase_taproot)}; |
| 54 | test_setup.CreateAndProcessBlock({first_tx}, coinbase_spk); |
| 55 | |
| 56 | std::vector<CMutableTransaction> txs; |
| 57 | txs.reserve(num_txs); |
| 58 | CTransactionRef tx_to_spend{MakeTransactionRef(first_tx)}; |
| 59 | for (int i{0}; i < num_txs; i++) { |
| 60 | std::vector<COutPoint> inputs; |
| 61 | inputs.reserve(outputs.size()); |
| 62 | |
| 63 | for (size_t j{0}; j < outputs.size(); j++) { |
| 64 | inputs.emplace_back(tx_to_spend->GetHash(), j); |
| 65 | } |
| 66 | |
| 67 | const auto [tx, _]{test_setup.CreateValidTransaction( |
| 68 | {tx_to_spend}, inputs, chainstate.m_chain.Height() + 1, keys, outputs, {}, {})}; |
| 69 | txs.emplace_back(tx); |
| 70 | tx_to_spend = MakeTransactionRef(tx); |
| 71 | } |
| 72 | |
| 73 | // Coinbase output can use any output type as it is not spent and will not change the benchmark |
| 74 | return test_setup.CreateBlock(txs, coinbase_spk); |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Creates key pairs and corresponding outputs for the benchmark transactions. |
no test coverage detected