Skip to content

Commit

Permalink
Merge branch 'vardiff' of https://github.com/vertcoin/p2pool-vtc into…
Browse files Browse the repository at this point in the history
… vardiff
  • Loading branch information
metalicjames committed Nov 13, 2017
2 parents dee4690 + d18bc96 commit e51ba5a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions p2pool/bitcoin/stratum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion p2pool/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e51ba5a

Please sign in to comment.