Browse Source

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.
3.2.x
SomberNight 7 years ago
parent
commit
1e06b1921e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 16
      lib/wallet.py

16
lib/wallet.py

@ -205,11 +205,9 @@ class Abstract_Wallet(PrintError):
self.fiat_value = storage.get('fiat_value', {})
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', {})
# Transactions pending verification. A map from tx hash to transaction
# height. Access is not contended so no lock is needed.
# Transactions pending verification. txid -> tx_height. Access with self.lock.
self.unverified_tx = defaultdict(int)
self.load_keystore()
@ -460,19 +458,21 @@ class Abstract_Wallet(PrintError):
# tx will be verified only if height > 0
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):
# Remove from the unverified map and add to the verified map and
self.unverified_tx.pop(tx_hash, None)
# Remove from the unverified map and add to the verified map
with self.lock:
self.unverified_tx.pop(tx_hash, None)
self.verified_tx[tx_hash] = info # (tx_height, timestamp, pos)
height, conf, timestamp = self.get_tx_height(tx_hash)
self.network.trigger_callback('verified', tx_hash, height, conf, timestamp)
def get_unverified_txs(self):
'''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):
'''Used by the verifier when a reorg has happened'''

Loading…
Cancel
Save