Skip to content

Commit

Permalink
Fix display of block number in web view; block number is now correctl…
Browse files Browse the repository at this point in the history
…y decoded from the coinbase of a share regardless of its size.
  • Loading branch information
maaku committed Sep 10, 2014
1 parent d8f9c63 commit ab3c272
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions p2pool/data.py
Expand Up @@ -12,6 +12,28 @@
from p2pool.bitcoin import data as bitcoin_data, script, sha256
from p2pool.util import math, forest, pack

def deserialize_bignum(str_, len_):
result = 0L
for idx in xrange(len_//8):
limb, str_ = pack.IntType(64).unpack(str_[:8]), str_[8:]
result += limb << (idx * 64)
if len_ & 4:
limb, str_ = pack.IntType(32).unpack(str_[:4]), str_[4:]
result += limb << ((len_ & ~7) * 8)
if len_ & 2:
limb, str_ = pack.IntType(16).unpack(str_[:2]), str_[2:]
result += limb << ((len_ & ~3) * 8)
if len_ & 1:
limb, str_ = pack.IntType(8).unpack(str_[:1]), str_[1:]
result += limb << ((len_ & ~1) * 8)
return result
def parse_bip0034(coinbase):
_, opdata = script.parse(coinbase).next()
bignum = deserialize_bignum(opdata, len(opdata))
if ord(opdata[-1]) & 0x80:
bignum = -bignum
return (bignum,)

# hashlink

hash_link_type = pack.ComposedType([
Expand Down
2 changes: 1 addition & 1 deletion p2pool/web.py
Expand Up @@ -218,7 +218,7 @@ def decent_height():
web_root.putChild('recent_blocks', WebInterface(lambda: [dict(
ts=s.timestamp,
hash='%064x' % s.header_hash,
number=pack.IntType(24).unpack(s.share_data['coinbase'][1:4]) if len(s.share_data['coinbase']) >= 4 else None,
number=p2pool_data.parse_bip0034(s.share_data['coinbase'])[0],
share='%064x' % s.hash,
) for s in node.tracker.get_chain(node.best_share_var.value, min(node.tracker.get_height(node.best_share_var.value), 24*60*60//node.net.SHARE_PERIOD)) if s.pow_hash <= s.header['bits'].target]))
web_root.putChild('uptime', WebInterface(lambda: time.time() - start_time))
Expand Down

0 comments on commit ab3c272

Please sign in to comment.