mirror of https://github.com/bitcoin/bitcoin
[refactor] Remove BlockAssembler m_mempool member
Instead, pass the mempool pointer as an argument to CreateNewBlock and pass that on to addPackageTxs. Before, addPackageTxs had access to both the m_mempool member and the passed in mempool, which could be confusing.
This commit is contained in:
parent
1105aa46dd
commit
a323388036
|
@ -64,9 +64,8 @@ static BlockAssembler::Options ClampOptions(BlockAssembler::Options options)
|
|||
return options;
|
||||
}
|
||||
|
||||
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options)
|
||||
BlockAssembler::BlockAssembler(Chainstate& chainstate, const Options& options)
|
||||
: chainparams{chainstate.m_chainman.GetParams()},
|
||||
m_mempool{mempool},
|
||||
m_chainstate{chainstate},
|
||||
m_options{ClampOptions(options)}
|
||||
{
|
||||
|
@ -87,8 +86,8 @@ static BlockAssembler::Options ConfiguredOptions()
|
|||
return options;
|
||||
}
|
||||
|
||||
BlockAssembler::BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool)
|
||||
: BlockAssembler(chainstate, mempool, ConfiguredOptions()) {}
|
||||
BlockAssembler::BlockAssembler(Chainstate& chainstate)
|
||||
: BlockAssembler(chainstate, ConfiguredOptions()) {}
|
||||
|
||||
void BlockAssembler::resetBlock()
|
||||
{
|
||||
|
@ -103,7 +102,7 @@ void BlockAssembler::resetBlock()
|
|||
nFees = 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, const CTxMemPool* mempool)
|
||||
{
|
||||
const auto time_start{SteadyClock::now()};
|
||||
|
||||
|
@ -138,9 +137,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||
|
||||
int nPackagesSelected = 0;
|
||||
int nDescendantsUpdated = 0;
|
||||
if (m_mempool) {
|
||||
LOCK(m_mempool->cs);
|
||||
addPackageTxs(*m_mempool, nPackagesSelected, nDescendantsUpdated);
|
||||
if (mempool) {
|
||||
LOCK(mempool->cs);
|
||||
addPackageTxs(*mempool, nPackagesSelected, nDescendantsUpdated);
|
||||
}
|
||||
|
||||
const auto time_1{SteadyClock::now()};
|
||||
|
|
|
@ -149,7 +149,6 @@ private:
|
|||
int64_t m_lock_time_cutoff;
|
||||
|
||||
const CChainParams& chainparams;
|
||||
const CTxMemPool* const m_mempool;
|
||||
Chainstate& m_chainstate;
|
||||
|
||||
public:
|
||||
|
@ -161,11 +160,11 @@ public:
|
|||
bool test_block_validity{true};
|
||||
};
|
||||
|
||||
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool);
|
||||
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options);
|
||||
explicit BlockAssembler(Chainstate& chainstate);
|
||||
explicit BlockAssembler(Chainstate& chainstate, const Options& options);
|
||||
|
||||
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, const CTxMemPool* mempool);
|
||||
|
||||
inline static std::optional<int64_t> m_last_block_num_txs{};
|
||||
inline static std::optional<int64_t> m_last_block_weight{};
|
||||
|
|
|
@ -158,7 +158,7 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
|
|||
{
|
||||
UniValue blockHashes(UniValue::VARR);
|
||||
while (nGenerate > 0 && !chainman.m_interrupt) {
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler{chainman.ActiveChainstate(), &mempool}.CreateNewBlock(coinbase_script));
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler{chainman.ActiveChainstate()}.CreateNewBlock(coinbase_script, &mempool));
|
||||
if (!pblocktemplate.get())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
||||
|
||||
|
@ -370,7 +370,7 @@ static RPCHelpMan generateblock()
|
|||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
std::unique_ptr<CBlockTemplate> blocktemplate(BlockAssembler{chainman.ActiveChainstate(), nullptr}.CreateNewBlock(coinbase_script));
|
||||
std::unique_ptr<CBlockTemplate> blocktemplate(BlockAssembler{chainman.ActiveChainstate()}.CreateNewBlock(coinbase_script, nullptr));
|
||||
if (!blocktemplate) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
|
||||
}
|
||||
|
@ -807,7 +807,7 @@ static RPCHelpMan getblocktemplate()
|
|||
|
||||
// Create new block
|
||||
CScript scriptDummy = CScript() << OP_TRUE;
|
||||
pblocktemplate = BlockAssembler{active_chainstate, &mempool}.CreateNewBlock(scriptDummy);
|
||||
pblocktemplate = BlockAssembler{active_chainstate}.CreateNewBlock(scriptDummy, &mempool);
|
||||
if (!pblocktemplate)
|
||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev,
|
|||
const std::vector<CMutableTransaction>& txns,
|
||||
const CScript& scriptPubKey)
|
||||
{
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(scriptPubKey);
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler{m_node.chainman->ActiveChainstate()}.CreateNewBlock(scriptPubKey, m_node.mempool.get());
|
||||
CBlock& block = pblocktemplate->block;
|
||||
block.hashPrevBlock = prev->GetBlockHash();
|
||||
block.nTime = prev->nTime + 1;
|
||||
|
|
|
@ -169,14 +169,14 @@ FUZZ_TARGET(mini_miner_selection, .init = initialize_miner)
|
|||
miner_options.nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
||||
miner_options.test_block_validity = false;
|
||||
|
||||
node::BlockAssembler miner{g_setup->m_node.chainman->ActiveChainstate(), &pool, miner_options};
|
||||
node::BlockAssembler miner{g_setup->m_node.chainman->ActiveChainstate(), miner_options};
|
||||
node::MiniMiner mini_miner{pool, outpoints};
|
||||
assert(mini_miner.IsReadyToCalculate());
|
||||
|
||||
CScript spk_placeholder = CScript() << OP_0;
|
||||
// Use BlockAssembler as oracle. BlockAssembler and MiniMiner should select the same
|
||||
// transactions, stopping once packages do not meet target_feerate.
|
||||
const auto blocktemplate{miner.CreateNewBlock(spk_placeholder)};
|
||||
const auto blocktemplate{miner.CreateNewBlock(spk_placeholder, &pool)};
|
||||
mini_miner.BuildMockTemplate(target_feerate);
|
||||
assert(!mini_miner.IsReadyToCalculate());
|
||||
auto mock_template_txids = mini_miner.GetMockTemplateTxids();
|
||||
|
|
|
@ -94,8 +94,8 @@ void Finish(FuzzedDataProvider& fuzzed_data_provider, MockedTxPool& tx_pool, Cha
|
|||
BlockAssembler::Options options;
|
||||
options.nBlockMaxWeight = fuzzed_data_provider.ConsumeIntegralInRange(0U, MAX_BLOCK_WEIGHT);
|
||||
options.blockMinFeeRate = CFeeRate{ConsumeMoney(fuzzed_data_provider, /*max=*/COIN)};
|
||||
auto assembler = BlockAssembler{chainstate, &tx_pool, options};
|
||||
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE);
|
||||
auto assembler = BlockAssembler{chainstate, options};
|
||||
auto block_template = assembler.CreateNewBlock(CScript{} << OP_TRUE, &tx_pool);
|
||||
Assert(block_template->block.vtx.size() >= 1);
|
||||
}
|
||||
const auto info_all = tx_pool.infoAll();
|
||||
|
|
|
@ -49,7 +49,7 @@ struct MinerTestingSetup : public TestingSetup {
|
|||
m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node));
|
||||
return *m_node.mempool;
|
||||
}
|
||||
BlockAssembler AssemblerForTest(CTxMemPool& tx_mempool);
|
||||
BlockAssembler AssemblerForTest();
|
||||
};
|
||||
} // namespace miner_tests
|
||||
|
||||
|
@ -57,13 +57,13 @@ BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup)
|
|||
|
||||
static CFeeRate blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
||||
|
||||
BlockAssembler MinerTestingSetup::AssemblerForTest(CTxMemPool& tx_mempool)
|
||||
BlockAssembler MinerTestingSetup::AssemblerForTest()
|
||||
{
|
||||
BlockAssembler::Options options;
|
||||
|
||||
options.nBlockMaxWeight = MAX_BLOCK_WEIGHT;
|
||||
options.blockMinFeeRate = blockMinFeeRate;
|
||||
return BlockAssembler{m_node.chainman->ActiveChainstate(), &tx_mempool, options};
|
||||
return BlockAssembler{m_node.chainman->ActiveChainstate(), options};
|
||||
}
|
||||
|
||||
constexpr static struct {
|
||||
|
@ -132,7 +132,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||
Txid hashHighFeeTx = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(50000).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
|
||||
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4U);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
|
||||
|
@ -153,7 +153,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
|
||||
Txid hashLowFeeTx = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(feeToUse).FromTx(tx));
|
||||
pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
// Verify that the free tx and the low fee tx didn't get selected
|
||||
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
|
||||
|
@ -167,7 +167,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
|
||||
hashLowFeeTx = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(feeToUse + 2).FromTx(tx));
|
||||
pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
|
||||
|
@ -189,7 +189,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
|
||||
Txid hashLowFeeTx2 = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
|
||||
pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
|
||||
// Verify that this tx isn't selected.
|
||||
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
||||
|
@ -202,7 +202,7 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
|
|||
tx.vin[0].prevout.n = 1;
|
||||
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
|
||||
tx_mempool.addUnchecked(entry.Fee(10000).FromTx(tx));
|
||||
pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 9U);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
LOCK(tx_mempool.cs);
|
||||
|
||||
// Just to make sure we can still make simple blocks
|
||||
auto pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
auto pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_CHECK(pblocktemplate);
|
||||
|
||||
// block sigops > limit: 1000 CHECKMULTISIG + 1
|
||||
|
@ -245,7 +245,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx.vin[0].prevout.hash = hash;
|
||||
}
|
||||
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-blk-sigops"));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool), std::runtime_error, HasReason("bad-blk-sigops"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -262,7 +262,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx_mempool.addUnchecked(entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
}
|
||||
BOOST_CHECK(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -286,7 +286,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx_mempool.addUnchecked(entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
}
|
||||
BOOST_CHECK(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -296,7 +296,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
// orphan in tx_mempool, template creation fails
|
||||
hash = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).FromTx(tx));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -317,7 +317,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; // First txn output + fresh coinbase - new txn fee
|
||||
hash = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(HIGHERFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
||||
BOOST_CHECK(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -333,7 +333,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
// give it a fee so it'll get mined
|
||||
tx_mempool.addUnchecked(entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
|
||||
// Should throw bad-cb-multiple
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-cb-multiple"));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool), std::runtime_error, HasReason("bad-cb-multiple"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -350,7 +350,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx.vout[0].scriptPubKey = CScript() << OP_2;
|
||||
hash = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(HIGHFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(true).FromTx(tx));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -370,7 +370,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
next->BuildSkip();
|
||||
m_node.chainman->ActiveChain().SetTip(*next);
|
||||
}
|
||||
BOOST_CHECK(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
// Extend to a 210000-long block chain.
|
||||
while (m_node.chainman->ActiveChain().Tip()->nHeight < 210000) {
|
||||
CBlockIndex* prev = m_node.chainman->ActiveChain().Tip();
|
||||
|
@ -382,7 +382,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
next->BuildSkip();
|
||||
m_node.chainman->ActiveChain().SetTip(*next);
|
||||
}
|
||||
BOOST_CHECK(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
|
||||
// invalid p2sh txn in tx_mempool, template creation fails
|
||||
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
||||
|
@ -399,7 +399,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
hash = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(LOWFEE).Time(Now<NodeSeconds>()).SpendsCoinbase(false).FromTx(tx));
|
||||
// Should throw block-validation-failed
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
|
||||
BOOST_CHECK_EXCEPTION(AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool), std::runtime_error, HasReason("block-validation-failed"));
|
||||
|
||||
// Delete the dummy blocks again.
|
||||
while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {
|
||||
|
@ -501,7 +501,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
|
||||
BOOST_CHECK(!TestSequenceLocks(CTransaction{tx}, tx_mempool)); // Sequence locks fail
|
||||
|
||||
auto pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
auto pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_CHECK(pblocktemplate);
|
||||
|
||||
// None of the of the absolute height/time locked tx should have made
|
||||
|
@ -517,7 +517,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
|
|||
m_node.chainman->ActiveChain().Tip()->nHeight++;
|
||||
SetMockTime(m_node.chainman->ActiveChain().Tip()->GetMedianTimePast() + 1);
|
||||
|
||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool));
|
||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5U);
|
||||
}
|
||||
|
||||
|
@ -584,7 +584,7 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
|
|||
Txid hashFreeGrandchild = tx.GetHash();
|
||||
tx_mempool.addUnchecked(entry.Fee(0).SpendsCoinbase(false).FromTx(tx));
|
||||
|
||||
auto pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey);
|
||||
auto pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, &tx_mempool);
|
||||
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashFreeParent);
|
||||
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashFreePrioritisedTx);
|
||||
|
@ -606,9 +606,8 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
CScript scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate;
|
||||
|
||||
CTxMemPool& tx_mempool{*m_node.mempool};
|
||||
// Simple block creation, nothing special yet:
|
||||
BOOST_CHECK(pblocktemplate = AssemblerForTest(tx_mempool).CreateNewBlock(scriptPubKey));
|
||||
BOOST_CHECK(pblocktemplate = AssemblerForTest().CreateNewBlock(scriptPubKey, Assert(m_node.mempool.get())));
|
||||
|
||||
// We can't make transactions until we have inputs
|
||||
// Therefore, load 110 blocks :)
|
||||
|
|
|
@ -20,7 +20,7 @@ static void mineBlock(const node::NodeContext& node, std::chrono::seconds block_
|
|||
{
|
||||
auto curr_time = GetTime<std::chrono::seconds>();
|
||||
SetMockTime(block_time); // update time so the block is created with it
|
||||
CBlock block = node::BlockAssembler{node.chainman->ActiveChainstate(), nullptr}.CreateNewBlock(CScript() << OP_TRUE)->block;
|
||||
CBlock block = node::BlockAssembler{node.chainman->ActiveChainstate()}.CreateNewBlock(CScript() << OP_TRUE, nullptr)->block;
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, node.chainman->GetConsensus())) ++block.nNonce;
|
||||
block.fChecked = true; // little speedup
|
||||
SetMockTime(curr_time); // process block at current time
|
||||
|
|
|
@ -112,8 +112,8 @@ std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coi
|
|||
const BlockAssembler::Options& assembler_options)
|
||||
{
|
||||
auto block = std::make_shared<CBlock>(
|
||||
BlockAssembler{Assert(node.chainman)->ActiveChainstate(), Assert(node.mempool.get()), assembler_options}
|
||||
.CreateNewBlock(coinbase_scriptPubKey)
|
||||
BlockAssembler{Assert(node.chainman)->ActiveChainstate(), assembler_options}
|
||||
.CreateNewBlock(coinbase_scriptPubKey, Assert(node.mempool.get()))
|
||||
->block);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
|
|
@ -370,7 +370,7 @@ CBlock TestChain100Setup::CreateBlock(
|
|||
const CScript& scriptPubKey,
|
||||
Chainstate& chainstate)
|
||||
{
|
||||
CBlock block = BlockAssembler{chainstate, nullptr}.CreateNewBlock(scriptPubKey)->block;
|
||||
CBlock block = BlockAssembler{chainstate}.CreateNewBlock(scriptPubKey, nullptr)->block;
|
||||
|
||||
Assert(block.vtx.size() == 1);
|
||||
for (const CMutableTransaction& tx : txns) {
|
||||
|
|
|
@ -65,7 +65,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
|
|||
static int i = 0;
|
||||
static uint64_t time = Params().GenesisBlock().nTime;
|
||||
|
||||
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(CScript{} << i++ << OP_TRUE);
|
||||
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate()}.CreateNewBlock(CScript{} << i++ << OP_TRUE, m_node.mempool.get());
|
||||
auto pblock = std::make_shared<CBlock>(ptemplate->block);
|
||||
pblock->hashPrevBlock = prev_hash;
|
||||
pblock->nTime = ++time;
|
||||
|
@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE(witness_commitment_index)
|
|||
LOCK(Assert(m_node.chainman)->GetMutex());
|
||||
CScript pubKey;
|
||||
pubKey << 1 << OP_TRUE;
|
||||
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate(), m_node.mempool.get()}.CreateNewBlock(pubKey);
|
||||
auto ptemplate = BlockAssembler{m_node.chainman->ActiveChainstate()}.CreateNewBlock(pubKey, m_node.mempool.get());
|
||||
CBlock pblock = ptemplate->block;
|
||||
|
||||
CTxOut witness;
|
||||
|
|
Loading…
Reference in New Issue