1
0

wallet/verifier: persist wallet.verified_tx when verifier finishes

Previously verified_tx was only persisted in wallet.stop_threads(), hence only on clean shutdowns.
This commit is contained in:
SomberNight
2018-05-30 18:21:29 +02:00
parent 4159322db0
commit 060404e17c
2 changed files with 39 additions and 12 deletions

View File

@@ -222,9 +222,10 @@ class Abstract_Wallet(PrintError):
self.load_unverified_transactions()
self.remove_local_transactions_we_dont_have()
# there is a difference between wallet.up_to_date and interface.is_up_to_date()
# interface.is_up_to_date() returns true when all requests have been answered and processed
# There is a difference between wallet.up_to_date and network.is_up_to_date().
# network.is_up_to_date() returns true when all requests have been answered and processed
# wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
# Neither of them considers the verifier.
self.up_to_date = False
# save wallet type the first time
@@ -291,6 +292,12 @@ class Abstract_Wallet(PrintError):
if write:
self.storage.write()
def save_verified_tx(self, write=False):
with self.lock:
self.storage.put('verified_tx3', self.verified_tx)
if write:
self.storage.write()
def clear_history(self):
with self.lock:
with self.transaction_lock:
@@ -365,6 +372,10 @@ class Abstract_Wallet(PrintError):
self.up_to_date = up_to_date
if up_to_date:
self.save_transactions(write=True)
# if the verifier is also up to date, persist that too;
# otherwise it will persist its results when it finishes
if self.verifier and self.verifier.is_up_to_date():
self.save_verified_tx(write=True)
def is_up_to_date(self):
with self.lock: return self.up_to_date
@@ -445,7 +456,7 @@ class Abstract_Wallet(PrintError):
with self.lock:
self.verified_tx.pop(tx_hash)
if self.verifier:
self.verifier.merkle_roots.pop(tx_hash, None)
self.verifier.remove_spv_proof_for_tx(tx_hash)
# tx will be verified only if height > 0
if tx_hash not in self.verified_tx:
@@ -965,7 +976,7 @@ class Abstract_Wallet(PrintError):
self.unverified_tx.pop(tx_hash, None)
self.verified_tx.pop(tx_hash, None)
if self.verifier:
self.verifier.merkle_roots.pop(tx_hash, None)
self.verifier.remove_spv_proof_for_tx(tx_hash)
# but remove completely if not is_mine
if self.txi[tx_hash] == {}:
# FIXME the test here should be for "not all is_mine"; cannot detect conflict in some cases
@@ -1322,8 +1333,7 @@ class Abstract_Wallet(PrintError):
# remain so they will be GC-ed
self.storage.put('stored_height', self.get_local_height())
self.save_transactions()
with self.lock:
self.storage.put('verified_tx3', self.verified_tx)
self.save_verified_tx()
self.storage.write()
def wait_until_synchronized(self, callback=None):