1
0

rework AddressSynchronizer.is_up_to_date

- AddressSynchronizer no longer has its own state re up_to_date,
  it defers to Synchronizer/Verifier instead
- Synchronizer is now tracking address sync states throughout their lifecycle:
  and Synchronizer.is_up_to_date() checks all states
- Synchronizer.add_queue (internal) is removed as it was redundant
- should fix wallet.is_up_to_date flickering during sync due to race

related:
dc6c481406
1c20a29a22
This commit is contained in:
SomberNight
2022-12-21 15:23:11 +00:00
parent 77981956d6
commit 29a0560f98
2 changed files with 60 additions and 55 deletions

View File

@@ -84,8 +84,6 @@ class AddressSynchronizer(Logger, EventListener):
self.unverified_tx = defaultdict(int) # type: Dict[str, int] # txid -> height. Access with self.lock.
# Txs the server claims are in the mempool:
self.unconfirmed_tx = defaultdict(int) # type: Dict[str, int] # txid -> height. Access with self.lock.
# true when synchronized
self._up_to_date = False # considers both Synchronizer and Verifier
# thread local storage for caching stuff
self.threadlocal_cache = threading.local()
@@ -210,9 +208,9 @@ class AddressSynchronizer(Logger, EventListener):
def add_address(self, address):
if address not in self.db.history:
self.db.history[address] = []
self.set_up_to_date(False)
if self.synchronizer:
self.synchronizer.add(address)
self.up_to_date_changed()
def get_conflicting_transactions(self, tx_hash, tx: Transaction, include_self=False):
"""Returns a set of transaction hashes from the wallet history that are
@@ -677,17 +675,14 @@ class AddressSynchronizer(Logger, EventListener):
# local transaction
return TxMinedInfo(height=TX_HEIGHT_LOCAL, conf=0)
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
def up_to_date_changed(self) -> None:
# fire triggers
util.trigger_callback('adb_set_up_to_date', self)
if status_changed:
self.logger.info(f'set_up_to_date: {up_to_date}')
def is_up_to_date(self):
return self._up_to_date
if not self.synchronizer or not self.verifier:
return False
return self.synchronizer.is_up_to_date() and self.verifier.is_up_to_date()
def reset_netrequest_counters(self) -> None:
if self.synchronizer: