diff --git a/src/sv2/block_options.h b/src/sv2/block_options.h index c636346b..4ebadbe0 100644 --- a/src/sv2/block_options.h +++ b/src/sv2/block_options.h @@ -14,6 +14,8 @@ namespace node { //! Default reserved weight for block assembly scaffolding (header, coinbase, etc). static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000}; +//! Minimum reserved weight enforced by block assembly. +static constexpr size_t MIN_BLOCK_RESERVED_WEIGHT{2000}; struct BlockCreateOptions { /** Set false to omit mempool transactions from templates. */ diff --git a/src/sv2/template_provider.cpp b/src/sv2/template_provider.cpp index 8152c3f5..31705dc5 100644 --- a/src/sv2/template_provider.cpp +++ b/src/sv2/template_provider.cpp @@ -258,14 +258,13 @@ void Sv2TemplateProvider::ThreadSv2ClientHandler(size_t client_id) const size_t block_reserved_floor{1168}; // Reserve a little more so that if the above calculation is // wrong or there's an implementation error, we don't produce - // an invalid bock when the template is completely full. + // an invalid block when the template is completely full. const size_t block_reserved_padding{400}; - // Bitcoin Core enforces a mimimum block reserved weight of 2000. - options.block_reserved_weight = std::min(size_t(2000), - block_reserved_floor + - block_reserved_padding + - client->m_coinbase_tx_outputs_size * 4); + // Bitcoin Core enforces a minimum block reserved weight of 2000. + options.block_reserved_weight = std::max( + node::MIN_BLOCK_RESERVED_WEIGHT, + block_reserved_floor + block_reserved_padding + client->m_coinbase_tx_outputs_size * 4); } return true; }; diff --git a/src/test/sv2_template_provider_tests.cpp b/src/test/sv2_template_provider_tests.cpp index a7e3f9f2..698285eb 100644 --- a/src/test/sv2_template_provider_tests.cpp +++ b/src/test/sv2_template_provider_tests.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include +#include #include #include #include @@ -27,6 +29,15 @@ BOOST_FIXTURE_TEST_SUITE(sv2_template_provider_tests, Sv2BasicTestingSetup) +BOOST_AUTO_TEST_CASE(block_reserved_weight_floor) +{ + node::BlockCreateOptions options{}; + // Guard against regressions where the reserved weight floor is treated as a cap. + options.block_reserved_weight = 1800; + options.block_reserved_weight = std::max(node::MIN_BLOCK_RESERVED_WEIGHT, options.block_reserved_weight); + BOOST_REQUIRE_EQUAL(options.block_reserved_weight, node::MIN_BLOCK_RESERVED_WEIGHT); +} + BOOST_AUTO_TEST_CASE(client_tests) { TPTester tester{};