Browse Source

Initialization of BCI raises Exception not sys.exit

Reasoning for this change: to ensure that Qt will show
a message and gracefully exit (or quit attempting to
load a wallet) in all 3 cases: on startup it show an
intelligible message if the RPC connection fails (as
before this PR), if the RPC fails while no wallet is
loaded and thus no wallet service is started, it should
show an intelligible error message when you attempt to
load a wallet and it fails, and finally it should show
an intelligible error message before quitting, if the rpc
connection fails during the period when the wallet is
already loaded.
By switching to an Exception instead of sys.exit, it does
mean that starting a yieldgenerator shows a stack trace,
but it also shows an intelligible error message (in red),
and this is command line, so UI requirements are less strong.
We preserve the "good" behaviour of no stack trace, but
only error message, if the rpc connection is lost during
running.
master
Adam Gibson 6 years ago
parent
commit
52b9ba8573
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 6
      jmclient/jmclient/blockchaininterface.py
  2. 20
      jmclient/jmclient/wallet_service.py
  3. 1
      scripts/joinmarket-qt.py

6
jmclient/jmclient/blockchaininterface.py

@ -168,8 +168,10 @@ class BitcoinCoreInterface(BlockchainInterface):
if not blockchainInfo:
# see note in BitcoinCoreInterface.rpc - here
# we have to create this object before reactor start,
# so sys.exit *is* the right call:
sys.exit(EXIT_FAILURE)
# so reactor is not stopped, so we override the 'swallowing'
# of the Exception that happened in self.rpc():
raise JsonRpcConnectionError("RPC connection to Bitcoin Core "
"was not established successfully.")
actualNet = blockchainInfo['chain']
netmap = {'main': 'mainnet', 'test': 'testnet', 'regtest': 'regtest'}

20
jmclient/jmclient/wallet_service.py

@ -41,16 +41,27 @@ class WalletService(Service):
# the JM wallet object.
self.bci = jm_single().bc_interface
# main loop used to check for transactions, instantiated
# after wallet is synced:
self.monitor_loop = None
self.wallet = wallet
self.synced = False
# keep track of the quasi-real-time blockheight
# (updated in main monitor loop)
self.current_blockheight = None
if self.bci is not None:
self.update_blockheight()
if not self.update_blockheight():
# this accounts for the unusual case
# where the application started up with
# a functioning blockchain interface, but
# that bci is now failing when we are starting
# the wallet service.
raise Exception("WalletService failed to start "
"due to inability to query block height.")
else:
jlog.warning("No blockchain source available, " +
"wallet tools will not show correct balances.")
self.wallet = wallet
self.synced = False
# Dicts of registered callbacks, by type
# and then by txinfo, for events
@ -119,7 +130,8 @@ class WalletService(Service):
should *not* be restarted, instead a new
WalletService instance should be created.
"""
self.monitor_loop.stop()
if self.monitor_loop:
self.monitor_loop.stop()
self.wallet.close()
super(WalletService, self).stopService()

1
scripts/joinmarket-qt.py

@ -1753,7 +1753,6 @@ class JMMainWindow(QMainWindow):
# add information callbacks:
self.wallet_service.add_restart_callback(self.restartWithMsg)
self.wallet_service.autofreeze_warning_cb = self.autofreeze_warning_cb
self.wallet_service.startService()
self.syncmsg = ""
self.walletRefresh = task.LoopingCall(self.updateWalletInfo)

Loading…
Cancel
Save