Browse Source

interface: trigger fewer 'blockchain_updated' notifications

The Qt GUI refreshes all tabs on 'blockchain_updated', which is expensive for very large wallets.
Previously, on every new block, the GUI would get one notification for each connected interface,
now only the fastest interface triggers it.

(was testing with a wallet where refreshing all tabs takes 15 seconds, and 10*15 seconds is
even more annoying...)
master
SomberNight 4 years ago
parent
commit
b3d8b4603f
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 12
      electrum/interface.py

12
electrum/interface.py

@ -736,24 +736,30 @@ class Interface(Logger):
if self.tip < constants.net.max_checkpoint(): if self.tip < constants.net.max_checkpoint():
raise GracefulDisconnect('server tip below max checkpoint') raise GracefulDisconnect('server tip below max checkpoint')
self._mark_ready() self._mark_ready()
await self._process_header_at_tip() blockchain_updated = await self._process_header_at_tip()
# header processing done # header processing done
if blockchain_updated:
util.trigger_callback('blockchain_updated') util.trigger_callback('blockchain_updated')
util.trigger_callback('network_updated') util.trigger_callback('network_updated')
await self.network.switch_unwanted_fork_interface() await self.network.switch_unwanted_fork_interface()
await self.network.switch_lagging_interface() await self.network.switch_lagging_interface()
async def _process_header_at_tip(self): async def _process_header_at_tip(self) -> bool:
"""Returns:
False - boring fast-forward: we already have this header as part of this blockchain from another interface,
True - new header we didn't have, or reorg
"""
height, header = self.tip, self.tip_header height, header = self.tip, self.tip_header
async with self.network.bhi_lock: async with self.network.bhi_lock:
if self.blockchain.height() >= height and self.blockchain.check_header(header): if self.blockchain.height() >= height and self.blockchain.check_header(header):
# another interface amended the blockchain # another interface amended the blockchain
self.logger.info(f"skipping header {height}") self.logger.info(f"skipping header {height}")
return return False
_, height = await self.step(height, header) _, height = await self.step(height, header)
# in the simple case, height == self.tip+1 # in the simple case, height == self.tip+1
if height <= self.tip: if height <= self.tip:
await self.sync_until(height) await self.sync_until(height)
return True
async def sync_until(self, height, next_height=None): async def sync_until(self, height, next_height=None):
if next_height is None: if next_height is None:

Loading…
Cancel
Save