diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index b5a9401e5..55e1d99f6 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -887,7 +887,6 @@ class LBRYumWallet(Wallet): self._lag_counter = 0 self.blocks_behind = 0 self.catchup_progress = 0 - self.max_behind = 0 def _is_first_run(self): return (not self.printed_retrieving_headers and @@ -975,57 +974,28 @@ class LBRYumWallet(Wallet): def _load_blockchain(self): blockchain_caught_d = defer.Deferred() - def check_caught_up(): - local_height = self.network.get_catchup_progress() + def on_update_callback(event, *args): + # This callback is called by lbryum when something chain + # related has happened + local_height = self.network.get_local_height() remote_height = self.network.get_server_height() + updated_blocks_behind = self.network.get_blocks_behind() + log.info( + 'Local Height: %s, remote height: %s, behind: %s', + local_height, remote_height, updated_blocks_behind) - if remote_height == 0: + self.blocks_behind = updated_blocks_behind + if local_height != remote_height: return - height_diff = remote_height - local_height + assert self.blocks_behind == 0 + self.network.unregister_callback(on_update_callback) + log.info("Wallet Loaded") + reactor.callFromThread(blockchain_caught_d.callback, True) - if height_diff <= 5: - self.blocks_behind = 0 - msg = "" - if self._caught_up_counter != 0: - msg += "All caught up. " - msg += "Wallet loaded." - log.info(msg) - self._catch_up_check.stop() - self._catch_up_check = None - blockchain_caught_d.callback(True) - return + self.network.register_callback(on_update_callback, ['updated']) - if height_diff < self.blocks_behind: - # We're making progress in catching up - self._lag_counter = 0 - self.is_lagging = False - else: - # No progress. Might be lagging - self._lag_counter += 1 - if self._lag_counter >= 900: - self.is_lagging = True - - self.blocks_behind = height_diff - - if self.blocks_behind > self.max_behind: - self.max_behind = self.blocks_behind - self.catchup_progress = int(100 * (self.blocks_behind / (5 + self.max_behind))) - if self._caught_up_counter == 0: - log.info('Catching up with the blockchain') - if self._caught_up_counter % 30 == 0: - log.info('Blocks left: %d', (remote_height - local_height)) - - self._caught_up_counter += 1 - - def log_error(err): - log.warning(err.getErrorMessage()) - return defer.fail(err) - - self._catch_up_check = task.LoopingCall(check_caught_up) d = defer.succeed(self.wallet.start_threads(self.network)) - d.addCallback(lambda _: self._catch_up_check.start(.1)) - d.addErrback(log_error) d.addCallback(lambda _: blockchain_caught_d) return d diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index e46bcdfe5..edb7b81a6 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -82,13 +82,10 @@ STREAM_STAGES = [ CONNECTION_STATUS_CONNECTED = 'connected' CONNECTION_STATUS_VERSION_CHECK = 'version_check' CONNECTION_STATUS_NETWORK = 'network_connection' -CONNECTION_STATUS_WALLET = 'wallet_catchup_lag' CONNECTION_MESSAGES = { CONNECTION_STATUS_CONNECTED: 'No connection problems detected', CONNECTION_STATUS_VERSION_CHECK: "There was a problem checking for updates on github", CONNECTION_STATUS_NETWORK: "Your internet connection appears to have been interrupted", - CONNECTION_STATUS_WALLET: "Catching up with the blockchain is slow. " + - "If this continues try restarting LBRY", } PENDING_ID = "not set" @@ -387,9 +384,6 @@ class Daemon(AuthJSONRPCServer): if not self.git_lbrynet_version or not self.git_lbryum_version: self.connection_status_code = CONNECTION_STATUS_VERSION_CHECK - elif self.startup_status[0] == 'loading_wallet' and self.session.wallet.is_lagging: - self.connection_status_code = CONNECTION_STATUS_WALLET - if not self.connected_to_internet: self.connection_status_code = CONNECTION_STATUS_NETWORK @@ -1122,7 +1116,7 @@ class Daemon(AuthJSONRPCServer): progress = 0 if status['blocks_behind'] > 0: message += ' ' + str(status['blocks_behind']) + " blocks behind." - progress = self.session.wallet.catchup_progress + progress = status['blocks_behind'] return { 'message': message,