interface: workaround electrs erroring on 'blockchain.estimatefee'
15.00 | E | i/interface.[electrum.blockstream.info:50002] | Exception in run: ProtocolError(-32600, 'ill-formed response error object: cannot estimate fee for 25 blocks')
Traceback (most recent call last):
File "...\electrum\electrum\util.py", line 1261, in wrapper
return await func(*args, **kwargs)
File "...\electrum\electrum\interface.py", line 516, in wrapper_func
return await func(self, *args, **kwargs)
File "...\electrum\electrum\interface.py", line 539, in run
await self.open_session(ssl_context)
File "...\electrum\electrum\interface.py", line 689, in open_session
async with self.taskgroup as group:
File "...\aiorpcX\aiorpcx\curio.py", line 304, in __aexit__
await self.join()
File "...\electrum\electrum\util.py", line 1423, in join
task.result()
File "...\electrum\electrum\interface.py", line 726, in request_fee_estimates
async with OldTaskGroup() as group:
File "...\aiorpcX\aiorpcx\curio.py", line 304, in __aexit__
await self.join()
File "...\electrum\electrum\util.py", line 1423, in join
task.result()
File "...\electrum\electrum\interface.py", line 1128, in get_estimatefee
res = await self.session.send_request('blockchain.estimatefee', [num_blocks])
File "...\electrum\electrum\interface.py", line 171, in send_request
response = await asyncio.wait_for(
File "...\Python310\lib\asyncio\tasks.py", line 408, in wait_for
return await fut
File "...\aiorpcX\aiorpcx\session.py", line 540, in send_request
return await self._send_concurrent(message, future, 1)
File "...\aiorpcX\aiorpcx\session.py", line 512, in _send_concurrent
return await future
File "...\aiorpcX\aiorpcx\jsonrpc.py", line 721, in receive_message
item, request_id = self._protocol.message_to_item(message)
File "...\aiorpcX\aiorpcx\jsonrpc.py", line 273, in message_to_item
return cls._process_response(payload)
File "...\aiorpcX\aiorpcx\jsonrpc.py", line 220, in _process_response
raise cls._error(code, message, False, request_id)
aiorpcx.jsonrpc.ProtocolError: (-32600, 'ill-formed response error object: cannot estimate fee for 25 blocks')
This commit is contained in:
@@ -1121,11 +1121,21 @@ class Interface(Logger):
|
||||
async def get_estimatefee(self, num_blocks: int) -> int:
|
||||
"""Returns a feerate estimate for getting confirmed within
|
||||
num_blocks blocks, in sat/kbyte.
|
||||
Returns -1 if the server could not provide an estimate.
|
||||
"""
|
||||
if not is_non_negative_integer(num_blocks):
|
||||
raise Exception(f"{repr(num_blocks)} is not a num_blocks")
|
||||
# do request
|
||||
res = await self.session.send_request('blockchain.estimatefee', [num_blocks])
|
||||
try:
|
||||
res = await self.session.send_request('blockchain.estimatefee', [num_blocks])
|
||||
except aiorpcx.jsonrpc.ProtocolError as e:
|
||||
# The protocol spec says the server itself should already have returned -1
|
||||
# if it cannot provide an estimate, however apparently electrs does not conform
|
||||
# and sends an error instead. Convert it here:
|
||||
if "cannot estimate fee" in e.message:
|
||||
res = -1
|
||||
else:
|
||||
raise
|
||||
# check response
|
||||
if res != -1:
|
||||
assert_non_negative_int_or_float(res)
|
||||
|
||||
Reference in New Issue
Block a user