Skip to content

Commit be63674

Browse files
committed
Merge bitcoin/bitcoin#30324: optimization: Moved repeated -printpriority fetching out of AddToBlock
323ce30 Moved the repeated -printpriority fetching out of AddToBlock (Lőrinc) Pull request description: `AddToBlock` was called repeatedly from `addPackageTxs` where the constant value of `printpriority` is recalculated every time. <img src="https://github.com/bitcoin/bitcoin/assets/1841944/6fd89647-7b6c-4f44-bd04-98d16cd2a938"> This showed up during profiling of AssembleBlock, fetching it once in the constructor results in a small speed increase for many iterations. > ./src/bench/bench_bitcoin --filter='AssembleBlock' --min-time=10000 before: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 156,460.15 | 6,391.40 | 0.1% | 11.03 | `AssembleBlock` after: | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 149,289.55 | 6,698.39 | 0.3% | 10.97 | `AssembleBlock` --- The slight speedup shows up in CI as well: <img src="https://github.com/bitcoin/bitcoin/assets/1841944/3be779c9-2dce-4a96-ae5f-cab5435bd72f"> ACKs for top commit: maflcko: ACK 323ce30 achow101: ACK 323ce30 tdb3: re ACK 323ce30 furszy: utACK 323ce30 Tree-SHA512: c2a0aab429646453ad0470956529f1cac8c38778c4c53f82c92c6cbaaaeb69f3d3603c0014ff097844b151e9da7caa2371a4676244caea96527cb540e66825a3
2 parents 1e16b10 + 323ce30 commit be63674

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ using node::BlockManager;
126126
using node::CacheSizes;
127127
using node::CalculateCacheSizes;
128128
using node::DEFAULT_PERSIST_MEMPOOL;
129-
using node::DEFAULT_PRINTPRIORITY;
129+
using node::DEFAULT_PRINT_MODIFIED_FEE;
130130
using node::DEFAULT_STOPATHEIGHT;
131131
using node::DumpMempool;
132132
using node::LoadMempool;
@@ -624,7 +624,7 @@ void SetupServerArgs(ArgsManager& argsman)
624624
strprintf("Maximum tip age in seconds to consider node in initial block download (default: %u)",
625625
Ticks<std::chrono::seconds>(DEFAULT_MAX_TIP_AGE)),
626626
ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
627-
argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINTPRIORITY), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
627+
argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINT_MODIFIED_FEE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
628628
argsman.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
629629

630630
SetupChainParamsBaseOptions(argsman);

src/node/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void ApplyArgsManOptions(const ArgsManager& args, BlockAssembler::Options& optio
7979
if (const auto blockmintxfee{args.GetArg("-blockmintxfee")}) {
8080
if (const auto parsed{ParseMoney(*blockmintxfee)}) options.blockMinFeeRate = CFeeRate{*parsed};
8181
}
82+
options.print_modified_fee = args.GetBoolArg("-printpriority", options.print_modified_fee);
8283
}
8384

8485
void BlockAssembler::resetBlock()
@@ -222,8 +223,7 @@ void BlockAssembler::AddToBlock(CTxMemPool::txiter iter)
222223
nFees += iter->GetFee();
223224
inBlock.insert(iter->GetSharedTx()->GetHash());
224225

225-
bool fPrintPriority = gArgs.GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
226-
if (fPrintPriority) {
226+
if (m_options.print_modified_fee) {
227227
LogPrintf("fee rate %s txid %s\n",
228228
CFeeRate(iter->GetModifiedFee(), iter->GetTxSize()).ToString(),
229229
iter->GetTx().GetHash().ToString());

src/node/miner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ChainstateManager;
3030
namespace Consensus { struct Params; };
3131

3232
namespace node {
33-
static const bool DEFAULT_PRINTPRIORITY = false;
33+
static const bool DEFAULT_PRINT_MODIFIED_FEE = false;
3434

3535
struct CBlockTemplate
3636
{
@@ -159,6 +159,7 @@ class BlockAssembler
159159
CFeeRate blockMinFeeRate{DEFAULT_BLOCK_MIN_TX_FEE};
160160
// Whether to call TestBlockValidity() at the end of CreateNewBlock().
161161
bool test_block_validity{true};
162+
bool print_modified_fee{DEFAULT_PRINT_MODIFIED_FEE};
162163
};
163164

164165
explicit BlockAssembler(Chainstate& chainstate, const CTxMemPool* mempool, const Options& options);

0 commit comments

Comments
 (0)