added .new_script back to Share
authorForrest Voight <forrest@forre.st>
Fri, 17 Feb 2012 18:40:08 +0000 (13:40 -0500)
committerForrest Voight <forrest@forre.st>
Sat, 18 Feb 2012 05:35:30 +0000 (00:35 -0500)
p2pool/data.py
p2pool/draw.py
p2pool/main.py
p2pool/skiplists.py
p2pool/test/test_skiplists.py

index 372a234..259ee85 100644 (file)
@@ -50,7 +50,7 @@ share_type = pack.ComposedType([
 ])
 
 class Share(object):
-    __slots__ = 'header share_info merkle_branch other_txs timestamp share_data previous_hash target pow_hash header_hash hash time_seen peer net'.split(' ')
+    __slots__ = 'header share_info merkle_branch other_txs timestamp share_data previous_hash target pow_hash header_hash hash time_seen peer net new_script'.split(' ')
     
     @classmethod
     def from_share(cls, share, net):
@@ -96,6 +96,7 @@ class Share(object):
             raise ValueError('new_script too long!')
         if script.get_sigop_count(self.share_data['new_script']) > 1:
             raise ValueError('too many sigops!')
+        self.new_script = self.share_data['new_script']
         
         self.previous_hash = self.share_data['previous_share_hash']
         
index 9b4094b..f4cf1ba 100644 (file)
@@ -35,7 +35,7 @@ def perp_and_normalize_to((dx, dy), d):
 
 def go(share, tracker, t, d):
     #c = color.green if share.peer is None else color.red
-    c = get_color(share.share_data['new_script'])
+    c = get_color(share.new_script)
     pos = get_pos(share, t, d)
     pygame.draw.circle(d, c, pos.rounded, 5)
     if share.previous_hash in tracker.shares:
@@ -52,7 +52,7 @@ def go(share, tracker, t, d):
         pygame.draw.circle(d, c, pos.rounded, 10, 2)
     for child_hash in tracker.reverse_shares.get(share.hash, set()):
         go(tracker.shares[child_hash], tracker, t, d)
-    d.blit(f.render(bitcoin_data.script2_to_human(share.share_data['new_script'], tracker.net.PARENT), True, (255, 255, 255)), pos)
+    d.blit(f.render(bitcoin_data.script2_to_human(share.new_script, tracker.net.PARENT), True, (255, 255, 255)), pos)
 
 pygame.font.init()
 f = pygame.font.SysFont("Monospace", 16)
index f238cbb..e68aa99 100644 (file)
@@ -920,7 +920,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint):
                 def _new_share(self, share):
                     if share.pow_hash <= share.header['bits'].target and share.header_hash not in self.announced_hashes and abs(share.timestamp - time.time()) < 10*60:
                         self.announced_hashes.add(share.header_hash)
-                        message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.share_data['new_script'], net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
+                        message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.new_script, net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
                         self.delayed_messages[message] = reactor.callLater(random.expovariate(1/5), lambda: (self.say(self.channel, message), self.delayed_messages.pop(message)))
                 def connectionLost(self, reason):
                     tracker.verified.added.unwatch(self.watch_id)
index ac55bec..d14f306 100644 (file)
@@ -7,7 +7,7 @@ class WeightsSkipList(forest.TrackerSkipList):
         from p2pool.bitcoin import data as bitcoin_data
         share = self.tracker.shares[element]
         att = bitcoin_data.target_to_average_attempts(share.target)
-        return 1, {share.share_data['new_script']: att*(65535-share.share_data['donation'])}, att*65535, att*share.share_data['donation']
+        return 1, {share.new_script: att*(65535-share.share_data['donation'])}, att*65535, att*share.share_data['donation']
     
     def combine_deltas(self, (share_count1, weights1, total_weight1, total_donation_weight1), (share_count2, weights2, total_weight2, total_donation_weight2)):
         return share_count1 + share_count2, math.add_dicts(weights1, weights2), total_weight1 + total_weight2, total_donation_weight1 + total_donation_weight2
index 06d14ef..7934d36 100644 (file)
@@ -10,7 +10,7 @@ class Test(unittest.TestCase):
         t = forest.Tracker()
         d = skiplists.WeightsSkipList(t)
         for i in xrange(200):
-            t.add(test_forest.FakeShare(hash=i, previous_hash=i - 1 if i > 0 else None, share_data=dict(new_script=i, donation=1234), target=2**249))
+            t.add(test_forest.FakeShare(hash=i, previous_hash=i - 1 if i > 0 else None, new_script=i, share_data=dict(donation=1234), target=2**249))
         for i in xrange(200):
             a = random.randrange(200)
             d(a, random.randrange(a + 1), 1000000*65535)[1]