Merge pull request #3161 from lbryio/ledger-compatibility

handle connections from ledger clients in spv server
This commit is contained in:
Jack Robison 2021-01-22 00:09:50 -05:00 committed by GitHub
commit 575e471553
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 16 deletions

View file

@ -344,7 +344,7 @@ class MemPool:
value += sum(v for h168, v in tx.out_pairs if h168 == hashX) value += sum(v for h168, v in tx.out_pairs if h168 == hashX)
return value return value
async def compact_fee_histogram(self): def compact_fee_histogram(self):
"""Return a compact fee histogram of the current mempool.""" """Return a compact fee histogram of the current mempool."""
return self.cached_compact_histogram return self.cached_compact_histogram

View file

@ -923,7 +923,7 @@ class LBRYElectrumX(SessionBase):
self.hashX_subs = {} self.hashX_subs = {}
self.sv_seen = False self.sv_seen = False
self.protocol_tuple = self.PROTOCOL_MIN self.protocol_tuple = self.PROTOCOL_MIN
self.protocol_string = None
self.daemon = self.session_mgr.daemon self.daemon = self.session_mgr.daemon
self.bp: LBRYBlockProcessor = self.session_mgr.bp self.bp: LBRYBlockProcessor = self.session_mgr.bp
self.db: LBRYLevelDB = self.bp.db self.db: LBRYLevelDB = self.bp.db
@ -1474,7 +1474,8 @@ class LBRYElectrumX(SessionBase):
client_name: a string identifying the client client_name: a string identifying the client
protocol_version: the protocol version spoken by the client protocol_version: the protocol version spoken by the client
""" """
if self.protocol_string is not None:
return self.version, self.protocol_string
if self.sv_seen and self.protocol_tuple >= (1, 4): if self.sv_seen and self.protocol_tuple >= (1, 4):
raise RPCError(BAD_REQUEST, f'server.version already sent') raise RPCError(BAD_REQUEST, f'server.version already sent')
self.sv_seen = True self.sv_seen = True
@ -1484,8 +1485,7 @@ class LBRYElectrumX(SessionBase):
if self.env.drop_client is not None and \ if self.env.drop_client is not None and \
self.env.drop_client.match(client_name): self.env.drop_client.match(client_name):
self.close_after_send = True self.close_after_send = True
raise RPCError(BAD_REQUEST, raise RPCError(BAD_REQUEST, f'unsupported client: {client_name}')
f'unsupported client: {client_name}')
if self.client_version != client_name[:17]: if self.client_version != client_name[:17]:
self.session_mgr.session_count_metric.labels(version=self.client_version).dec() self.session_mgr.session_count_metric.labels(version=self.client_version).dec()
self.client_version = client_name[:17] self.client_version = client_name[:17]
@ -1494,19 +1494,16 @@ class LBRYElectrumX(SessionBase):
# Find the highest common protocol version. Disconnect if # Find the highest common protocol version. Disconnect if
# that protocol version in unsupported. # that protocol version in unsupported.
ptuple, client_min = util.protocol_version( ptuple, client_min = util.protocol_version(protocol_version, self.PROTOCOL_MIN, self.PROTOCOL_MAX)
protocol_version, self.PROTOCOL_MIN, self.PROTOCOL_MAX)
if ptuple is None: if ptuple is None:
# FIXME: this fills the logs ptuple, client_min = util.protocol_version(protocol_version, (1, 1, 0), (1, 4, 0))
# if client_min > self.PROTOCOL_MIN: if ptuple is None:
# self.logger.info(f'client requested future protocol version ' self.close_after_send = True
# f'{util.version_string(client_min)} ' raise RPCError(BAD_REQUEST, f'unsupported protocol version: {protocol_version}')
# f'- is your software out of date?')
self.close_after_send = True
raise RPCError(BAD_REQUEST,
f'unsupported protocol version: {protocol_version}')
self.protocol_tuple = ptuple self.protocol_tuple = ptuple
return self.version, self.protocol_version_string() self.protocol_string = util.version_string(ptuple)
return self.version, self.protocol_string
async def transaction_broadcast(self, raw_tx): async def transaction_broadcast(self, raw_tx):
"""Broadcast a raw transaction to the network. """Broadcast a raw transaction to the network.