Browse Source

Merge #1348: Abort sync_unspent if blockheight RPC call fails

0b34e0b Abort sync_unspent if blockheight RPC call fails (Adam Gibson)
master
Adam Gibson 3 years ago
parent
commit
b1804c0442
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 27
      jmclient/jmclient/wallet_service.py

27
jmclient/jmclient/wallet_service.py

@ -17,7 +17,7 @@ from jmclient.blockchaininterface import (INF_HEIGHT, BitcoinCoreInterface,
BitcoinCoreNoHistoryInterface) BitcoinCoreNoHistoryInterface)
from jmclient.wallet import FidelityBondMixin, BaseWallet from jmclient.wallet import FidelityBondMixin, BaseWallet
from jmbase import (stop_reactor, hextobin, utxo_to_utxostr, from jmbase import (stop_reactor, hextobin, utxo_to_utxostr,
jmprint, EXIT_SUCCESS) jmprint, EXIT_SUCCESS, EXIT_FAILURE)
"""Wallet service """Wallet service
@ -805,12 +805,27 @@ class WalletService(Service):
def sync_unspent(self): def sync_unspent(self):
st = time.time() st = time.time()
# block height needs to be real time for addition to our utxos: # block height needs to be real time for addition to our utxos.
current_blockheight = self.bci.get_current_block_height() # We are a little aggressive in trying this RPC call, because if
# it fails we cannot continue:
for i in range(5):
current_blockheight = self.bci.get_current_block_height()
if current_blockheight:
break
if i < 4:
jlog.debug("Error calling blockheight RPC, trying again in 0.5s.")
# sync unspent calls are synchronous; this short sleep should
# not affect us since we are not yet in main monitor loop.
time.sleep(0.5)
if not current_blockheight: if not current_blockheight:
# this failure will shut down the application elsewhere, here # this failure is critical; give up:
# just give up: jlog.error("Failed to access the current blockheight, "
return "and therefore could not sync the wallet. "
"Shutting down.")
if self.isRunning:
self.stopService()
stop_reactor()
sys.exit(EXIT_FAILURE)
wallet_name = self.get_wallet_name() wallet_name = self.get_wallet_name()
self.reset_utxos() self.reset_utxos()

Loading…
Cancel
Save