From b3d8b4603f16224db98509d40bb545c3b32a63eb Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sat, 14 May 2022 01:20:22 +0200 Subject: [PATCH] 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...) --- electrum/interface.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/electrum/interface.py b/electrum/interface.py index 850d5d9ea..50949a908 100644 --- a/electrum/interface.py +++ b/electrum/interface.py @@ -736,24 +736,30 @@ class Interface(Logger): if self.tip < constants.net.max_checkpoint(): raise GracefulDisconnect('server tip below max checkpoint') self._mark_ready() - await self._process_header_at_tip() + blockchain_updated = await self._process_header_at_tip() # header processing done - util.trigger_callback('blockchain_updated') + if blockchain_updated: + util.trigger_callback('blockchain_updated') util.trigger_callback('network_updated') await self.network.switch_unwanted_fork_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 async with self.network.bhi_lock: if self.blockchain.height() >= height and self.blockchain.check_header(header): # another interface amended the blockchain self.logger.info(f"skipping header {height}") - return + return False _, height = await self.step(height, header) # in the simple case, height == self.tip+1 if height <= self.tip: await self.sync_until(height) + return True async def sync_until(self, height, next_height=None): if next_height is None: