Browse Source

Access to unverified_tx no longer needs a lock

Once the proxy thread jobs are created only they access this,
and they all run under the proxy thread, so there is no contention.
283
Neil Booth 9 years ago
parent
commit
478bde8afa
  1. 8
      lib/wallet.py

8
lib/wallet.py

@ -171,7 +171,8 @@ class Abstract_Wallet(object):
# spv # spv
self.verifier = None self.verifier = None
# Transactions pending verification. Each value is the transaction 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 = {} self.unverified_tx = {}
# Verified transactions. Each value is a (height, timestamp, block_pos) tuple. Access with self.lock. # Verified transactions. Each value is a (height, timestamp, block_pos) tuple. Access with self.lock.
self.verified_tx = storage.get('verified_tx3',{}) self.verified_tx = storage.get('verified_tx3',{})
@ -417,7 +418,6 @@ class Abstract_Wallet(object):
def add_unverified_tx(self, tx_hash, tx_height): def add_unverified_tx(self, tx_hash, tx_height):
if tx_height > 0: if tx_height > 0:
with self.lock:
self.unverified_tx[tx_hash] = tx_height self.unverified_tx[tx_hash] = tx_height
def add_verified_tx(self, tx_hash, info): def add_verified_tx(self, tx_hash, info):
@ -429,9 +429,9 @@ class Abstract_Wallet(object):
self.network.trigger_callback('verified', (tx_hash, conf, timestamp)) self.network.trigger_callback('verified', (tx_hash, conf, timestamp))
def get_unverified_txs(self): def get_unverified_txs(self):
'''Returns a list of tuples (tx_hash, height) that are unverified and not beyond local height''' '''Returns a list of tuples (tx_hash, height) that are unverified
and not beyond local height'''
txs = [] txs = []
with self.lock:
for tx_hash, tx_height in self.unverified_tx.items(): for tx_hash, tx_height in self.unverified_tx.items():
# do not request merkle branch before headers are available # do not request merkle branch before headers are available
if tx_hash not in self.verified_tx and tx_height <= self.get_local_height(): if tx_hash not in self.verified_tx and tx_height <= self.get_local_height():

Loading…
Cancel
Save