From 444dc7fb7f6792450ce2ad89df26cca89d46940e Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 26 Sep 2022 17:02:30 +0200 Subject: [PATCH] wallet: fix race condition that inhibits proper call of set_up_to_date --- electrum/wallet.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/electrum/wallet.py b/electrum/wallet.py index 3dad5f9db..2adece5ae 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -353,6 +353,7 @@ class Abstract_Wallet(ABC, Logger, EventListener): # true when synchronized. this is stricter than adb.is_up_to_date(): # to-be-generated (HD) addresses are also considered here (gap-limit-roll-forward) self._up_to_date = False + self._adb_uptodate_just_changed = False self.test_addresses_sanity() self.register_callbacks() @@ -385,8 +386,10 @@ class Abstract_Wallet(ABC, Logger, EventListener): # have history that are mined and SPV-verified. num_new_addrs = await run_in_thread(self.synchronize) up_to_date = self.adb.is_up_to_date() and num_new_addrs == 0 - if self.is_up_to_date() != up_to_date: - self.set_up_to_date(up_to_date) + if self.is_up_to_date() != up_to_date or self._adb_uptodate_just_changed: + self.set_up_to_date(up_to_date) + if self._adb_uptodate_just_changed: + self._adb_uptodate_just_changed = False def save_db(self): if self.storage: @@ -475,6 +478,12 @@ class Abstract_Wallet(ABC, Logger, EventListener): if status_changed: self.logger.info(f'set_up_to_date: {up_to_date}') + @event_listener + def on_event_adb_set_up_to_date(self, adb): + if self.adb != adb: + return + self._adb_uptodate_just_changed = True + @event_listener def on_event_adb_added_tx(self, adb, tx_hash): if self.adb != adb: