def createClearMerkleTree(self, height): subsidy = self.SubsidyAlgo(height) cbtxn = self.makeCoinbaseTxn(subsidy, False, witness_commitment=None) cbtxn.setCoinbase(b'\0\0') # necessary to avoid triggering segwit marker+flags cbtxn.assemble() MT = MerkleTree([cbtxn]) if self.currentMerkleTree: self.UpdateClearMerkleTree(MT, self.currentMerkleTree.MP) MT.witness_commitment = None return MT
def createClearMerkleTree(self, height): subsidy = self.SubsidyAlgo(height) blockInfo = (None, None) if hasattr(self, 'Rootstock') and self.Rootstock is not None: blockInfo = self.Rootstock.getBlockInfo() cbtxn = self.makeCoinbaseTxn(subsidy, False, witness_commitment=None) cbtxn.setCoinbase(b'\0\0') # necessary to avoid triggering segwit marker+flags cbtxn.assemble() MT = MerkleTree([cbtxn]) self.merkleTreeLock.acquire() if self.currentMerkleTree: self.UpdateClearMerkleTree(MT, self.currentMerkleTree.MP) self.merkleTreeLock.release() MT.witness_commitment = None if blockInfo[0] is not None: MT.rootstockBlockInfo = blockInfo return MT
def _ProcessGBT(self, MP, TS = None): oMP = MP MP = deepcopy(MP) if MP['version'] & 0xe0000000 != 0x20000000: self.logger.error('Template from \'%s\' has non-BIP9 block version (%x)' % (TS['name'], MP['version'])) return None ISupportAllRules = True for ruleflag in MP['rules']: (MandatoryRule, rule) = SplitRuleFlag(ruleflag) if rule not in SupportedRules: ISupportAllRules = False if MandatoryRule: self.logger.error('Template from \'%s\' strictly requires unsupported rule \'%s\'', TS['name'], rule) return None else: self.logger.warning('Template from \'%s\' loosely requires unsupported rule \'%s\'', TS['name'], rule) MP['_filtered_vbavailable'] = {} for ruleflag in MP['vbavailable']: rulebit = MP['vbavailable'][ruleflag] rulemask = (1 << rulebit) if MP['version'] & rulemask: MP['_filtered_vbavailable'][ruleflag] = rulebit prevBlock = bytes.fromhex(MP['previousblockhash'])[::-1] if 'height' not in MP: MP['height'] = TS['access'].getinfo()['blocks'] + 1 height = MP['height'] bits = bytes.fromhex(MP['bits'])[::-1] (MP['_bits'], MP['_prevBlock']) = (bits, prevBlock) MP['_BlockVersionBytes'] = struct.pack('<L', MP['version']) if (prevBlock, height, bits) != self.currentBlock and (self.currentBlock[1] is None or height > self.currentBlock[1]): self.updateBlock(prevBlock, height, bits, _HBH=(MP['previousblockhash'], MP['bits'])) txnlist = MP['transactions'] if len(txnlist) and isinstance(txnlist[0], dict): txninfo = txnlist txnlist = tuple(a['data'] for a in txnlist) elif 'transactionfees' in MP: # Backward compatibility with pre-BIP22 gmp_fees branch txninfo = [{'fee':a} for a in MP['transactionfees']] else: # Backward compatibility with pre-BIP22 hex-only (bitcoind <0.7, Eloipool <future) txninfo = [{}] * len(txnlist) # TODO: cache Txn or at least txid from previous merkle roots? txnlist = [a for a in map(bytes.fromhex, txnlist)] self._makeBlockSafe(MP, txnlist, txninfo) if len(MP['transactions']) != len(txnlist) and not ISupportAllRules: self.logger.error('Template from \'%s\' should be trimmed, but requires unsupported rule(s)', TS['name']) return None txnobjs = [None] for i in range(len(txnlist)): iinfo = txninfo[i] ka = {} if 'txid' in iinfo: ka['txid'] = bytes.fromhex(iinfo['txid'])[::-1] txnobjs.append(Txn(data=txnlist[i], **ka)) 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') cbtxn.assemble() txnobjs[0] = cbtxn txnobjs = list(txnobjs) newMerkleTree = MerkleTree(txnobjs) newMerkleTree.POTInfo = MP.get('POTInfo') newMerkleTree.MP = MP newMerkleTree.oMP = oMP newMerkleTree.witness_commitment = witness_commitment return newMerkleTree