Skip to content

Commit ebcf8d1

Browse files
committed
Sv2NewTemplate: add coinbase_witness_reserved_value
Adding coinbase_witness_reserved_value to the Sv2NewTemplate message so that it is automatically propagated to other roles in the Stratum v2 ecosystem, rather than assumed to be 0x00...00. This ensures that if this value ever gets consensus meaning, miners only need to upgrade their node software, not the rest of the mining stack. This is a breaking change requiring an updated Stratum v2 spec as well as support on the SRI side.
1 parent d2e3b42 commit ebcf8d1

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/sv2/messages.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ node::Sv2NewTemplateMsg::Sv2NewTemplateMsg(const CBlockHeader& header, const CTr
1111

1212
m_coinbase_tx_version = coinbase_tx->CURRENT_VERSION;
1313
m_coinbase_prefix = coinbase_tx->vin[0].scriptSig;
14+
if (coinbase_tx->HasWitness()) {
15+
const auto& witness_stack{coinbase_tx->vin[0].scriptWitness.stack};
16+
Assert(witness_stack.size() == 1 || witness_stack[0].size() == 32);
17+
m_coinbase_witness_reserved_value = uint256(witness_stack[0]);
18+
}
1419
m_coinbase_tx_input_sequence = coinbase_tx->vin[0].nSequence;
1520

1621
// The coinbase nValue already contains the nFee + the Block Subsidy when built using CreateBlock().

src/sv2/messages.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ struct Sv2NewTemplateMsg
282282
*/
283283
CScript m_coinbase_prefix;
284284

285+
/**
286+
* BIP 141 witness reserved value. If there is no segwit commitment in
287+
* m_coinbase_tx_outputs this value must be ignored.
288+
*/
289+
uint256 m_coinbase_witness_reserved_value;
290+
285291
/**
286292
* The coinbase transaction input’s nSequence field.
287293
*/
@@ -324,6 +330,7 @@ struct Sv2NewTemplateMsg
324330
<< m_version
325331
<< m_coinbase_tx_version
326332
<< m_coinbase_prefix
333+
<< m_coinbase_witness_reserved_value
327334
<< m_coinbase_tx_input_sequence
328335
<< m_coinbase_tx_value_remaining
329336
<< m_coinbase_tx_outputs_count;

src/test/sv2_messages_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ BOOST_AUTO_TEST_CASE(Sv2NewTemplate_test)
110110
// U32 02000000 coinbase tx version
111111
// B0_255 04 coinbase_prefix len
112112
// 03012100 coinbase prefix
113+
// U256 0000000000000000000000000000000000000000000000000000000000000000 - witness reserved value
113114
// U32 ffffffff coinbase tx input sequence
114115
// U64 0040075af0750700 coinbase tx value remaining
115116
// U32 01000000 coinbase tx outputs count
@@ -119,7 +120,7 @@ BOOST_AUTO_TEST_CASE(Sv2NewTemplate_test)
119120
// U32 dbc80d00 coinbase lock time (height 903,387)
120121
// SEQ0_255[U256] 01 merkle path length
121122
// 1a6240823de4c8d6aaf826851bdf2b0e8d5acf7c31e8578cff4c394b5a32bd4e - merkle path
122-
std::string expected{"01000000000000000000000030020000000403012100ffffffff0040075af0750700010000000c000100000000000000036a012adbc80d00011a6240823de4c8d6aaf826851bdf2b0e8d5acf7c31e8578cff4c394b5a32bd4e"};
123+
std::string expected{"010000000000000000000000300200000004030121000000000000000000000000000000000000000000000000000000000000000000ffffffff0040075af0750700010000000c000100000000000000036a012adbc80d00011a6240823de4c8d6aaf826851bdf2b0e8d5acf7c31e8578cff4c394b5a32bd4e"};
123124

124125
node::Sv2NewTemplateMsg new_template;
125126
new_template.m_template_id = 1;
@@ -131,6 +132,8 @@ BOOST_AUTO_TEST_CASE(Sv2NewTemplate_test)
131132
CScript prefix(coinbase_prefix.begin(), coinbase_prefix.end());
132133
new_template.m_coinbase_prefix = prefix;
133134

135+
new_template.m_coinbase_witness_reserved_value = uint256(0);
136+
134137
new_template.m_coinbase_tx_input_sequence = 4294967295;
135138
new_template.m_coinbase_tx_value_remaining = MAX_MONEY;
136139

src/test/sv2_template_provider_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
BOOST_FIXTURE_TEST_SUITE(sv2_template_provider_tests, TestChain100Setup)
2020

21-
static constexpr size_t SV2_NEW_TEMPLATE_MESSAGE_SIZE{91};
21+
static constexpr size_t SV2_NEW_TEMPLATE_MESSAGE_SIZE{91 + 32};
2222

2323
/**
2424
* A class for testing the Template Provider. Each TPTester encapsulates a

0 commit comments

Comments
 (0)