Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115613
D6436.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Subscribers
None
D6436.diff
View Options
diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp
--- a/src/test/blockfilter_index_tests.cpp
+++ b/src/test/blockfilter_index_tests.cpp
@@ -57,10 +57,11 @@
static CBlock CreateBlock(const CBlockIndex *prev,
const std::vector<CMutableTransaction> &txns,
- const CScript &scriptPubKey) {
+ const CScript &scriptPubKey,
+ const CTxMemPool &mempool) {
const Config &config = GetConfig();
std::unique_ptr<CBlockTemplate> pblocktemplate =
- BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey);
+ BlockAssembler(config, mempool).CreateNewBlock(scriptPubKey);
CBlock &block = pblocktemplate->block;
block.hashPrevBlock = prev->GetBlockHash();
block.nTime = prev->nTime + 1;
@@ -84,13 +85,14 @@
static bool BuildChain(const CBlockIndex *pindex,
const CScript &coinbase_script_pub_key, size_t length,
- std::vector<std::shared_ptr<CBlock>> &chain) {
+ std::vector<std::shared_ptr<CBlock>> &chain,
+ const CTxMemPool &mempool) {
std::vector<CMutableTransaction> no_txns;
chain.resize(length);
for (auto &block : chain) {
block = std::make_shared<CBlock>(
- CreateBlock(pindex, no_txns, coinbase_script_pub_key));
+ CreateBlock(pindex, no_txns, coinbase_script_pub_key, mempool));
CBlockHeader header = block->GetBlockHeader();
CValidationState state;
@@ -164,8 +166,10 @@
CScript coinbase_script_pub_key =
GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
std::vector<std::shared_ptr<CBlock>> chainA, chainB;
- BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainA));
- BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainB));
+ BOOST_REQUIRE(
+ BuildChain(tip, coinbase_script_pub_key, 10, chainA, ::g_mempool));
+ BOOST_REQUIRE(
+ BuildChain(tip, coinbase_script_pub_key, 10, chainB, ::g_mempool));
// Check that new blocks on chain A get indexed.
uint256 chainA_last_header = last_header;
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -234,7 +234,8 @@
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2);
}
-void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) {
+void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg,
+ const CTxMemPool &mempool) {
GlobalConfig config;
config.SetMaxBlockSize(eb);
@@ -245,7 +246,7 @@
<< OP_CHECKSIG;
std::unique_ptr<CBlockTemplate> pblocktemplate =
- BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey);
+ BlockAssembler(config, mempool).CreateNewBlock(scriptPubKey);
CBlock *pblock = &pblocktemplate->block;
@@ -263,10 +264,10 @@
// Coinbase scriptSig has to contains the correct EB value
// converted to MB, rounded down to the first decimal
BOOST_AUTO_TEST_CASE(CheckCoinbase_EB) {
- TestCoinbaseMessageEB(1000001, "/EB1.0/");
- TestCoinbaseMessageEB(2000000, "/EB2.0/");
- TestCoinbaseMessageEB(8000000, "/EB8.0/");
- TestCoinbaseMessageEB(8320000, "/EB8.3/");
+ TestCoinbaseMessageEB(1000001, "/EB1.0/", ::g_mempool);
+ TestCoinbaseMessageEB(2000000, "/EB2.0/", ::g_mempool);
+ TestCoinbaseMessageEB(8000000, "/EB8.0/", ::g_mempool);
+ TestCoinbaseMessageEB(8320000, "/EB8.3/", ::g_mempool);
}
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
@@ -684,10 +685,11 @@
fCheckpointsEnabled = true;
}
-void CheckBlockMaxSize(const Config &config, uint64_t size, uint64_t expected) {
+void CheckBlockMaxSize(const Config &config, const CTxMemPool &mempool,
+ uint64_t size, uint64_t expected) {
gArgs.ForceSetArg("-blockmaxsize", std::to_string(size));
- BlockAssembler ba(config, g_mempool);
+ BlockAssembler ba(config, mempool);
BOOST_CHECK_EQUAL(ba.GetMaxGeneratedBlockSize(), expected);
}
@@ -699,27 +701,30 @@
// Test around historical 1MB (plus one byte because that's mandatory)
config.SetMaxBlockSize(ONE_MEGABYTE + 1);
- CheckBlockMaxSize(config, 0, 1000);
- CheckBlockMaxSize(config, 1000, 1000);
- CheckBlockMaxSize(config, 1001, 1001);
- CheckBlockMaxSize(config, 12345, 12345);
-
- CheckBlockMaxSize(config, ONE_MEGABYTE - 1001, ONE_MEGABYTE - 1001);
- CheckBlockMaxSize(config, ONE_MEGABYTE - 1000, ONE_MEGABYTE - 1000);
- CheckBlockMaxSize(config, ONE_MEGABYTE - 999, ONE_MEGABYTE - 999);
- CheckBlockMaxSize(config, ONE_MEGABYTE, ONE_MEGABYTE - 999);
+ CheckBlockMaxSize(config, ::g_mempool, 0, 1000);
+ CheckBlockMaxSize(config, ::g_mempool, 1000, 1000);
+ CheckBlockMaxSize(config, ::g_mempool, 1001, 1001);
+ CheckBlockMaxSize(config, ::g_mempool, 12345, 12345);
+
+ CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 1001,
+ ONE_MEGABYTE - 1001);
+ CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 1000,
+ ONE_MEGABYTE - 1000);
+ CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE - 999,
+ ONE_MEGABYTE - 999);
+ CheckBlockMaxSize(config, ::g_mempool, ONE_MEGABYTE, ONE_MEGABYTE - 999);
// Test around default cap
config.SetMaxBlockSize(DEFAULT_MAX_BLOCK_SIZE);
// Now we can use the default max block size.
- CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 1001,
+ CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 1001,
DEFAULT_MAX_BLOCK_SIZE - 1001);
- CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 1000,
+ CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 1000,
DEFAULT_MAX_BLOCK_SIZE - 1000);
- CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE - 999,
+ CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE - 999,
DEFAULT_MAX_BLOCK_SIZE - 1000);
- CheckBlockMaxSize(config, DEFAULT_MAX_BLOCK_SIZE,
+ CheckBlockMaxSize(config, ::g_mempool, DEFAULT_MAX_BLOCK_SIZE,
DEFAULT_MAX_BLOCK_SIZE - 1000);
// If the parameter is not specified, we use
diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp
--- a/src/test/validation_block_tests.cpp
+++ b/src/test/validation_block_tests.cpp
@@ -50,7 +50,7 @@
}
};
-std::shared_ptr<CBlock> Block(const Config &config,
+std::shared_ptr<CBlock> Block(const Config &config, const CTxMemPool &mempool,
const BlockHash &prev_hash) {
static int i = 0;
static uint64_t time = config.GetChainParams().GenesisBlock().nTime;
@@ -58,7 +58,7 @@
CScript pubKey;
pubKey << i++ << OP_TRUE;
- auto ptemplate = BlockAssembler(config, g_mempool).CreateNewBlock(pubKey);
+ auto ptemplate = BlockAssembler(config, mempool).CreateNewBlock(pubKey);
auto pblock = std::make_shared<CBlock>(ptemplate->block);
pblock->hashPrevBlock = prev_hash;
pblock->nTime = ++time;
@@ -83,15 +83,17 @@
// construct a valid block
const std::shared_ptr<const CBlock> GoodBlock(const Config &config,
+ const CTxMemPool &mempool,
const BlockHash &prev_hash) {
return FinalizeBlock(config.GetChainParams().GetConsensus(),
- Block(config, prev_hash));
+ Block(config, mempool, prev_hash));
}
// construct an invalid block (but with a valid header)
const std::shared_ptr<const CBlock> BadBlock(const Config &config,
+ const CTxMemPool &mempool,
const BlockHash &prev_hash) {
- auto pblock = Block(config, prev_hash);
+ auto pblock = Block(config, mempool, prev_hash);
CMutableTransaction coinbase_spend;
coinbase_spend.vin.push_back(
@@ -105,7 +107,8 @@
return ret;
}
-void BuildChain(const Config &config, const BlockHash &root, int height,
+void BuildChain(const Config &config, const CTxMemPool &mempool,
+ const BlockHash &root, int height,
const unsigned int invalid_rate, const unsigned int branch_rate,
const unsigned int max_size,
std::vector<std::shared_ptr<const CBlock>> &blocks) {
@@ -117,17 +120,18 @@
bool gen_fork = InsecureRandRange(100) < branch_rate;
const std::shared_ptr<const CBlock> pblock =
- gen_invalid ? BadBlock(config, root) : GoodBlock(config, root);
+ gen_invalid ? BadBlock(config, mempool, root)
+ : GoodBlock(config, mempool, root);
blocks.push_back(pblock);
if (!gen_invalid) {
- BuildChain(config, pblock->GetHash(), height - 1, invalid_rate,
+ BuildChain(config, mempool, pblock->GetHash(), height - 1, invalid_rate,
branch_rate, max_size, blocks);
}
if (gen_fork) {
- blocks.push_back(GoodBlock(config, root));
- BuildChain(config, blocks.back()->GetHash(), height - 1, invalid_rate,
- branch_rate, max_size, blocks);
+ blocks.push_back(GoodBlock(config, mempool, root));
+ BuildChain(config, mempool, blocks.back()->GetHash(), height - 1,
+ invalid_rate, branch_rate, max_size, blocks);
}
}
@@ -139,8 +143,8 @@
std::vector<std::shared_ptr<const CBlock>> blocks;
while (blocks.size() < 50) {
blocks.clear();
- BuildChain(config, chainParams.GenesisBlock().GetHash(), 100, 15, 10,
- 500, blocks);
+ BuildChain(config, ::g_mempool, chainParams.GenesisBlock().GetHash(),
+ 100, 15, 10, 500, blocks);
}
bool ignored;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:33 (5 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187629
Default Alt Text
D6436.diff (9 KB)
Attached To
D6436: Explicitely pass the mempool down in some test
Event Timeline
Log In to Comment