bump protocol version

This commit is contained in:
Victor Shyba 2019-11-25 17:54:23 -03:00 committed by Lex Berezhny
parent 58df2b9bcf
commit cec6dca72f
2 changed files with 11 additions and 4 deletions

View file

@ -95,7 +95,8 @@ class LBRYSessionManager(SessionManager):
class LBRYElectrumX(ElectrumX): class LBRYElectrumX(ElectrumX):
PROTOCOL_MIN = (0, 0) # temporary, for supporting 0.10 protocol PROTOCOL_MIN = (2, 0) # v0.48 is backwards incompatible, forking a new protocol
PROTOCOL_MAX = (2, 0)
max_errors = math.inf # don't disconnect people for errors! let them happen... max_errors = math.inf # don't disconnect people for errors! let them happen...
session_mgr: LBRYSessionManager session_mgr: LBRYSessionManager
version = sdk_version version = sdk_version
@ -111,7 +112,7 @@ class LBRYElectrumX(ElectrumX):
self.filtering_channels_ids = list(filter(None, filtering_channels.split(' '))) self.filtering_channels_ids = list(filter(None, filtering_channels.split(' ')))
def set_request_handlers(self, ptuple): def set_request_handlers(self, ptuple):
super().set_request_handlers(ptuple) super().set_request_handlers((1, 2) if ptuple == (2, 0) else ptuple) # our "2.0" is electrumx 1.2
handlers = { handlers = {
'blockchain.transaction.get_height': self.transaction_get_height, 'blockchain.transaction.get_height': self.transaction_get_height,
'blockchain.claimtrie.search': self.claimtrie_search, 'blockchain.claimtrie.search': self.claimtrie_search,

View file

@ -13,6 +13,8 @@ log = logging.getLogger(__name__)
class ClientSession(BaseClientSession): class ClientSession(BaseClientSession):
PROTOCOL_VERSION = '2.0'
def __init__(self, *args, network, server, timeout=30, on_connect_callback=None, **kwargs): def __init__(self, *args, network, server, timeout=30, on_connect_callback=None, **kwargs):
self.network = network self.network = network
self.server = server self.server = server
@ -102,6 +104,9 @@ class ClientSession(BaseClientSession):
if (perf_counter() - self.last_send) > self.max_seconds_idle or self.response_time is None: if (perf_counter() - self.last_send) > self.max_seconds_idle or self.response_time is None:
await self.ensure_server_version() await self.ensure_server_version()
retry_delay = default_delay retry_delay = default_delay
except RPCError as e:
log.warning("Server error, ignoring for 1h: %s:%d -- %s", *self.server, e.message)
retry_delay = 60 * 60
except (asyncio.TimeoutError, OSError): except (asyncio.TimeoutError, OSError):
await self.close() await self.close()
retry_delay = min(60, retry_delay * 2) retry_delay = min(60, retry_delay * 2)
@ -113,9 +118,10 @@ class ClientSession(BaseClientSession):
finally: finally:
self.trigger_urgent_reconnect.clear() self.trigger_urgent_reconnect.clear()
async def ensure_server_version(self, required='1.2', timeout=3): async def ensure_server_version(self, required=None, timeout=3):
return await asyncio.wait_for( return await asyncio.wait_for(
self.send_request('server.version', [__version__, required]), timeout=timeout self.send_request(
'server.version', [__version__, required or self.PROTOCOL_VERSION]), timeout=timeout
) )
async def create_connection(self, timeout=6): async def create_connection(self, timeout=6):