From 961dae39755dd1977377bfd1c4b5a90484a6b424 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 22 Nov 2016 10:38:21 +0000 Subject: [PATCH] ForceWitnessCommitment option --- merklemaker.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/merklemaker.py b/merklemaker.py index 86244cd..67826d2 100644 --- a/merklemaker.py +++ b/merklemaker.py @@ -46,13 +46,15 @@ def SplitRuleFlag(ruleflag): else: return (False, ruleflag) -def CalculateWitnessCommitment(txnobjs, nonce): +def CalculateWitnessCommitment(txnobjs, nonce, force=False): gentx_withash = b'\0' * 0x20 withashes = (gentx_withash,) + tuple(a.get_witness_hash() for a in txnobjs[1:]) - txids = (gentx_withash,) + tuple(a.txid for a in txnobjs[1:]) - if withashes == txids: - # Unnecessary - return None + + if not force: + txids = (gentx_withash,) + tuple(a.txid for a in txnobjs[1:]) + if withashes == txids: + # Unnecessary + return None wmr = MerkleTree(data=withashes).merkleRoot() commitment = util.dblsha(wmr + nonce) @@ -113,6 +115,7 @@ def __init__(self, *a, **k): self.lastBlock = (None, None, None) self.SubsidyAlgo = lambda height: 5000000000 >> (height // 210000) self.WitnessNonce = b'\0' * 0x20 + self.ForceWitnessCommitment = False def _prepare(self): self.UseTemplateChecks = True @@ -460,7 +463,7 @@ def _ProcessGBT(self, MP, TS = None): ka['txid'] = bytes.fromhex(iinfo['txid'])[::-1] txnobjs.append(Txn(data=txnlist[i], **ka)) - witness_commitment = CalculateWitnessCommitment(txnobjs, self.WitnessNonce) + witness_commitment = CalculateWitnessCommitment(txnobjs, self.WitnessNonce, force=self.ForceWitnessCommitment) cbtxn = self.makeCoinbaseTxn(MP['coinbasevalue'], prevBlockHex = MP['previousblockhash'], witness_commitment=witness_commitment) cbtxn.setCoinbase(b'\0\0')