Skip to content

Commit

Permalink
Add coinbase_output_max_sigops
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjors committed Jun 18, 2024
1 parent 0cec95e commit 60e03de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/common/sv2_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ struct Sv2CoinbaseOutputConstraintsMsg
*/
uint32_t m_coinbase_output_max_additional_size;

/**
* The maximum additional sigops which the pool will add in coinbase transaction outputs.
*/
uint16_t m_coinbase_output_max_sigops;

template <typename Stream>
void Unserialize(Stream& s)
{
s >> m_coinbase_output_max_additional_size;
s >> m_coinbase_output_max_sigops;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Mining
* @param[in] coinbase_output_max_additional_size maximum additional serialized bytes which the pool will add in coinbase transaction outputs
* @returns a block template
*/
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true, size_t coinbase_output_max_additional_size = DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIZE) = 0;
virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool = true, size_t coinbase_output_max_additional_size = DEFAULT_COINBASE_OUTPUT_MAX_ADDITIONAL_SIZE, size_t coinbase_output_max_sigops = DEFAULT_COINBASE_OUTPUT_MAX_SIGOPS) = 0;
/**
* Processes new block. A valid new block is automatically relayed to peers.
*
Expand Down
4 changes: 3 additions & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,16 @@ class MinerImpl : public Mining
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, chainman().ActiveChain().Tip(), /*fCheckPOW=*/false, check_merkle_root);
}

std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool, size_t coinbase_output_max_additional_size) override
std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool, size_t coinbase_output_max_additional_size, size_t coinbase_output_max_sigops) override
{
BlockAssembler::Options options;
ApplyArgsManOptions(gArgs, options);

// TODO: fail sv2 handshake
Assume(options.nBlockMaxWeight >= coinbase_output_max_additional_size);
Assume(options.coinbase_output_max_sigops <= MAX_BLOCK_SIGOPS_COST);
options.coinbase_output_max_additional_size = coinbase_output_max_additional_size;
options.coinbase_output_max_sigops = coinbase_output_max_sigops;

LOCK(::cs_main);
return BlockAssembler{chainman().ActiveChainstate(), use_mempool ? context()->mempool.get() : nullptr, options}.CreateNewBlock(script_pub_key);
Expand Down
9 changes: 5 additions & 4 deletions src/test/sv2_template_provider_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ BOOST_AUTO_TEST_CASE(client_tests)
// output data size:
BOOST_REQUIRE(tester.GetBlockTemplateCount() == 0);

std::vector<uint8_t> coinbase_output_max_additional_size_bytes{
0x01, 0x00, 0x00, 0x00
std::vector<uint8_t> coinbase_output_constraint_bytes{
0x01, 0x00, 0x00, 0x00, // coinbase_output_max_additional_size
0x00, 0x00 // coinbase_output_max_sigops
};
node::Sv2NetHeader cb_header{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, 4};
node::Sv2NetMsg msg{std::move(cb_header), std::move(coinbase_output_max_additional_size_bytes)};
node::Sv2NetHeader cb_header{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, 6};
node::Sv2NetMsg msg{std::move(cb_header), std::move(coinbase_output_constraint_bytes)};
// The reply should be NewTemplate and SetNewPrevHash
tester.receiveMessage(msg);
tester.ProcessOurResponse(2 * SV2_HEADER_ENCRYPTED_SIZE + 91 + 80 + 2 * Poly1305::TAGLEN);
Expand Down

0 comments on commit 60e03de

Please sign in to comment.