Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sv2/block_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
11 changes: 5 additions & 6 deletions src/sv2/template_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
11 changes: 11 additions & 0 deletions src/test/sv2_template_provider_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <boost/test/unit_test.hpp>
#include <interfaces/mining.h>
#include <sv2/block_options.h>
#include <interfaces/init.h>
#include <sv2/messages.h>
#include <test/sv2_test_setup.h>
Expand All @@ -16,6 +17,7 @@
#include <test/sv2_mock_mining.h>

#include <future>
#include <algorithm>
#include <memory>
#include <string>
#include <thread>
Expand All @@ -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{};
Expand Down
Loading