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):