Skip to content

Commit

Permalink
Merge #1348: Abort sync_unspent if blockheight RPC call fails
Browse files Browse the repository at this point in the history
0b34e0b Abort sync_unspent if blockheight RPC call fails (Adam Gibson)
  • Loading branch information
AdamISZ committed Dec 19, 2022
2 parents 6160418 + 0b34e0b commit b1804c0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions jmclient/jmclient/wallet_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BitcoinCoreNoHistoryInterface)
from jmclient.wallet import FidelityBondMixin, BaseWallet
from jmbase import (stop_reactor, hextobin, utxo_to_utxostr,
jmprint, EXIT_SUCCESS)
jmprint, EXIT_SUCCESS, EXIT_FAILURE)

"""Wallet service
Expand Down Expand Up @@ -805,12 +805,27 @@ def sync_addresses(self):

def sync_unspent(self):
st = time.time()
# block height needs to be real time for addition to our utxos:
current_blockheight = self.bci.get_current_block_height()
# block height needs to be real time for addition to our utxos.
# 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:
# this failure will shut down the application elsewhere, here
# just give up:
return
# this failure is critical; give up:
jlog.error("Failed to access the current blockheight, "
"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()
self.reset_utxos()

Expand Down

0 comments on commit b1804c0

Please sign in to comment.