removed Share.shared
authorForrest Voight <forrest.voight@gmail.com>
Mon, 28 Nov 2011 01:45:44 +0000 (20:45 -0500)
committerForrest Voight <forrest.voight@gmail.com>
Mon, 28 Nov 2011 01:45:44 +0000 (20:45 -0500)
p2pool/data.py
p2pool/main.py

index c085a31..1ac6542 100644 (file)
@@ -139,7 +139,7 @@ class Share(object):
     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 shared 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'.split(' ')
     
     def __init__(self, net, header, share_info, merkle_branch=None, other_txs=None):
         if header['timestamp'] >= TRANSITION_TIME:
@@ -197,7 +197,6 @@ class Share(object):
         
         # XXX eww
         self.time_seen = time.time()
-        self.shared = False
         self.peer = None
     
     def as_block(self, tracker, net):
@@ -241,9 +240,6 @@ class Share(object):
             if len(bitcoin_data.block_type.pack(dict(header=self.header, txs=[gentx] + self.other_txs))) > 1000000 - 1000:
                 raise ValueError('block size too large')
     
-    def flag_shared(self):
-        self.shared = True
-    
     def __repr__(self):
         return '<Share %s>' % (' '.join('%s=%r' % (k, getattr(self, k)) for k in self.__slots__),)
 
@@ -326,7 +322,6 @@ class NewShare(Share):
         
         # XXX eww
         self.time_seen = time.time()
-        self.shared = False
         self.peer = None
     
     def check(self, tracker, now, net):
index c8379de..63c8c7d 100644 (file)
@@ -101,6 +101,7 @@ def main(args):
         print
         
         tracker = p2pool.OkayTracker(args.net)
+        shared_share_hashes = set()
         ss = p2pool.ShareStore(os.path.join(os.path.dirname(sys.argv[0]), args.net.NAME + '_shares.'), args.net)
         known_verified = set()
         print "Loading shares..."
@@ -108,7 +109,7 @@ def main(args):
             if mode == 'share':
                 if contents.hash in tracker.shares:
                     continue
-                contents.shared = True
+                shared_share_hashes.add(contents.hash)
                 contents.time_seen = 0
                 tracker.add(contents)
                 if len(tracker.shares) % 1000 == 0 and tracker.shares:
@@ -129,6 +130,7 @@ def main(args):
         tracker.verified.added.watch(lambda share: ss.add_verified_hash(share.hash))
         tracker.removed.watch(lambda share: ss.forget_share(share.hash))
         tracker.verified.removed.watch(lambda share: ss.forget_verified_share(share.hash))
+        tracker.removed.watch(lambda share: shared_share_hashes.discard(share.hash))
         
         peer_heads = expiring_dict.ExpiringDict(300) # hash -> peers that know of it
         
@@ -232,7 +234,7 @@ def main(args):
                 #if p2pool_init.DEBUG:
                 #    print "Sending share %s to %r" % (p2pool.format_hash(share.hash), peer.addr)
                 peer.sendShares([share])
-            share.flag_shared()
+            shared_share_hashes.add(share.hash)
         
         def p2p_shares(shares, peer=None):
             if len(shares) > 5:
@@ -345,7 +347,7 @@ def main(args):
         def work_changed(new_work):
             #print 'Work changed:', new_work
             for share in tracker.get_chain_known(new_work['best_share_hash']):
-                if share.shared:
+                if share.hash in shared_share_hashes:
                     break
                 share_share(share, share.peer)
         current_work.changed.watch(work_changed)