wallet.py: access unverified_tx with self.lock

Only actually needed due to Imported_Wallet.delete_address, but it takes some time to see this.
The verifier and the synchronizer both access unverified_tx but they are both run in the Network thread.
In any case, there does not seem to be a measurable performance hit when using the lock.
This commit is contained in:
SomberNight 2018-05-30 19:01:47 +02:00
parent 060404e17c
commit 1e06b1921e
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -205,11 +205,9 @@ class Abstract_Wallet(PrintError):
self.fiat_value = storage.get('fiat_value', {}) self.fiat_value = storage.get('fiat_value', {})
self.receive_requests = storage.get('payment_requests', {}) self.receive_requests = storage.get('payment_requests', {})
# Verified transactions. Each value is a (height, timestamp, block_pos) tuple. Access with self.lock. # Verified transactions. txid -> (height, timestamp, block_pos). Access with self.lock.
self.verified_tx = storage.get('verified_tx3', {}) self.verified_tx = storage.get('verified_tx3', {})
# Transactions pending verification. txid -> tx_height. Access with self.lock.
# Transactions pending verification. A map from tx hash to transaction
# height. Access is not contended so no lock is needed.
self.unverified_tx = defaultdict(int) self.unverified_tx = defaultdict(int)
self.load_keystore() self.load_keystore()
@ -460,19 +458,21 @@ class Abstract_Wallet(PrintError):
# tx will be verified only if height > 0 # tx will be verified only if height > 0
if tx_hash not in self.verified_tx: if tx_hash not in self.verified_tx:
self.unverified_tx[tx_hash] = tx_height with self.lock:
self.unverified_tx[tx_hash] = tx_height
def add_verified_tx(self, tx_hash, info): def add_verified_tx(self, tx_hash, info):
# Remove from the unverified map and add to the verified map and # Remove from the unverified map and add to the verified map
self.unverified_tx.pop(tx_hash, None)
with self.lock: with self.lock:
self.unverified_tx.pop(tx_hash, None)
self.verified_tx[tx_hash] = info # (tx_height, timestamp, pos) self.verified_tx[tx_hash] = info # (tx_height, timestamp, pos)
height, conf, timestamp = self.get_tx_height(tx_hash) height, conf, timestamp = self.get_tx_height(tx_hash)
self.network.trigger_callback('verified', tx_hash, height, conf, timestamp) self.network.trigger_callback('verified', tx_hash, height, conf, timestamp)
def get_unverified_txs(self): def get_unverified_txs(self):
'''Returns a map from tx hash to transaction height''' '''Returns a map from tx hash to transaction height'''
return self.unverified_tx with self.lock:
return dict(self.unverified_tx) # copy
def undo_verifications(self, blockchain, height): def undo_verifications(self, blockchain, height):
'''Used by the verifier when a reorg has happened''' '''Used by the verifier when a reorg has happened'''