Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions p2pool/dash/stratum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions p2pool/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down