mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
Merge #19775: test: Activate segwit in TestChain100Setup
fad84b7e14
test: Activate segwit in TestChain100Setup (MarcoFalke)fa11ff2980
test: Pass empty tx pool to block assembler (MarcoFalke)fa96574b0d
test: Move doxygen comment to header (MarcoFalke) Pull request description: This fixes not only a TODO in the code, but also prevents a never ending source of uninitialized reads. E.g. * #18376 * https://github.com/bitcoin/bitcoin/pull/19704#issuecomment-678259092 * ... ACKs for top commit: jnewbery: utACKfad84b7e14
Tree-SHA512: 64cf16a59656d49e022b603f3b06441ceae35a33a4253b4382bc8a89a56e08ad5412c8fa734d0fc7b58586f40ea6d57b348a3b4838bc6890a41ae2ec3902e378
This commit is contained in:
commit
92735e45ba
2 changed files with 17 additions and 31 deletions
|
@ -196,49 +196,34 @@ TestingSetup::~TestingSetup()
|
|||
|
||||
TestChain100Setup::TestChain100Setup()
|
||||
{
|
||||
// CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests.
|
||||
// TODO: fix the code to support SegWit blocks.
|
||||
gArgs.ForceSetArg("-segwitheight", "432");
|
||||
// Need to recreate chainparams
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
|
||||
// Generate a 100-block chain:
|
||||
coinbaseKey.MakeNewKey(true);
|
||||
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||
for (int i = 0; i < COINBASE_MATURITY; i++)
|
||||
{
|
||||
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||
for (int i = 0; i < COINBASE_MATURITY; i++) {
|
||||
std::vector<CMutableTransaction> noTxns;
|
||||
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);
|
||||
m_coinbase_txns.push_back(b.vtx[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new block with just given transactions, coinbase paying to
|
||||
// scriptPubKey, and try to add it to the current chain.
|
||||
CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(*m_node.mempool, chainparams).CreateNewBlock(scriptPubKey);
|
||||
CBlock& block = pblocktemplate->block;
|
||||
CTxMemPool empty_pool;
|
||||
CBlock block = BlockAssembler(empty_pool, chainparams).CreateNewBlock(scriptPubKey)->block;
|
||||
|
||||
// Replace mempool-selected txns with just coinbase plus passed-in txns:
|
||||
block.vtx.resize(1);
|
||||
for (const CMutableTransaction& tx : txns)
|
||||
Assert(block.vtx.size() == 1);
|
||||
for (const CMutableTransaction& tx : txns) {
|
||||
block.vtx.push_back(MakeTransactionRef(tx));
|
||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot
|
||||
{
|
||||
LOCK(cs_main);
|
||||
unsigned int extraNonce = 0;
|
||||
IncrementExtraNonce(&block, ::ChainActive().Tip(), extraNonce);
|
||||
}
|
||||
RegenerateCommitments(block);
|
||||
|
||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
|
||||
|
||||
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
|
||||
Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
|
||||
|
||||
CBlock result = block;
|
||||
return result;
|
||||
return block;
|
||||
}
|
||||
|
||||
TestChain100Setup::~TestChain100Setup()
|
||||
|
@ -246,8 +231,8 @@ TestChain100Setup::~TestChain100Setup()
|
|||
gArgs.ForceSetArg("-segwitheight", "0");
|
||||
}
|
||||
|
||||
|
||||
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) {
|
||||
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx)
|
||||
{
|
||||
return FromTx(MakeTransactionRef(tx));
|
||||
}
|
||||
|
||||
|
|
|
@ -102,15 +102,16 @@ class CBlock;
|
|||
struct CMutableTransaction;
|
||||
class CScript;
|
||||
|
||||
//
|
||||
// Testing fixture that pre-creates a
|
||||
// 100-block REGTEST-mode block chain
|
||||
//
|
||||
/**
|
||||
* Testing fixture that pre-creates a 100-block REGTEST-mode block chain
|
||||
*/
|
||||
struct TestChain100Setup : public RegTestingSetup {
|
||||
TestChain100Setup();
|
||||
|
||||
// Create a new block with just given transactions, coinbase paying to
|
||||
// scriptPubKey, and try to add it to the current chain.
|
||||
/**
|
||||
* Create a new block with just given transactions, coinbase paying to
|
||||
* scriptPubKey, and try to add it to the current chain.
|
||||
*/
|
||||
CBlock CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns,
|
||||
const CScript& scriptPubKey);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue