From 3a0ce58cdab8a37c67faea238268d50a5a78d7ea Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 8 Nov 2019 12:52:39 -0300 Subject: [PATCH] send back correct server version --- lbry/lbry/wallet/server/session.py | 2 ++ lbry/tests/integration/test_wallet_server_sessions.py | 7 ++++++- torba/torba/server/session.py | 11 ++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lbry/lbry/wallet/server/session.py b/lbry/lbry/wallet/server/session.py index be7cfd0c0..5df97444f 100644 --- a/lbry/lbry/wallet/server/session.py +++ b/lbry/lbry/wallet/server/session.py @@ -16,6 +16,7 @@ from lbry.wallet.server.db.writer import LBRYDB from lbry.wallet.server.db import reader from lbry.wallet.server.websocket import AdminWebSocket from lbry.wallet.server.metrics import ServerLoadData, APICallMetrics +from lbry import __version__ as sdk_version class ResultCacheItem: @@ -94,6 +95,7 @@ class LBRYElectrumX(ElectrumX): PROTOCOL_MIN = (0, 0) # temporary, for supporting 0.10 protocol max_errors = math.inf # don't disconnect people for errors! let them happen... session_mgr: LBRYSessionManager + version = sdk_version def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/lbry/tests/integration/test_wallet_server_sessions.py b/lbry/tests/integration/test_wallet_server_sessions.py index 3ac714ce6..ba6a92cb8 100644 --- a/lbry/tests/integration/test_wallet_server_sessions.py +++ b/lbry/tests/integration/test_wallet_server_sessions.py @@ -2,13 +2,14 @@ import asyncio import os import lbry.wallet +from lbry import __version__ as sdk_version from lbry.testcase import CommandTestCase from lbry.extras.daemon.Components import HeadersComponent from torba.client.basenetwork import ClientSession from torba.testcase import IntegrationTestCase -class TestSessionBloat(IntegrationTestCase): +class TestSessions(IntegrationTestCase): """ Tests that server cleans up stale connections after session timeout and client times out too. """ @@ -33,6 +34,10 @@ class TestSessionBloat(IntegrationTestCase): self.assertTrue(session.is_closing()) self.assertEqual(len(self.conductor.spv_node.server.session_mgr.sessions), 0) + async def test_proper_version(self): + info = await self.ledger.network.get_server_features() + self.assertEqual(sdk_version, info['server_version']) + class TestSegwitServer(IntegrationTestCase): LEDGER = lbry.wallet diff --git a/torba/torba/server/session.py b/torba/torba/server/session.py index edee37d6e..6f92e894a 100644 --- a/torba/torba/server/session.py +++ b/torba/torba/server/session.py @@ -618,6 +618,7 @@ class SessionBase(RPCSession): MAX_CHUNK_SIZE = 2016 session_counter = itertools.count() request_handlers: typing.Dict[str, typing.Callable] = {} + version = '0.5.7' def __init__(self, session_mgr, db, mempool, peer_mgr, kind): connection = JSONRPCConnection(JSONRPCAutoDetect) @@ -742,7 +743,7 @@ class ElectrumX(SessionBase): return { 'hosts': env.hosts_dict(), 'pruning': None, - 'server_version': torba.__version__, + 'server_version': cls.version, 'protocol_min': min_str, 'protocol_max': max_str, 'genesis_hash': env.coin.GENESIS_HASH, @@ -758,7 +759,7 @@ class ElectrumX(SessionBase): @classmethod def server_version_args(cls): """The arguments to a server.version RPC call to a peer.""" - return [torba.__version__, cls.protocol_min_max_strings()] + return [cls.version, cls.protocol_min_max_strings()] def protocol_version_string(self): return util.version_string(self.protocol_tuple) @@ -1063,7 +1064,7 @@ class ElectrumX(SessionBase): revision //= 100 daemon_version = f'{major:d}.{minor:d}.{revision:d}' for pair in [ - ('$SERVER_VERSION', torba.__version__), + ('$SERVER_VERSION', self.version), ('$DAEMON_VERSION', daemon_version), ('$DAEMON_SUBVERSION', network_info['subversion']), ('$DONATION_ADDRESS', self.env.donation_address), @@ -1077,7 +1078,7 @@ class ElectrumX(SessionBase): async def banner(self): """Return the server banner text.""" - banner = f'You are connected to an {torba.__version__} server.' + banner = f'You are connected to an {self.version} server.' if self.is_tor(): banner_file = self.env.tor_banner_file @@ -1147,7 +1148,7 @@ class ElectrumX(SessionBase): f'unsupported protocol version: {protocol_version}') self.set_request_handlers(ptuple) - return torba.__version__, self.protocol_version_string() + return self.version, self.protocol_version_string() async def transaction_broadcast(self, raw_tx): """Broadcast a raw transaction to the network.