import random
import time
import os
+import struct
from twisted.python import log
def from_share1b(cls, share1b, net):
return cls(net, **share1b)
- __slots__ = 'header previous_block share_info merkle_branch other_txs timestamp share_data new_script subsidy previous_hash previous_share_hash target nonce pow_hash header_hash hash time_seen peer'.split(' ')
+ __slots__ = 'header previous_block share_info merkle_branch other_txs timestamp share_data new_script subsidy previous_hash previous_share_hash target nonce pow_hash header_hash hash time_seen peer stale_frac'.split(' ')
def __init__(self, net, header, share_info, merkle_branch=None, other_txs=None):
if merkle_branch is None and other_txs is None:
if script.get_sigop_count(self.new_script) > 1:
raise ValueError('too many sigops!')
+ self.stale_frac = None
+ if len(self.nonce) >= 4:
+ a, b = struct.unpack("<HH", self.nonce[-4:])
+ if a != 0 or a == b:
+ self.stale_frac = a/65535
+
# XXX eww
self.time_seen = time.time()
self.peer = None
return '<Share %s>' % (' '.join('%s=%r' % (k, getattr(self, k)) for k in self.__slots__),)
class NewShare(Share):
- __slots__ = 'header previous_block share_info merkle_branch other_txs timestamp share_data new_script subsidy previous_hash previous_share_hash target nonce pow_hash header_hash hash time_seen peer donation'.split(' ')
+ __slots__ = 'header previous_block share_info merkle_branch other_txs timestamp share_data new_script subsidy previous_hash previous_share_hash target nonce pow_hash header_hash hash time_seen peer donation stale_frac'.split(' ')
@classmethod
def from_share(cls, share, net):
if script.get_sigop_count(self.new_script) > 1:
raise ValueError('too many sigops!')
+ self.stale_frac = self.share_data['stale_frac']/254 if self.share_data['stale_frac'] != 255 else None
+
# XXX eww
self.time_seen = time.time()
self.peer = None
if current_work.value['best_share_hash'] is not None:
height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
att_s = p2pool.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], args.net, min(height - 1, 720))
- fracs = [read_stale_frac(share) for share in itertools.islice(tracker.get_chain_known(current_work.value['best_share_hash']), 120) if read_stale_frac(share) is not None]
+ fracs = [share.stale_frac for share in itertools.islice(tracker.get_chain_known(current_work.value['best_share_hash']), 120) if share.stale_frac is not None]
return json.dumps(int(att_s / (1. - (math.median(fracs) if fracs else 0))))
return json.dumps(None)
task.LoopingCall(signal.alarm, 30).start(1)
- def read_stale_frac(share):
- if isinstance(share, p2pool.NewShare):
- return share.share_data['stale_frac']/254 if share.share_data['stale_frac'] != 255 else None
- if len(share.nonce) < 4:
- return None
- a, b = struct.unpack("<HH", share.nonce[-4:])
- if a == 0 or a != b:
- return None
- return a/65535
-
pool_str = None;
while True:
yield deferral.sleep(3)
weights, total_weight, donation_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 720), 65535*2**256)
shares, stale_doa_shares, stale_not_doa_shares = get_share_counts(True)
stale_shares = stale_doa_shares + stale_not_doa_shares
- fracs = [read_stale_frac(share) for share in itertools.islice(tracker.get_chain_known(current_work.value['best_share_hash']), 120) if read_stale_frac(share) is not None]
+ fracs = [share.stale_frac for share in itertools.islice(tracker.get_chain_known(current_work.value['best_share_hash']), 120) if share.stale_frac is not None]
str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % (
math.format(int(att_s / (1. - (math.median(fracs) if fracs else 0)))),
height,