import random
import time
-from twisted.internet import defer
from twisted.python import log
import p2pool
from p2pool import skiplists
from p2pool.bitcoin import data as bitcoin_data, script
-from p2pool.util import memoize, expiring_dict, math, deferral
+from p2pool.util import memoize, expiring_dict, math
merkle_branch_type = bitcoin_data.ListType(bitcoin_data.ComposedType([
self.get_cumulative_weights = skiplists.WeightsSkipList(self)
+ def add(self, share, known_verified=False):
+ bitcoin_data.Tracker.add(self, share)
+ if known_verified:
+ self.verified.add(share)
+
def attempt_verify(self, share, now):
if share.hash in self.verified.shares:
return True
)
# eat away at heads
- while True:
- removed = False
- for share_hash in list(self.heads):
- if share_hash in scores[-5:]:
- continue
- if self.shares[share_hash].time_seen > time.time() - 30:
- continue
- self.remove(share_hash)
- if share_hash in self.verified.shares:
- self.verified.remove(share_hash)
- removed = True
- if not removed:
- break
+ if scores:
+ while True:
+ to_remove = set()
+ for share_hash, tail in self.heads.iteritems():
+ if share_hash in scores[-5:]:
+ continue
+ if self.shares[share_hash].time_seen > time.time() - 30:
+ continue
+ if max(self.shares[before_tail_hash].time_seen for before_tail_hash in self.reverse_shares.get(tail)) > time.time() - 120:
+ continue
+ to_remove.add(share_hash)
+ for share_hash in to_remove:
+ self.remove(share_hash)
+ if share_hash in self.verified.shares:
+ self.verified.remove(share_hash)
+ if not to_remove:
+ break
# drop tails
while True:
start = time.time()
for aftertail in list(self.reverse_shares.get(tail, set())):
self.remove(aftertail)
- if tail in self.verified.shares:
+ if aftertail in self.verified.shares:
self.verified.remove(aftertail)
removed = True
end = time.time()
P2P_PORT = 9333
MAX_TARGET = 2**256//2**32 - 1
PERSIST = True
+ HEADERSTORE_FILENAME = 'headers.dat'
class Testnet(bitcoin_data.Testnet):
SHARE_PERIOD = 1 # seconds
P2P_PORT = 19333
MAX_TARGET = 2**256//2**20 - 1
PERSIST = False
+ HEADERSTORE_FILENAME = 'testnet_headers.dat'