Skip to content

Commit

Permalink
merklemaker: Use sizelimit/sigoplimit from GBT, rather than hard-code…
Browse files Browse the repository at this point in the history
…d 1 MB / 20k sigops
  • Loading branch information
luke-jr committed Jan 29, 2016
1 parent d5e6d90 commit e154959
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions merklemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,17 @@ def _APOT(self, txninfopot, MP, POTInfo):
return True

def _makeBlockSafe(self, MP, txnlist, txninfo):
sizelimit = MP.get('sizelimit', 1000000) - 0x10000 # 64 KB breathing room
blocksize = sum(map(len, txnlist)) + 80
while blocksize > 934464: # 1 "MB" limit - 64 KB breathing room
while blocksize > sizelimit:
txnsize = len(txnlist[-1])
self._trimBlock(MP, txnlist, txninfo, 'SizeLimit', lambda x: 'Making blocks over 1 MB size limit (%d bytes; %s)' % (blocksize, x))
blocksize -= txnsize

# NOTE: This check doesn't work at all without BIP22 transaction obj format
sigoplimit = MP.get('sigoplimit', 20000) - 0x200 # 512 sigop breathing room
blocksigops = sum(a.get('sigops', 0) for a in txninfo)
while blocksigops > 19488: # 20k limit - 0x200 breathing room
while blocksigops > sigoplimit:
txnsigops = txninfo[-1]['sigops']
self._trimBlock(MP, txnlist, txninfo, 'SigOpLimit', lambda x: 'Making blocks over 20k SigOp limit (%d; %s)' % (blocksigops, x))
blocksigops -= txnsigops
Expand Down

0 comments on commit e154959

Please sign in to comment.