Skip to content

Commit 52fd151

Browse files
committed
test: drop scriptPubKeyIn arg from CreateNewBlock
This removes the temporary overload added in the previous commit. Also drop unneeded custom coinbase output scripts.
1 parent ff41b9e commit 52fd151

15 files changed

+85
-62
lines changed

src/bench/block_assemble.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@
2020
#include <memory>
2121
#include <vector>
2222

23+
using node::BlockAssembler;
24+
2325
static void AssembleBlock(benchmark::Bench& bench)
2426
{
2527
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
2628

2729
CScriptWitness witness;
2830
witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);
31+
BlockAssembler::Options options;
32+
options.coinbase_output_script = P2WSH_OP_TRUE;
2933

3034
// Collect some loose transactions that spend the coinbases of our mined blocks
3135
constexpr size_t NUM_BLOCKS{200};
3236
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
3337
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
3438
CMutableTransaction tx;
35-
tx.vin.emplace_back(MineBlock(test_setup->m_node, P2WSH_OP_TRUE));
39+
tx.vin.emplace_back(MineBlock(test_setup->m_node, options));
3640
tx.vin.back().scriptWitness = witness;
3741
tx.vout.emplace_back(1337, P2WSH_OP_TRUE);
3842
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
@@ -48,19 +52,20 @@ static void AssembleBlock(benchmark::Bench& bench)
4852
}
4953

5054
bench.run([&] {
51-
PrepareBlock(test_setup->m_node, P2WSH_OP_TRUE);
55+
PrepareBlock(test_setup->m_node, options);
5256
});
5357
}
5458
static void BlockAssemblerAddPackageTxns(benchmark::Bench& bench)
5559
{
5660
FastRandomContext det_rand{true};
5761
auto testing_setup{MakeNoLogFileContext<TestChain100Setup>()};
5862
testing_setup->PopulateMempool(det_rand, /*num_transactions=*/1000, /*submit=*/true);
59-
node::BlockAssembler::Options assembler_options;
63+
BlockAssembler::Options assembler_options;
6064
assembler_options.test_block_validity = false;
65+
assembler_options.coinbase_output_script = P2WSH_OP_TRUE;
6166

6267
bench.run([&] {
63-
PrepareBlock(testing_setup->m_node, P2WSH_OP_TRUE, assembler_options);
68+
PrepareBlock(testing_setup->m_node, assembler_options);
6469
});
6570
}
6671

src/node/miner.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,11 @@ class BlockAssembler
172172
/** Construct a new block template */
173173
std::unique_ptr<CBlockTemplate> CreateNewBlock();
174174

175-
/** Temporary overload for tests */
176-
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn)
177-
{
178-
m_options.coinbase_output_script = scriptPubKeyIn;
179-
return CreateNewBlock();
180-
};
181-
182175
inline static std::optional<int64_t> m_last_block_num_txs{};
183176
inline static std::optional<int64_t> m_last_block_weight{};
184177

185178
private:
186-
// TODO: make const again
187-
Options m_options;
179+
const Options m_options;
188180

189181
// utility functions
190182
/** Clear the block's state and prepare for assembling a new block */

src/test/blockfilter_index_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
6767
const std::vector<CMutableTransaction>& txns,
6868
const CScript& scriptPubKey)
6969
{
70-
BlockAssembler::Options options;
71-
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get(), options}.CreateNewBlock(scriptPubKey);
70+
BlockAssembler::Options options;
71+
options.coinbase_output_script = scriptPubKey;
72+
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get(), options}.CreateNewBlock();
7273
CBlock& block = pblocktemplate->block;
7374
block.hashPrevBlock = prev->GetBlockHash();
7475
block.nTime = prev->nTime + 1;

src/test/fuzz/mini_miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ FUZZ_TARGET(mini_miner_selection, .init = initialize_miner)
174174
miner_options.blockMinFeeRate = target_feerate;
175175
miner_options.nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
176176
miner_options.test_block_validity = false;
177+
miner_options.coinbase_output_script = CScript() << OP_0;
177178

178179
node::BlockAssembler miner{g_setup->m_node.chainman->ActiveChainstate(), &pool, miner_options};
179180
node::MiniMiner mini_miner{pool, outpoints};
180181
assert(mini_miner.IsReadyToCalculate());
181182

