From 3cbeadfbc3160a7fe4246d9247d54477e348e12d Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 3 Mar 2020 20:04:57 -0500 Subject: [PATCH 1/2] lbrynet status command returns features available of currenty connected wallet server, including thetrending algorithm used --- lbry/extras/daemon/components.py | 1 + lbry/wallet/network.py | 4 ++++ lbry/wallet/server/db/writer.py | 2 +- lbry/wallet/server/env.py | 1 + lbry/wallet/server/session.py | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index fe045a6c2..7de4d9fe2 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -121,6 +121,7 @@ class WalletComponent(Component): connected = f"{addr_and_port[0]}:{addr_and_port[1]}" result = { 'connected': connected, + 'connected_features': self.wallet_manager.ledger.network.server_features, 'servers': [ { 'host': session.server[0], diff --git a/lbry/wallet/network.py b/lbry/wallet/network.py index 4e821499d..f0739fa1c 100644 --- a/lbry/wallet/network.py +++ b/lbry/wallet/network.py @@ -162,6 +162,7 @@ class Network: self.ledger = ledger self.session_pool = SessionPool(network=self, timeout=self.config.get('connect_timeout', 6)) self.client: Optional[ClientSession] = None + self.server_features = None self._switch_task: Optional[asyncio.Task] = None self.running = False self.remote_height: int = 0 @@ -189,17 +190,20 @@ class Network: while self.running: if self.is_connected: await self.client.on_disconnected.first + self.server_features = None self.client = None continue self.client = await self.session_pool.wait_for_fastest_session() log.info("Switching to SPV wallet server: %s:%d", *self.client.server) try: + self.server_features = await self.get_server_features() self._update_remote_height((await self.subscribe_headers(),)) self._on_connected_controller.add(True) log.info("Subscribed to headers: %s:%d", *self.client.server) except (asyncio.TimeoutError, ConnectionError): log.info("Switching to %s:%d timed out, closing and retrying.", *self.client.server) self.client.synchronous_close() + self.server_features = None self.client = None async def start(self): diff --git a/lbry/wallet/server/db/writer.py b/lbry/wallet/server/db/writer.py index 30afc743a..cb9ad07ea 100644 --- a/lbry/wallet/server/db/writer.py +++ b/lbry/wallet/server/db/writer.py @@ -866,7 +866,7 @@ class LBRYLevelDB(LevelDB): super().__init__(*args, **kwargs) path = os.path.join(self.env.db_dir, 'claims.db') trending = [] - for algorithm_name in set(self.env.default('TRENDING_ALGORITHMS', 'zscore').split(' ')): + for algorithm_name in self.env.trending_algorithms: if algorithm_name in TRENDING_ALGORITHMS: trending.append(TRENDING_ALGORITHMS[algorithm_name]) self.sql = SQLDB( diff --git a/lbry/wallet/server/env.py b/lbry/wallet/server/env.py index 4d766b416..173137257 100644 --- a/lbry/wallet/server/env.py +++ b/lbry/wallet/server/env.py @@ -37,6 +37,7 @@ class Env: self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK']) self.db_dir = self.required('DB_DIRECTORY') self.db_engine = self.default('DB_ENGINE', 'leveldb') + self.trending_algorithms = list(set(self.default('TRENDING_ALGORITHMS', 'zscore').split(' '))) self.max_query_workers = self.integer('MAX_QUERY_WORKERS', None) self.individual_tag_indexes = self.boolean('INDIVIDUAL_TAG_INDEXES', True) self.track_metrics = self.boolean('TRACK_METRICS', False) diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index a8d59b0c9..77e9bdcf6 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -863,6 +863,7 @@ class LBRYElectrumX(SessionBase): 'donation_address': env.donation_address, 'daily_fee': env.daily_fee, 'hash_function': 'sha256', + 'trending_algorithm': env.trending_algorithms } async def server_features_async(self): From 05228529b032ed16adb0bdcaedbdc2b9cbb21b2c Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Tue, 3 Mar 2020 20:26:07 -0500 Subject: [PATCH 2/2] fix tests --- lbry/wallet/server/session.py | 2 +- tests/integration/blockchain/test_network.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lbry/wallet/server/session.py b/lbry/wallet/server/session.py index 77e9bdcf6..d343bb2f3 100644 --- a/lbry/wallet/server/session.py +++ b/lbry/wallet/server/session.py @@ -863,7 +863,7 @@ class LBRYElectrumX(SessionBase): 'donation_address': env.donation_address, 'daily_fee': env.daily_fee, 'hash_function': 'sha256', - 'trending_algorithm': env.trending_algorithms + 'trending_algorithm': env.trending_algorithms[0] } async def server_features_async(self): diff --git a/tests/integration/blockchain/test_network.py b/tests/integration/blockchain/test_network.py index 6f87cdc37..95400e321 100644 --- a/tests/integration/blockchain/test_network.py +++ b/tests/integration/blockchain/test_network.py @@ -30,7 +30,9 @@ class NetworkTests(IntegrationTestCase): 'payment_address': '', 'donation_address': '', 'daily_fee': '0', - 'server_version': lbry.__version__}, await self.ledger.network.get_server_features()) + 'server_version': lbry.__version__, + 'trending_algorithm': 'zscore', + }, await self.ledger.network.get_server_features()) await self.conductor.spv_node.stop() payment_address, donation_address = await self.account.get_addresses(limit=2) await self.conductor.spv_node.start( @@ -54,7 +56,9 @@ class NetworkTests(IntegrationTestCase): 'payment_address': payment_address, 'donation_address': donation_address, 'daily_fee': '42', - 'server_version': lbry.__version__}, await self.ledger.network.get_server_features()) + 'server_version': lbry.__version__, + 'trending_algorithm': 'zscore', + }, await self.ledger.network.get_server_features()) class ReconnectTests(IntegrationTestCase):