rate and users now use last hour of shares
authorForrest Voight <forrest@forre.st>
Sat, 30 Jul 2011 19:13:53 +0000 (19:13 +0000)
committerForrest Voight <forrest@forre.st>
Sat, 30 Jul 2011 19:13:53 +0000 (19:13 +0000)
p2pool/data.py
p2pool/main.py

index b446af1..ea613d9 100644 (file)
@@ -203,9 +203,11 @@ class Share(object):
     def __repr__(self):
         return '<Share %s>' % (' '.join('%s=%r' % (k, v) for k, v in self.__dict__.iteritems()),)
 
-def get_pool_attempts_per_second(tracker, previous_share_hash, net):
+def get_pool_attempts_per_second(tracker, previous_share_hash, net, dist=None):
+    if dist is None:
+        dist = net.TARGET_LOOKBEHIND
     # XXX could be optimized to use nth_parent and cumulative_weights
-    chain = list(itertools.islice(tracker.get_chain_to_root(previous_share_hash), net.TARGET_LOOKBEHIND))
+    chain = list(itertools.islice(tracker.get_chain_to_root(previous_share_hash), dist))
     attempts = sum(bitcoin_data.target_to_average_attempts(share.target) for share in chain[:-1])
     time = chain[0].timestamp - chain[-1].timestamp
     if time == 0:
index 32ac175..1e943ee 100644 (file)
@@ -362,12 +362,12 @@ def main(args):
         def get_rate():
             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)
+                att_s = p2pool.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], args.net, min(height, 720))
                 return att_s
         
         def get_users():
             height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
-            weights, total_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 1000), 2**100)
+            weights, total_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 720), 2**256)
             res = {}
             for script in sorted(weights, key=lambda s: weights[s]):
                 res[script.encode('hex')] = weights[script]/total_weight