self.work_cache = {}
self.work_cache_times = self.worker_bridge.new_work_event.times
- self.merkle_root_to_handler = expiring_dict.ExpiringDict(300)
+ self.merkle_roots = expiring_dict.ExpiringDict(300)
def attach_to(self, res, get_handler=None):
res.putChild('', _GETableServer(_Provider(self, long_poll=False), get_handler))
if data is not None:
header = getwork.decode_data(data)
- if header['merkle_root'] not in self.merkle_root_to_handler:
+ if header['merkle_root'] not in self.merkle_roots:
print >>sys.stderr, '''Couldn't link returned work's merkle root with its handler. This should only happen if this process was recently restarted!'''
defer.returnValue(False)
- defer.returnValue(self.merkle_root_to_handler[header['merkle_root']](header, request))
+ handler, orig_timestamp = self.merkle_roots[header['merkle_root']]
+ dt = header['timestamp'] - orig_timestamp
+ if dt < 0 or dt % 12 == 11 or dt >= 600:
+ print >>sys.stderr, '''Miner %s @ %s rolled timestamp improperly! This may be a bug in the miner that is causing you to lose work!''' % (request.getUser(), request.getClientIP())
+ defer.returnValue(handler(header, request))
if p2pool.DEBUG:
id = random.randrange(1000, 10000)
res, orig_timestamp, handler = self.work_cache.pop(key)
else:
res, handler = self.worker_bridge.get_work(*key)
- assert res.merkle_root not in self.merkle_root_to_handler
+ assert res.merkle_root not in self.merkle_roots
orig_timestamp = res.timestamp
- self.merkle_root_to_handler[res.merkle_root] = handler
+ self.merkle_roots[res.merkle_root] = handler, orig_timestamp
if res.timestamp + 12 < orig_timestamp + 600:
self.work_cache[key] = res.update(timestamp=res.timestamp + 12), orig_timestamp, handler