diff --git a/p2pool/dash/stratum.py b/p2pool/dash/stratum.py index 365df882..c5ea8c5e 100644 --- a/p2pool/dash/stratum.py +++ b/p2pool/dash/stratum.py @@ -72,8 +72,20 @@ def rpc_submit(self, worker_name, job_id, extranonce2, ntime, nonce): bits=x['bits'], nonce=pack.IntType(32).unpack(getwork._swap4(nonce.decode('hex'))), ) - return got_response(header, worker_name, coinb_nonce) - + res = got_response(header, worker_name, coinb_nonce) + + # Disconnect miners with large DOA rates to prevent DoS + 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() + + # 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 + def close(self): self.wb.new_work_event.unwatch(self.watch_id) diff --git a/p2pool/work.py b/p2pool/work.py index 1a6637ee..aa5b7460 100644 --- a/p2pool/work.py +++ b/p2pool/work.py @@ -50,6 +50,9 @@ def __init__(self, node, my_pubkey_hash, donation_percentage, merged_urls, worke self.my_share_hashes = set() self.my_doa_share_hashes = set() + self.invalid_hashes = 0 + self.total_hashes = 0 + self.address_throttle = 0 self.tracker_view = forest.TrackerView(self.node.tracker, forest.get_attributedelta_type(dict(forest.AttributeDelta.attrs, @@ -477,10 +480,13 @@ def _(err): self.share_received.happened(dash_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: