From 280ce6a0aed469c920aa4faa3baf10fd6572a106 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Thu, 28 May 2026 11:37:27 +0200 Subject: [PATCH] miner: ensure block_max_weight is flattened before limit checks Suggested in https://github.com/bitcoin/bitcoin/pull/33966#discussion_r3303462087 --- src/node/miner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node/miner.cpp b/src/node/miner.cpp index ccd9cc7c57a..32a21440c4e 100644 --- a/src/node/miner.cpp +++ b/src/node/miner.cpp @@ -245,7 +245,9 @@ std::unique_ptr BlockAssembler::CreateNewBlock() bool BlockAssembler::TestChunkBlockLimits(FeePerWeight chunk_feerate, int64_t chunk_sigops_cost) const { - if (nBlockWeight + chunk_feerate.size >= m_options.block_max_weight) { + // block_max_weight has been flattened before block assembly limit checks. + Assert(m_options.block_max_weight); + if (nBlockWeight + chunk_feerate.size >= *m_options.block_max_weight) { return false; } if (nBlockSigOpsCost + chunk_sigops_cost >= MAX_BLOCK_SIGOPS_COST) { @@ -318,8 +320,10 @@ void BlockAssembler::addChunks() m_mempool->SkipBuilderChunk(); ++nConsecutiveFailed; + // block_max_weight has been flattened before block assembly limit checks. + Assert(m_options.block_max_weight); if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight + - BLOCK_FULL_ENOUGH_WEIGHT_DELTA > m_options.block_max_weight) { + BLOCK_FULL_ENOUGH_WEIGHT_DELTA > *m_options.block_max_weight) { // Give up if we're close to full and haven't succeeded in a while return; }