From 43451c485f3ccab4beb389c27ea2c9cea862b0a7 Mon Sep 17 00:00:00 2001 From: jobevers Date: Sat, 28 Jan 2017 08:00:39 -0800 Subject: [PATCH 1/5] change alerts to logs --- lbrynet/core/Wallet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 77af430d2..e898e4061 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -24,8 +24,8 @@ from lbrynet.core.Error import (UnknownNameError, InvalidStreamInfoError, Reques from lbrynet.db_migrator.migrate1to2 import UNSET_NOUT from lbrynet.metadata.Metadata import Metadata + log = logging.getLogger(__name__) -alert = logging.getLogger("lbryalert." + __name__) class ReservedPoints(object): @@ -895,7 +895,7 @@ class LBRYumWallet(Wallet): def setup_network(): self.config = make_config(self._config) self.network = Network(self.config) - alert.info("Loading the wallet") + log.info("Loading the wallet") return defer.succeed(self.network.start()) d = setup_network() @@ -904,7 +904,7 @@ class LBRYumWallet(Wallet): if self.network.is_connecting(): if not self.printed_retrieving_headers and \ self.network.blockchain.retrieving_headers: - alert.info("Running the wallet for the first time. This may take a moment.") + log.info("Running the wallet for the first time. This may take a moment.") self.printed_retrieving_headers = True return False self._start_check.stop() @@ -988,7 +988,7 @@ https://github.com/lbryio/lbry/issues/437 to reduce your wallet size") if self._caught_up_counter != 0: msg += "All caught up. " msg += "Wallet loaded." - alert.info(msg) + log.info(msg) self._catch_up_check.stop() self._catch_up_check = None blockchain_caught_d.callback(True) @@ -1010,9 +1010,9 @@ https://github.com/lbryio/lbry/issues/437 to reduce your wallet size") self.max_behind = self.blocks_behind self.catchup_progress = int(100 * (self.blocks_behind / (5 + self.max_behind))) if self._caught_up_counter == 0: - alert.info('Catching up with the blockchain') + log.info('Catching up with the blockchain') if self._caught_up_counter % 30 == 0: - alert.info('Blocks left: %d', (remote_height - local_height)) + log.info('Blocks left: %d', (remote_height - local_height)) self._caught_up_counter += 1 From 04ee2f786dc71047add1314dee2dece0c3d3ee55 Mon Sep 17 00:00:00 2001 From: jobevers Date: Sat, 28 Jan 2017 08:06:29 -0800 Subject: [PATCH 2/5] remove backslash line continuation --- lbrynet/core/Wallet.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index e898e4061..14aad4535 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -889,6 +889,10 @@ class LBRYumWallet(Wallet): self.catchup_progress = 0 self.max_behind = 0 + def _is_first_run(self): + return (not self.printed_retrieving_headers and + self.network.blockchain.retrieving_headers) + def _start(self): network_start_d = defer.Deferred() @@ -902,8 +906,7 @@ class LBRYumWallet(Wallet): def check_started(): if self.network.is_connecting(): - if not self.printed_retrieving_headers and \ - self.network.blockchain.retrieving_headers: + if self._is_first_run(): log.info("Running the wallet for the first time. This may take a moment.") self.printed_retrieving_headers = True return False @@ -967,8 +970,8 @@ class LBRYumWallet(Wallet): def _check_large_wallet(self): if len(self.wallet.addresses(include_change=False)) > 1000: - log.warning("Your wallet is excessively large, please follow instructions here: \ -https://github.com/lbryio/lbry/issues/437 to reduce your wallet size") + log.warning(("Your wallet is excessively large, please follow instructions here: ", + "https://github.com/lbryio/lbry/issues/437 to reduce your wallet size")) def _load_blockchain(self): blockchain_caught_d = defer.Deferred() @@ -1207,8 +1210,9 @@ class LBRYcrdAddressRequester(object): # ======== internal calls ======== # def _handle_address_response(self, response_dict, peer, request, protocol): - assert request.response_identifier in response_dict, \ - "Expected %s in dict but did not get it" % request.response_identifier + if request.response_identifier not in response_dict: + raise ValueError( + "Expected {} in response but did not get it".format(request.response_identifier)) assert protocol in self._protocols, "Responding protocol is not in our list of protocols" address = response_dict[request.response_identifier] self.wallet.update_peer_address(peer, address) From 7360015fa4b5ad604d0b86bbe6ab09f8089e1711 Mon Sep 17 00:00:00 2001 From: jobevers Date: Sat, 28 Jan 2017 10:55:59 -0800 Subject: [PATCH 3/5] small refactor --- lbrynet/core/Wallet.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 14aad4535..b5a9401e5 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -895,15 +895,13 @@ class LBRYumWallet(Wallet): def _start(self): network_start_d = defer.Deferred() + self.config = make_config(self._config) def setup_network(): - self.config = make_config(self._config) self.network = Network(self.config) log.info("Loading the wallet") return defer.succeed(self.network.start()) - d = setup_network() - def check_started(): if self.network.is_connecting(): if self._is_first_run(): @@ -919,6 +917,7 @@ class LBRYumWallet(Wallet): self._start_check = task.LoopingCall(check_started) + d = setup_network() d.addCallback(lambda _: self._load_wallet()) d.addCallback(self._save_wallet) d.addCallback(lambda _: self._start_check.start(.1)) From ed227a239ebe1e0afc5f49e351732979bafd91f5 Mon Sep 17 00:00:00 2001 From: jobevers Date: Sat, 28 Jan 2017 21:47:33 -0800 Subject: [PATCH 4/5] Fixes #449 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What was happening was the wallet claimed to be caught up before it actually was and so the wallet’s local_height was still the value from when lbry was last run, frequently more than 20 or 50 blocks behind. _get_value_for_name uses the block at local_height as the basis for the proof. If _get_value_for_name is called during that time between when the wallet claims to be caught up and it actually is, the “Block too deep error” happens. And since the discover page of the UI does name resolution right away, the error basically happens anytime somebody starts the app after not using it for a few hours. This changes the startup behaviour of the wallet to - use the `update` callback provided by lbryum - check that local_height and network_height match before declaring that the wallet has caught up For reference, the error is raised here: https://github.com/lbryio/lbrycrd/blob/1b896ae75b0fc7081ab9e4a1b7d45c94dcd73cbd/src/rpc/claimtrie.cpp#L688 --- lbrynet/core/Wallet.py | 60 ++++++++------------------------ lbrynet/lbrynet_daemon/Daemon.py | 8 +---- 2 files changed, 16 insertions(+), 52 deletions(-) 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, From 4bb3e2a154ef5805772128b386ec700835f8c904 Mon Sep 17 00:00:00 2001 From: jobevers Date: Wed, 1 Feb 2017 12:13:43 -0800 Subject: [PATCH 5/5] remove is_lagging wallet attribute --- lbrynet/core/Wallet.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 55e1d99f6..d66616cea 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -199,8 +199,6 @@ class Wallet(object): self.max_expected_payment_time = datetime.timedelta(minutes=3) self.stopped = True - self.is_lagging = None - self.manage_running = False self._manage_count = 0 self._balance_refresh_time = 3