address_sync: change up_to_date to be private; no lock needed to read
After some consideration I am fairly certain there is no need to take wallet.lock in `is_up_to_date()`. Any caller that might want some kind of guarantees re the value returned by is_up_to_date() would need to enforce them itself by e.g. taking wallet.lock around its critical code block. That is, even if is_up_to_date() itself takes the lock, between the call returning and the caller reading the value there could still have been a race. Also, the GUI was directly accessing the field already.
This commit is contained in:
@@ -88,7 +88,7 @@ class AddressSynchronizer(Logger):
|
||||
# Transactions pending verification. txid -> tx_height. Access with self.lock.
|
||||
self.unverified_tx = defaultdict(int)
|
||||
# true when synchronized
|
||||
self.up_to_date = False
|
||||
self._up_to_date = False
|
||||
# thread local storage for caching stuff
|
||||
self.threadlocal_cache = threading.local()
|
||||
|
||||
@@ -650,15 +650,15 @@ class AddressSynchronizer(Logger):
|
||||
|
||||
def set_up_to_date(self, up_to_date):
|
||||
with self.lock:
|
||||
status_changed = self.up_to_date != up_to_date
|
||||
self.up_to_date = up_to_date
|
||||
status_changed = self._up_to_date != up_to_date
|
||||
self._up_to_date = up_to_date
|
||||
if self.network:
|
||||
self.network.notify('status')
|
||||
if status_changed:
|
||||
self.logger.info(f'set_up_to_date: {up_to_date}')
|
||||
|
||||
def is_up_to_date(self):
|
||||
with self.lock: return self.up_to_date
|
||||
return self._up_to_date
|
||||
|
||||
def get_history_sync_state_details(self) -> Tuple[int, int]:
|
||||
if self.synchronizer:
|
||||
|
||||
@@ -927,7 +927,7 @@ class ElectrumWindow(App, Logger):
|
||||
self.num_blocks = self.network.get_local_height()
|
||||
server_height = self.network.get_server_height()
|
||||
server_lag = self.num_blocks - server_height
|
||||
if not self.wallet.up_to_date or server_height == 0:
|
||||
if not self.wallet.is_up_to_date() or server_height == 0:
|
||||
num_sent, num_answered = self.wallet.get_history_sync_state_details()
|
||||
status = ("{} [size=18dp]({}/{})[/size]"
|
||||
.format(_("Synchronizing..."), num_answered, num_sent))
|
||||
@@ -951,7 +951,7 @@ class ElectrumWindow(App, Logger):
|
||||
def update_wallet_synchronizing_progress(self, *dt):
|
||||
if not self.wallet:
|
||||
return
|
||||
if not self.wallet.up_to_date:
|
||||
if not self.wallet.is_up_to_date():
|
||||
self._trigger_update_status()
|
||||
|
||||
def get_max_amount(self):
|
||||
@@ -1010,7 +1010,7 @@ class ElectrumWindow(App, Logger):
|
||||
#@profiler
|
||||
def update_wallet(self, *dt):
|
||||
self._trigger_update_status()
|
||||
if self.wallet and (self.wallet.up_to_date or not self.network or not self.network.is_connected()):
|
||||
if self.wallet and (self.wallet.is_up_to_date() or not self.network or not self.network.is_connected()):
|
||||
self.update_tabs()
|
||||
|
||||
def notify(self, message):
|
||||
|
||||
@@ -836,7 +836,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||
def notify_transactions(self):
|
||||
if self.tx_notification_queue.qsize() == 0:
|
||||
return
|
||||
if not self.wallet.up_to_date:
|
||||
if not self.wallet.is_up_to_date():
|
||||
return # no notifications while syncing
|
||||
now = time.time()
|
||||
rate_limit = 20 # seconds
|
||||
@@ -883,7 +883,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||
if self.need_update.is_set():
|
||||
self.need_update.clear()
|
||||
self.update_wallet()
|
||||
elif not self.wallet.up_to_date:
|
||||
elif not self.wallet.is_up_to_date():
|
||||
# this updates "synchronizing" progress
|
||||
self.update_status()
|
||||
# resolve aliases
|
||||
@@ -977,7 +977,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||
# Server height can be 0 after switching to a new server
|
||||
# until we get a headers subscription request response.
|
||||
# Display the synchronizing message in that case.
|
||||
if not self.wallet.up_to_date or server_height == 0:
|
||||
if not self.wallet.is_up_to_date() or server_height == 0:
|
||||
num_sent, num_answered = self.wallet.get_history_sync_state_details()
|
||||
network_text = ("{} ({}/{})"
|
||||
.format(_("Synchronizing..."), num_answered, num_sent))
|
||||
@@ -1022,7 +1022,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
||||
|
||||
def update_wallet(self):
|
||||
self.update_status()
|
||||
if self.wallet.up_to_date or not self.network or not self.network.is_connected():
|
||||
if self.wallet.is_up_to_date() or not self.network or not self.network.is_connected():
|
||||
self.update_tabs()
|
||||
|
||||
def update_tabs(self, wallet=None):
|
||||
|
||||
@@ -118,7 +118,7 @@ class ElectrumGui(BaseElectrumGui):
|
||||
|
||||
def get_balance(self):
|
||||
if self.wallet.network.is_connected():
|
||||
if not self.wallet.up_to_date:
|
||||
if not self.wallet.is_up_to_date():
|
||||
msg = _("Synchronizing...")
|
||||
else:
|
||||
c, u, x = self.wallet.get_balance()
|
||||
|
||||
@@ -148,7 +148,7 @@ class ElectrumGui(BaseElectrumGui):
|
||||
if not self.network:
|
||||
msg = _("Offline")
|
||||
elif self.network.is_connected():
|
||||
if not self.wallet.up_to_date:
|
||||
if not self.wallet.is_up_to_date():
|
||||
msg = _("Synchronizing...")
|
||||
else:
|
||||
c, u, x = self.wallet.get_balance()
|
||||
|
||||
Reference in New Issue
Block a user