Skip to content

Sliding window long polling rate limit #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
11 changes: 8 additions & 3 deletions HttpTransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def send_internal(self, result, nonce):
def long_poll_thread(self):
last_host = None
while True:
sleep(1)
url = self.long_poll_url
if url != '':
proto = self.proto
Expand Down Expand Up @@ -165,12 +164,17 @@ def long_poll_thread(self):
say_line('long poll: new block %s%s', (result['result']['data'][56:64], result['result']['data'][48:56]))
except NotAuthorized:
say_line('long poll: Wrong username or password')
sleep(.5)
except RPCError as e:
say_line('long poll: %s', e)
sleep(.5)
except (IOError, httplib.HTTPException, ValueError):
say_line('long poll: IO error')
#traceback.print_exc()
self.close_lp_connection()
sleep(.5)
else:
sleep(.5)

def stop(self):
self.should_stop = True
Expand All @@ -179,7 +183,7 @@ def stop(self):
def set_server(self, server):
super(HttpTransport, self).set_server(server)
user, pwd = server[1:3]
self.headers = {"User-Agent": self.user_agent, "Authorization": 'Basic ' + b64encode('%s:%s' % (user, pwd))}
self.headers = {"User-Agent": self.user_agent, "Authorization": 'Basic ' + b64encode('%s:%s' % (user, pwd)), 'X-Work-Identifier': '1'}
self.long_poll_url = ''
if self.connection:
self.connection.close()
Expand Down Expand Up @@ -211,7 +215,8 @@ def decode(self, work):
job.f = np.zeros(8, np.uint32)
job.state2 = partial(job.state, job.merkle_end, job.time, job.difficulty, job.f)
job.targetQ = 2**256 / int(''.join(list(chunks(work['target'], 2))[::-1]), 16)
job.identifier = (1, work['identifier']) if 'identifier' in work else (0, job.header[25:29])

calculateF(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2)

return job
return job
4 changes: 2 additions & 2 deletions Transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def queue_work(self, work):
self.miner.work_queue.put(work)
if work:
self.update = False; self.last_work = time()
if self.last_block != work.header[25:29]:
self.last_block = work.header[25:29]
if self.last_block != work.identifier:
self.last_block = work.identifier
self.clear_result_queue()

def clear_result_queue(self):
Expand Down