Check for shutdown in block scanning loop.

master^2
tecnovert 6 months ago
parent 40eff0ce0f
commit 00912b277a
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
  1. 11
      basicswap/basicswap.py
  2. 2
      basicswap/interface/dcr/dcr.py

@ -3589,6 +3589,7 @@ class BasicSwap(BaseApp):
# Bid saved in checkBidState # Bid saved in checkBidState
def setLastHeightCheckedStart(self, coin_type, tx_height: int, session=None) -> int: def setLastHeightCheckedStart(self, coin_type, tx_height: int, session=None) -> int:
self.log.debug('setLastHeightCheckedStart {} {}'.format(Coins(coin_type).name, tx_height))
ci = self.ci(coin_type) ci = self.ci(coin_type)
coin_name = ci.coin_name() coin_name = ci.coin_name()
if tx_height < 1: if tx_height < 1:
@ -3924,6 +3925,7 @@ class BasicSwap(BaseApp):
chain_a_block_header = ci_from.getBlockHeaderFromHeight(bid.xmr_a_lock_tx.chain_height) chain_a_block_header = ci_from.getBlockHeaderFromHeight(bid.xmr_a_lock_tx.chain_height)
block_time = chain_a_block_header['time'] block_time = chain_a_block_header['time']
chain_b_block_header = ci_to.getBlockHeaderAt(block_time) chain_b_block_header = ci_to.getBlockHeaderAt(block_time)
self.log.debug('chain a block_time {}, chain b block height {}'.format(block_time, chain_b_block_header['height']))
dest_script = ci_to.getPkDest(xmr_swap.pkbs) dest_script = ci_to.getPkDest(xmr_swap.pkbs)
self.addWatchedScript(ci_to.coin_type(), bid.bid_id, dest_script, TxTypes.XMR_SWAP_B_LOCK) self.addWatchedScript(ci_to.coin_type(), bid.bid_id, dest_script, TxTypes.XMR_SWAP_B_LOCK)
self.setLastHeightCheckedStart(ci_to.coin_type(), chain_b_block_header['height'], session) self.setLastHeightCheckedStart(ci_to.coin_type(), chain_b_block_header['height'], session)
@ -4521,9 +4523,16 @@ class BasicSwap(BaseApp):
chain_blocks = ci.getChainHeight() chain_blocks = ci.getChainHeight()
last_height_checked: int = c['last_height_checked'] last_height_checked: int = c['last_height_checked']
block_check_min_time: int = c['block_check_min_time'] block_check_min_time: int = c['block_check_min_time']
self.log.debug('chain_blocks, last_height_checked %d %d', chain_blocks, last_height_checked) self.log.debug('{} chain_blocks, last_height_checked {} {}'.format(ci.ticker(), chain_blocks, last_height_checked))
blocks_checked: int = 0
while last_height_checked < chain_blocks: while last_height_checked < chain_blocks:
if self.delay_event.is_set():
break
blocks_checked += 1
if blocks_checked % 10000 == 0:
self.log.debug('{} chain_blocks, last_height_checked, blocks_checked {} {} {}'.format(ci.ticker(), chain_blocks, last_height_checked, blocks_checked))
block_hash = ci.rpc('getblockhash', [last_height_checked + 1]) block_hash = ci.rpc('getblockhash', [last_height_checked + 1])
try: try:
block = ci.getBlockWithTxns(block_hash) block = ci.getBlockWithTxns(block_hash)

@ -849,7 +849,7 @@ class DCRInterface(Secp256k1Interface):
blockchaininfo = self.rpc('getblockchaininfo') blockchaininfo = self.rpc('getblockchaininfo')
last_block_header = self.rpc('getblockheader', [blockchaininfo['bestblockhash']]) last_block_header = self.rpc('getblockheader', [blockchaininfo['bestblockhash']])
max_tries = 5000 max_tries = 15000
for i in range(max_tries): for i in range(max_tries):
prev_block_header = self.rpc('getblockheader', [last_block_header['previousblockhash']]) prev_block_header = self.rpc('getblockheader', [last_block_header['previousblockhash']])
if prev_block_header['time'] <= time: if prev_block_header['time'] <= time:

Loading…
Cancel
Save