Skip to content

Commit

Permalink
ForceWitnessCommitment option
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Nov 22, 2016
1 parent 7f31892 commit 961dae3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions merklemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 961dae3

Please sign in to comment.