Skip to content

Commit 99477c7

Browse files
sipalaanwj
authored andcommitted
Always add default_witness_commitment with GBT client support
Github-Pull: #9189 Rebased-From: ad04d1c
1 parent da5a16b commit 99477c7

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/main.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,15 +3503,8 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
35033503
{
35043504
std::vector<unsigned char> commitment;
35053505
int commitpos = GetWitnessCommitmentIndex(block);
3506-
bool fHaveWitness = false;
3507-
for (size_t t = 1; t < block.vtx.size(); t++) {
3508-
if (!block.vtx[t].wit.IsNull()) {
3509-
fHaveWitness = true;
3510-
break;
3511-
}
3512-
}
35133506
std::vector<unsigned char> ret(32, 0x00);
3514-
if (fHaveWitness && IsWitnessEnabled(pindexPrev, consensusParams)) {
3507+
if (consensusParams.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
35153508
if (commitpos == -1) {
35163509
uint256 witnessroot = BlockWitnessMerkleRoot(block, NULL);
35173510
CHash256().Write(witnessroot.begin(), 32).Write(&ret[0], 32).Finalize(witnessroot.begin());

src/rpc/mining.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
683683
result.push_back(Pair("curtime", pblock->GetBlockTime()));
684684
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
685685
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
686-
if (!pblocktemplate->vchCoinbaseCommitment.empty()) {
686+
687+
const struct BIP9DeploymentInfo& segwit_info = VersionBitsDeploymentInfo[Consensus::DEPLOYMENT_SEGWIT];
688+
if (!pblocktemplate->vchCoinbaseCommitment.empty() && setClientRules.find(segwit_info.name) != setClientRules.end()) {
687689
result.push_back(Pair("default_witness_commitment", HexStr(pblocktemplate->vchCoinbaseCommitment.begin(), pblocktemplate->vchCoinbaseCommitment.end())));
688690
}
689691

src/test/miner_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
213213
txCoinbase.vin[0].scriptSig = CScript();
214214
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce);
215215
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height());
216+
txCoinbase.vout.resize(1); // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
216217
txCoinbase.vout[0].scriptPubKey = CScript();
217218
pblock->vtx[0] = CTransaction(txCoinbase);
218219
if (txFirst.size() == 0)

0 commit comments

Comments
 (0)