track stales by hash
authorForrest Voight <forrest@forre.st>
Sun, 31 Jul 2011 19:25:42 +0000 (15:25 -0400)
committerForrest Voight <forrest@forre.st>
Sun, 31 Jul 2011 19:25:42 +0000 (15:25 -0400)
p2pool/main.py
p2pool/skiplists.py

index 9de23bf..757ca12 100644 (file)
@@ -478,14 +478,16 @@ def main(args):
                     if height > 5:
                         att_s = p2pool.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], args.net)
                         weights, total_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 120), 2**100)
-                        count = counter(current_work.value['best_share_hash'], height, 2**100)
+                        matching_in_chain = counter(current_work.value['best_share_hash'], height)
+                        shares_in_chain = my_shares & matching_in_chain
+                        stale_shares = my_shares - matching_in_chain
                         print 'Pool: %sH/s in %i shares Recent: %.02f%% >%sH/s Shares: %i (%i stale) Peers: %i' % (
                             math.format(att_s),
                             height,
                             weights.get(my_script, 0)/total_weight*100,
                             math.format(weights.get(my_script, 0)/total_weight*att_s),
-                            len(my_shares),
-                            len(my_shares) - count,
+                            len(shares_in_chain) + len(stale_shares),
+                            len(stale_shares),
                             len(p2p_node.peers),
                         )
                         #weights, total_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 100), 2**100)
index 6b0933f..d272553 100644 (file)
@@ -55,35 +55,34 @@ class CountsSkipList(skiplist.SkipList):
         return self.tracker.shares[element].previous_hash
     
     def get_delta(self, element):
-        from p2pool.bitcoin import data as bitcoin_data
         if element is None:
-            return 0 # XXX
+            raise AssertionError()
         share = self.tracker.shares[element]
-        weight = 1 if share.nonce[:8] == self.run_identifier else 0
-        return 1, weight, 1
-    
-    def combine_deltas(self, (share_count1, weights1, total_weight1), (share_count2, weights2, total_weight2)):
-        return share_count1 + share_count2, weights1 + weights2, total_weight1 + total_weight2
+        return 1, set([share.hash]) if share.nonce[:8] == self.run_identifier else set() 
     
-    def initial_solution(self, start, (max_shares, desired_weight)):
-        return 0, 0, 0
+    def combine_deltas(self, (share_count1, share_hashes1), (share_count2, share_hashes2)):
+        if share_hashes1 & share_hashes2:
+            raise AssertionError()
+        return share_count1 + share_count2, share_hashes1 | share_hashes2
     
+    def initial_solution(self, start, (desired_shares,)):
+        return 0, set()
     
-    def apply_delta(self, (share_count1, weights1, total_weight1), (share_count2, weights2, total_weight2), (max_shares, desired_weight)):
-        return share_count1 + share_count2, weights1 + weights2, total_weight1 + total_weight2
+    def apply_delta(self, (share_count1, share_hashes1), (share_count2, share_hashes2), (desired_shares,)):
+        if share_hashes1 & share_hashes2:
+            raise AssertionError()
+        return share_count1 + share_count2, share_hashes1 | share_hashes2
     
-    def judge(self, (share_count, weights, total_weight), (max_shares, desired_weight)):
-        if share_count > max_shares or total_weight > desired_weight:
+    def judge(self, (share_count, share_hashes), (desired_shares,)):
+        if share_count > desired_shares:
             return 1
-        elif share_count == max_shares or total_weight == desired_weight:
+        elif share_count == desired_shares:
             return 0
         else:
             return -1
     
-    def finalize(self, (share_count, weights, total_weight)):
-        if share_count != total_weight:
-            raise AssertionError()
-        return weights
+    def finalize(self, (share_count, share_hashes)):
+        return share_hashes
 
 if __name__ == '__main__':
     import random