diff --git a/p2pool/bitcoin/stratum.py b/p2pool/bitcoin/stratum.py index f9e31980..75095187 100644 --- a/p2pool/bitcoin/stratum.py +++ b/p2pool/bitcoin/stratum.py @@ -72,12 +72,18 @@ def rpc_submit(self, worker_name, job_id, extranonce2, ntime, nonce): nonce=pack.IntType(32).unpack(getwork._swap4(nonce.decode('hex'))), ) - # Disconnect miners with large DOA rates to prevent DoS + # Disconnect miners with large DOA rates to prevent DoS res = got_response(header, worker_name, coinb_nonce) - if len(self.wb._inner.my_share_hashes) > 20: + if len(self.wb._inner.my_share_hashes) > 20: if float(len(self.wb._inner.my_doa_share_hashes)) / float(len(self.wb._inner.my_share_hashes)) > 0.60: + self.transport.loseConnection() + return res + + # Disconnect miners with large hash > target to prevent DoS + if self.wb._inner.total_hashes > 20: + if float(self.wb._inner.invalid_hashes) / float(self.wb._inner.total_hashes) > 0.05: self.transport.loseConnection() - return res + return res def close(self): self.wb.new_work_event.unwatch(self.watch_id) diff --git a/p2pool/work.py b/p2pool/work.py index 90e7f92e..9b81d353 100644 --- a/p2pool/work.py +++ b/p2pool/work.py @@ -51,6 +51,9 @@ def __init__(self, node, my_pubkey_hash, donation_percentage, merged_urls, worke self.last_work_shares = variable.Variable( {} ) self.my_share_hashes = set() self.my_doa_share_hashes = set() + + self.invalid_hashes = 0 + self.total_hashes = 0 self.address_throttle = 0 @@ -176,7 +179,7 @@ def get_user_details(self, username): desired_pseudoshare_target = None desired_share_target = None - for symbol, parameter in zip(contents2[::2], contents2[1::2]): + '''for symbol, parameter in zip(contents2[::2], contents2[1::2]): if symbol == '+': try: desired_pseudoshare_target = bitcoin_data.difficulty_to_target_alt(float(parameter), self.node.net.PARENT.DUMB_SCRYPT_DIFF) @@ -189,6 +192,7 @@ def get_user_details(self, username): except: if p2pool.DEBUG: log.err() + ''' if self.args.address == 'dynamic': i = self.pubkeys.weighted() @@ -510,10 +514,13 @@ def _(err): self.share_received.happened(bitcoin_data.target_to_average_attempts(share.target), not on_time, share.hash) + self.total_hashes += 1 + if pow_hash > target: print 'Worker %s submitted share with hash > target:' % (user,) print ' Hash: %56x' % (pow_hash,) print ' Target: %56x' % (target,) + self.invalid_hashes += 1 elif header_hash in received_header_hashes: print >>sys.stderr, 'Worker %s submitted share more than once!' % (user,) else: