Skip to content

Commit

Permalink
daemon: catch RPC_PARSE_ERROR from bitcoind and simply retry
Browse files Browse the repository at this point in the history
see #238

So far it is unclear why bitcoind sends RPC_PARSE_ERROR, but
instead of doing a full shutdown, let's log the error(+request) and retry.
  • Loading branch information
SomberNight committed Nov 28, 2023
1 parent 3b802c7 commit 3148936
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions electrumx/server/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ class ServiceRefusedError(Exception):
some reason.'''


class DaemonParseError(Exception):
'''Internal - when the daemon returns an RPC_PARSE_ERROR.'''


class Daemon:
'''Handles connections to a daemon at the given URL.'''

RPC_IN_WARMUP = -28
RPC_PARSE_ERROR = -32700

id_counter = itertools.count()

Expand Down Expand Up @@ -172,6 +177,9 @@ def log_error(error):
except WarmingUpError:
log_error('starting up checking blocks')
on_good_message = 'running normally'
except DaemonParseError as e:
log_error(f"received RPC_PARSE_ERROR ({e=!r}). request was: {data=!r}")
on_good_message = 'running normally'

await asyncio.sleep(retry)
retry = max(min(self.max_retry, retry * 2), self.init_retry)
Expand All @@ -184,6 +192,8 @@ def processor(result):
return result['result']
if err.get('code') == self.RPC_IN_WARMUP:
raise WarmingUpError
if err.get('code') == self.RPC_PARSE_ERROR:
raise DaemonParseError(err)
raise DaemonError(err)

payload = {'method': method, 'id': next(self.id_counter)}
Expand All @@ -201,6 +211,8 @@ def processor(result):
errs = [item['error'] for item in result if item['error']]
if any(err.get('code') == self.RPC_IN_WARMUP for err in errs):
raise WarmingUpError
if any(err.get('code') == self.RPC_PARSE_ERROR for err in errs):
raise DaemonParseError
if not errs or replace_errs:
return [item['result'] for item in result]
raise DaemonError(errs)
Expand Down

0 comments on commit 3148936

Please sign in to comment.