182-
CScript spk_placeholder = CScript() << OP_0;
183183
// Use BlockAssembler as oracle. BlockAssembler and MiniMiner should select the same
184184
// transactions, stopping once packages do not meet target_feerate.
185-
const auto blocktemplate{miner.CreateNewBlock(spk_placeholder)};
185+
const auto blocktemplate{miner.CreateNewBlock()};
186186
mini_miner.BuildMockTemplate(target_feerate);
187187
assert(!mini_miner.IsReadyToCalculate());
188188
auto mock_template_txids = mini_miner.GetMockTemplateTxids();

src/test/fuzz/package_eval.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <validation.h>
2222
#include <validationinterface.h>
2323

24+
using node::BlockAssembler;
2425
using node::NodeContext;
2526

2627
namespace {
@@ -42,8 +43,11 @@ void initialize_tx_pool()
4243
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
4344
g_setup = testing_setup.get();
4445

46+
BlockAssembler::Options options;
47+
options.coinbase_output_script = P2WSH_EMPTY;
48+
4549
for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
46-
COutPoint prevout{MineBlock(g_setup->m_node, P2WSH_EMPTY)};
50+
COutPoint prevout{MineBlock(g_setup->m_node, options)};
4751
if (i < COINBASE_MATURITY) {
4852
// Remember the txids to avoid expensive disk access later on
4953
g_outpoints_coinbase_init_mature.push_back(prevout);

src/test/fuzz/process_message.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void initialize_process_message()
4545
{.extra_args = {"-txreconciliation"}});
4646
g_setup = testing_setup.get();
4747
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
48-
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
48+
MineBlock(g_setup->m_node, {});
4949
}
5050
g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
5151
}

src/test/fuzz/process_messages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void initialize_process_messages()
3535
{.extra_args = {"-txreconciliation"}});
3636
g_setup = testing_setup.get();
3737
for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
38-
MineBlock(g_setup->m_node, CScript() << OP_TRUE);
38+
MineBlock(g_setup->m_node, {});
3939
}
4040
g_setup->m_node.validation_signals->SyncWithValidationInterfaceQueue();
4141
}

src/test/fuzz/tx_pool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ void initialize_tx_pool()
4545
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
4646
g_setup = testing_setup.get();
4747

48+
BlockAssembler::Options options;
49+
options.coinbase_output_script = P2WSH_OP_TRUE;
50+
4851
for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
49-
COutPoint prevout{MineBlock(g_setup->m_node, P2WSH_OP_TRUE)};
52+
COutPoint prevout{MineBlock(g_setup->m_node, options)};
5053
// Remember the txids to avoid expensive disk access later on
5154
auto& outpoints = i < COINBASE_MATURITY ?
5255
g_outpoints_coinbase_init_mature :
@@ -98,7 +101,7 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Cha
98101
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
99102
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
100103
auto assembler = BlockAssembler{chainstate, &tx_pool, options};
101-
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
104+
auto block_template = assembler.CreateNewBlock();
102105
Assert(block_template->block.vtx.size() >= 1);
103106
}
104107
const auto info_all = tx_pool.infoAll();

src/test/fuzz/utxo_total_supply.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <util/chaintype.h>
1818
#include <validation.h>
1919

20+
using node::BlockAssembler;
21+
2022
FUZZ_TARGET(utxo_total_supply)
2123
{
2224
/** The testing setup that creates a chainman only (no chainstate) */
@@ -36,9 +38,11 @@ FUZZ_TARGET(utxo_total_supply)
3638
LOCK(chainman.GetMutex());
3739
return chainman.ActiveHeight();
3840
};
41+
BlockAssembler::Options options;
42+
options.coinbase_output_script = CScript() << OP_FALSE;
3943
const auto PrepareNextBlock = [&]() {
4044
// Use OP_FALSE to avoid BIP30 check from hitting early
41-
auto block = PrepareBlock(node, CScript{} << OP_FALSE);
45+
auto block = PrepareBlock(node, options);
4246
// Replace OP_FALSE with OP_TRUE
4347
{
4448
CMutableTransaction tx{*block->vtx.back()};

0 commit comments

Comments
 (0)