diff options
author | Andrew Chow <github@achow101.com> | 2023-01-11 18:02:59 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-01-11 18:11:11 -0500 |
commit | 2f6a8e5e02465e9de5c9f6202d5e3f8aa19bf70b (patch) | |
tree | 51219d4424b20212edf271e11da85232d1619f1a /src/test | |
parent | 908212506dfc7b23181f7fcebec97bf855b21617 (diff) | |
parent | 04528054fcde61aa00e009dbbe1ac350ca1cf748 (diff) |
Merge bitcoin/bitcoin#26695: bench: BlockAssembler on a mempool with packages
04528054fcde61aa00e009dbbe1ac350ca1cf748 [bench] BlockAssembler with mempool packages (glozow)
6ce265acf4ff6ee5057b46bcb8b55abc4422e6f8 [test util] lock cs_main before pool.cs in PopulateMempool (glozow)
8791410662ce3ab7ba6bbe9813c55369edd6e4c9 [test util] randomize fee in PopulateMempool (glozow)
cba5934eb697aedbe1966ebc2817ab87232a1b59 [miner] allow bypassing TestBlockValidity (glozow)
c0588523083c9c78770b8b19a52a919db56250d9 [refactor] parameterize BlockAssembler::Options in PrepareBlock (glozow)
a2de971ba1c588488dde653a76853666429d4911 [refactor] add helper to apply ArgsManager to BlockAssembler::Options (glozow)
Pull request description:
Performance of block template building matters as miners likely want to be able to start mining on a block with transactions asap after a block is found. We would want to know if a mempool PR accidentally caused, for example, a 100x slowdown. An `AssembleBlock()` bench exists, but it operates on a mempool with 101 transactions, each with 0 ancestors or descendants and with the same fee. Adding a bench with a more complex mempool is useful because (1) it's more realistic (2) updating packages can potentially cause the algorithm to take a long time.
ACKs for top commit:
kevkevinpal:
Tested ACK [0452805](https://github.com/bitcoin/bitcoin/pull/26695/commits/04528054fcde61aa00e009dbbe1ac350ca1cf748)
achow101:
ACK 04528054fcde61aa00e009dbbe1ac350ca1cf748
stickies-v:
ACK 04528054f
Tree-SHA512: 38c138d6a75616651f9b1faf4e3a1cd833437a486f4e84308fbee958e8462bb570582c88f7ba7ab99d80191e97855ac2cf27c43cc21585d3e4b0e227effe2fb5
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/util/mining.cpp | 12 | ||||
-rw-r--r-- | src/test/util/mining.h | 4 | ||||
-rw-r--r-- | src/test/util/setup_common.cpp | 12 |
3 files changed, 20 insertions, 8 deletions
diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp index 55e9d4d63b..0df1db84c4 100644 --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -8,7 +8,6 @@ #include <consensus/merkle.h> #include <key_io.h> #include <node/context.h> -#include <node/miner.h> #include <pow.h> #include <script/standard.h> #include <test/util/script.h> @@ -74,10 +73,11 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) return CTxIn{block->vtx[0]->GetHash(), 0}; } -std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) +std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey, + const BlockAssembler::Options& assembler_options) { auto block = std::make_shared<CBlock>( - BlockAssembler{Assert(node.chainman)->ActiveChainstate(), Assert(node.mempool.get())} + BlockAssembler{Assert(node.chainman)->ActiveChainstate(), Assert(node.mempool.get()), assembler_options} .CreateNewBlock(coinbase_scriptPubKey) ->block); @@ -87,3 +87,9 @@ std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coi return block; } +std::shared_ptr<CBlock> PrepareBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey) +{ + BlockAssembler::Options assembler_options; + ApplyArgsManOptions(*node.args, assembler_options); + return PrepareBlock(node, coinbase_scriptPubKey, assembler_options); +} diff --git a/src/test/util/mining.h b/src/test/util/mining.h index 09e712cd35..70b1f7b3fb 100644 --- a/src/test/util/mining.h +++ b/src/test/util/mining.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_TEST_UTIL_MINING_H #define BITCOIN_TEST_UTIL_MINING_H +#include <node/miner.h> + #include <memory> #include <string> #include <vector> @@ -25,6 +27,8 @@ CTxIn MineBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey); /** Prepare a block to be mined */ std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext&, const CScript& coinbase_scriptPubKey); +std::shared_ptr<CBlock> PrepareBlock(const node::NodeContext& node, const CScript& coinbase_scriptPubKey, + const node::BlockAssembler::Options& assembler_options); /** RPC-like helper function, returns the generated coin */ CTxIn generatetoaddress(const node::NodeContext&, const std::string& address); diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index efc8529bf6..1b28e5f2c0 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -397,15 +397,15 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex unspent_prevouts.pop_front(); } const size_t num_outputs = det_rand.randrange(24) + 1; - // Approximately 1000sat "fee," equal output amounts. - const CAmount amount_per_output = (total_in - 1000) / num_outputs; + const CAmount fee = 100 * det_rand.randrange(30); + const CAmount amount_per_output = (total_in - fee) / num_outputs; for (size_t n{0}; n < num_outputs; ++n) { CScript spk = CScript() << CScriptNum(num_transactions + n); mtx.vout.push_back(CTxOut(amount_per_output, spk)); } CTransactionRef ptx = MakeTransactionRef(mtx); mempool_transactions.push_back(ptx); - if (amount_per_output > 2000) { + if (amount_per_output > 3000) { // If the value is high enough to fund another transaction + fees, keep track of it so // it can be used to build a more complex transaction graph. Insert randomly into // unspent_prevouts for extra randomness in the resulting structures. @@ -415,9 +415,11 @@ std::vector<CTransactionRef> TestChain100Setup::PopulateMempool(FastRandomContex } } if (submit) { - LOCK2(m_node.mempool->cs, cs_main); + LOCK2(cs_main, m_node.mempool->cs); LockPoints lp; - m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, 1000, 0, 1, false, 4, lp)); + m_node.mempool->addUnchecked(CTxMemPoolEntry(ptx, /*fee=*/(total_in - num_outputs * amount_per_output), + /*time=*/0, /*entry_height=*/1, + /*spends_coinbase=*/false, /*sigops_cost=*/4, lp)); } --num_transactions; } |