diff --git a/jmclient/jmclient/wallet_service.py b/jmclient/jmclient/wallet_service.py index ae19f9b..01b1e2c 100644 --- a/jmclient/jmclient/wallet_service.py +++ b/jmclient/jmclient/wallet_service.py @@ -79,6 +79,12 @@ class WalletService(Service): False, otherwise return True (means self.current_blockheight has been correctly updated). """ + + def critical_error(): + jlog.error("Failure to get blockheight from Bitcoin Core.") + self.stopService() + return False + if self.current_blockheight: old_blockheight = self.current_blockheight else: @@ -88,13 +94,9 @@ class WalletService(Service): except Exception as e: # This should never happen now, as we are catching every # possible Exception in jsonrpc or bci.rpc: - jlog.error("Failure to get blockheight from Bitcoin Core:") - jlog.error(repr(e)) - if reactor.running: - reactor.stop() - return False + return critical_error() if not self.current_blockheight: - return False + return critical_error() # We have received a new blockheight from Core, sanity check it: assert isinstance(self.current_blockheight, Integral) @@ -191,7 +193,9 @@ class WalletService(Service): """ if not syncresult: jlog.error("Failed to sync the bitcoin wallet. Shutting down.") - reactor.stop() + self.stopService() + if reactor.running: + reactor.stop() return jlog.info("Starting transaction monitor in walletservice") self.monitor_loop = task.LoopingCall( diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index 8513bd1..8cebd2d 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -1403,7 +1403,8 @@ class JMMainWindow(QMainWindow): event.accept() if self.reactor.threadpool is not None: self.reactor.threadpool.stop() - self.reactor.stop() + if reactor.running: + self.reactor.stop() else: event.ignore() @@ -1765,10 +1766,25 @@ class JMMainWindow(QMainWindow): t = self.centralWidget().widget(0) if not self.wallet_service: #failure to sync in constructor means object is not created newsyncmsg = "Unable to sync wallet - see error in console." + elif not self.wallet_service.isRunning(): + JMQtMessageBox(self, + "The Joinmarket wallet service has stopped; this is usually caused " + "by a Bitcoin Core RPC connection failure. Is your node running?", + mbtype='crit', + title="Error") + qApp.exit(EXIT_FAILURE) + return elif not self.wallet_service.synced: return else: - t.updateWalletInfo(get_wallet_printout(self.wallet_service)) + try: + t.updateWalletInfo(get_wallet_printout(self.wallet_service)) + except Exception: + # this is very likely to happen in case Core RPC connection goes + # down (but, order of events means it is not deterministic). + log.debug("Failed to get wallet information, is there a problem with " + "the blockchain interface?") + return newsyncmsg = "Wallet synced successfully." if newsyncmsg != self.syncmsg: self.syncmsg = newsyncmsg