1
0

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:
SomberNight
2022-04-08 20:33:13 +02:00
parent 6c05de6fb9
commit 837fc1606c
5 changed files with 13 additions and 13 deletions

View File

@@ -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: