added args to skiplist finalize methods, which now check results using it
authorForrest Voight <forrest@forre.st>
Sat, 24 Dec 2011 07:11:58 +0000 (02:11 -0500)
committerForrest Voight <forrest@forre.st>
Sat, 24 Dec 2011 08:23:43 +0000 (03:23 -0500)
p2pool/skiplists.py
p2pool/util/forest.py
p2pool/util/skiplist.py

index da5dcf0..28520e3 100644 (file)
@@ -37,7 +37,9 @@ class WeightsSkipList(forest.TrackerSkipList):
         else:
             return -1
     
-    def finalize(self, (share_count, weights, total_weight, total_donation_weight)):
+    def finalize(self, (share_count, weights, total_weight, total_donation_weight), (max_shares, desired_weight)):
+        assert share_count <= max_shares and total_weight <= desired_weight
+        assert share_count == max_shares or total_weight == desired_weight
         return weights, total_weight, total_donation_weight
 
 class SumSkipList(forest.TrackerSkipList):
@@ -64,5 +66,6 @@ class SumSkipList(forest.TrackerSkipList):
     def judge(self, (result, count), (desired_count,)):
         return cmp(count, desired_count)
     
-    def finalize(self, (result, count)):
+    def finalize(self, (result, count), (desired_count,)):
+        assert count == desired_count
         return result
index 6e877b4..042a72a 100644 (file)
@@ -46,7 +46,8 @@ class DistanceSkipList(TrackerSkipList):
         else:
             return -1
     
-    def finalize(self, (dist, hash)):
+    def finalize(self, (dist, hash), (n,)):
+        assert dist == n
         return hash
 
 
index bc906fb..154edeb 100644 (file)
@@ -9,12 +9,12 @@ class SkipList(object):
     def forget_item(self, item):
         self.skips.pop(item, None)
     
-    def __call__(self, start, *args, **kwargs):
+    def __call__(self, start, *args):
         updates = {}
         pos = start
         sol = self.initial_solution(start, args)
         if self.judge(sol, args) == 0:
-            return self.finalize(sol)
+            return self.finalize(sol, args)
         while True:
             if pos not in self.skips:
                 self.skips[pos] = math.geometric(self.p), [(self.previous(pos), self.get_delta(pos))]
@@ -40,7 +40,7 @@ class SkipList(object):
                 decision = self.judge(sol_if, args)
                 #print pos, sol, jump, delta, sol_if, decision
                 if decision == 0:
-                    return self.finalize(sol_if)
+                    return self.finalize(sol_if, args)
                 elif decision < 0:
                     sol = sol_if
                     break