Skip to content

Commit a806647

Browse files
committed
[validation] Always include merkle root in coinbase commitment
1 parent 189128c commit a806647

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/validation.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,25 +3094,23 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
30943094
std::vector<unsigned char> commitment;
30953095
int commitpos = GetWitnessCommitmentIndex(block);
30963096
std::vector<unsigned char> ret(32, 0x00);
3097-
if (DeploymentEnabled(consensusParams, Consensus::DEPLOYMENT_SEGWIT)) {
3098-
if (commitpos == NO_WITNESS_COMMITMENT) {
3099-
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
3100-
CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
3101-
CTxOut out;
3102-
out.nValue = 0;
3103-
out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
3104-
out.scriptPubKey[0] = OP_RETURN;
3105-
out.scriptPubKey[1] = 0x24;
3106-
out.scriptPubKey[2] = 0xaa;
3107-
out.scriptPubKey[3] = 0x21;
3108-
out.scriptPubKey[4] = 0xa9;
3109-
out.scriptPubKey[5] = 0xed;
3110-
memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32);
3111-
commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end());
3112-
CMutableTransaction tx(*block.vtx[0]);
3113-
tx.vout.push_back(out);
3114-
block.vtx[0] = MakeTransactionRef(std::move(tx));
3115-
}
3097+
if (commitpos == NO_WITNESS_COMMITMENT) {
3098+
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
3099+
CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
3100+
CTxOut out;
3101+
out.nValue = 0;
3102+
out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
3103+
out.scriptPubKey[0] = OP_RETURN;
3104+
out.scriptPubKey[1] = 0x24;
3105+
out.scriptPubKey[2] = 0xaa;
3106+
out.scriptPubKey[3] = 0x21;
3107+
out.scriptPubKey[4] = 0xa9;
3108+
out.scriptPubKey[5] = 0xed;
3109+
memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32);
3110+
commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end());
3111+
CMutableTransaction tx(*block.vtx[0]);
3112+
tx.vout.push_back(out);
3113+
block.vtx[0] = MakeTransactionRef(std::move(tx));
31163114
}
31173115
UpdateUncommittedBlockStructures(block, pindexPrev, consensusParams);
31183116
return commitment;

0 commit comments

Comments
 (0)