Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max coinbase out sigops to CoinbaseOutputDataSize #45

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 4 additions & 4 deletions src/sv2/connman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,20 @@ void Sv2Connman::ProcessSv2Message(const Sv2NetMsg& sv2_net_msg, Sv2Client& clie

break;
}
case Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE:
case Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS:
{
if (!client.m_setup_connection_confirmed) {
CloseConnection(client.m_id);
client.m_disconnect_flag = true;
return;
}

node::Sv2CoinbaseOutputDataSizeMsg coinbase_output_data_size;
node::Sv2CoinbaseOutputConstraintsMsg coinbase_output_data_size;
try {
ss >> coinbase_output_data_size;
client.m_coinbase_output_data_size_recv = true;
} catch (const std::exception& e) {
LogPrintLevel(BCLog::SV2, BCLog::Level::Error, "Received invalid CoinbaseOutputDataSize message from client id=%zu: %s\n",
LogPrintLevel(BCLog::SV2, BCLog::Level::Error, "Received invalid CoinbaseOutputConstraints message from client id=%zu: %s\n",
client.m_id, e.what());
CloseConnection(client.m_id);
client.m_disconnect_flag = true;
Expand All @@ -333,7 +333,7 @@ void Sv2Connman::ProcessSv2Message(const Sv2NetMsg& sv2_net_msg, Sv2Client& clie
LogPrintLevel(BCLog::SV2, BCLog::Level::Debug, "coinbase_output_max_additional_size=%d bytes\n", max_additional_size);

if (max_additional_size > MAX_BLOCK_WEIGHT) {
LogPrintLevel(BCLog::SV2, BCLog::Level::Error, "Received impossible CoinbaseOutputDataSize from client id=%zu: %d\n",
LogPrintLevel(BCLog::SV2, BCLog::Level::Error, "Received impossible CoinbaseOutputConstraints from client id=%zu: %d\n",
client.m_id, max_additional_size);
CloseConnection(client.m_id);
client.m_disconnect_flag = true;
Expand Down
2 changes: 1 addition & 1 deletion src/sv2/connman.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Sv2Client
std::deque<Sv2NetMsg> m_send_messages;

/**
* Whether the client has received CoinbaseOutputDataSize message.
* Whether the client has received CoinbaseOutputConstraints message.
*/
bool m_coinbase_output_data_size_recv = false;

Expand Down
22 changes: 18 additions & 4 deletions src/sv2/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class Sv2MsgType : uint8_t {
REQUEST_TRANSACTION_DATA_SUCCESS = 0x74,
REQUEST_TRANSACTION_DATA_ERROR = 0x75,
SUBMIT_SOLUTION = 0x76,
COINBASE_OUTPUT_DATA_SIZE = 0x70,
COINBASE_OUTPUT_CONSTRAINTS = 0x70,
};

static const std::map<Sv2MsgType, std::string> SV2_MSG_NAMES{
Expand All @@ -54,7 +54,7 @@ static const std::map<Sv2MsgType, std::string> SV2_MSG_NAMES{
{Sv2MsgType::REQUEST_TRANSACTION_DATA_SUCCESS, "RequestTransactionData.Success"},
{Sv2MsgType::REQUEST_TRANSACTION_DATA_ERROR, "RequestTransactionData.Error"},
{Sv2MsgType::SUBMIT_SOLUTION, "SubmitSolution"},
{Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, "CoinbaseOutputDataSize"},
{Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS, "CoinbaseOutputConstraints"},
};

struct Sv2SetupConnectionMsg
Expand Down Expand Up @@ -137,29 +137,43 @@ struct Sv2SetupConnectionMsg
* The template provider MUST NOT provide NewWork messages which would represent consensus-invalid blocks once this
* additional size — along with a maximally-sized (100 byte) coinbase field — is added.
*/
struct Sv2CoinbaseOutputDataSizeMsg
struct Sv2CoinbaseOutputConstraintsMsg
{
/**
* The default message type value for this Stratum V2 message.
*/
static constexpr auto m_msg_type = Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE;
static constexpr auto m_msg_type = Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS;

/**
* The maximum additional serialized bytes which the pool will add in coinbase transaction outputs.
*/
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 Serialize(Stream& s) const
{
s << m_coinbase_output_max_additional_size;
s << m_coinbase_output_max_sigops;
};


template <typename Stream>
void Unserialize(Stream& s)
{
s >> m_coinbase_output_max_additional_size;
try {
// This field was added to the spec on ...,
// SRI roles before ... do not provide it.
s >> m_coinbase_output_max_sigops;
} catch (const std::ios_base::failure& e) {
// Just use the default if it's missing
m_coinbase_output_max_sigops = 400;
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/test/sv2_connman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(client_tests)
std::vector<uint8_t> coinbase_output_max_additional_size_bytes{
0x01, 0x00, 0x00, 0x00
};
node::Sv2NetMsg msg{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, std::move(coinbase_output_max_additional_size_bytes)};
node::Sv2NetMsg msg{node::Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS, std::move(coinbase_output_max_additional_size_bytes)};
// No reply expected, not yet implemented
tester.RemoteToLocalMsg(msg);
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/sv2_template_provider_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ 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::Sv2NetMsg msg{node::Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE, std::move(coinbase_output_max_additional_size_bytes)};
node::Sv2NetMsg msg{node::Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS, std::move(coinbase_output_constraint_bytes)};
tester.receiveMessage(msg);
BOOST_TEST_MESSAGE("The reply should be NewTemplate and SetNewPrevHash");
BOOST_REQUIRE_EQUAL(tester.PeerReceiveBytes(), 2 * SV2_HEADER_ENCRYPTED_SIZE + 91 + 80 + 2 * Poly1305::TAGLEN);
Expand Down
8 changes: 4 additions & 4 deletions src/test/sv2_transport_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using namespace std::literals;
using node::Sv2NetMsg;
using node::Sv2CoinbaseOutputDataSizeMsg;
using node::Sv2CoinbaseOutputConstraintsMsg;
using node::Sv2MsgType;

BOOST_FIXTURE_TEST_SUITE(sv2_transport_tests, RegTestingSetup)
Expand Down Expand Up @@ -363,15 +363,15 @@ BOOST_AUTO_TEST_CASE(sv2_transport_responder_test)
tester.CompareHash();

// Handshake complete, have the initiator send us a message:
Sv2CoinbaseOutputDataSizeMsg body{4000};
Sv2CoinbaseOutputConstraintsMsg body{4000, 400};
Sv2NetMsg msg{body};
BOOST_REQUIRE(msg.m_msg_type == Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE);
BOOST_REQUIRE(msg.m_msg_type == Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS);

tester.SendPacket(msg);
ret = tester.Interact();
BOOST_REQUIRE(ret && ret->size() == 1);
BOOST_CHECK((*ret)[0] &&
(*ret)[0]->m_msg_type == Sv2MsgType::COINBASE_OUTPUT_DATA_SIZE);
(*ret)[0]->m_msg_type == Sv2MsgType::COINBASE_OUTPUT_CONSTRAINTS);

tester.CompareHash();

Expand Down
Loading