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.
This commit is contained in:
@@ -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,8 +418,7 @@ 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):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
@@ -429,13 +429,13 @@ 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():
|
txs.append((tx_hash, tx_height))
|
||||||
txs.append((tx_hash, tx_height))
|
|
||||||
return txs
|
return txs
|
||||||
|
|
||||||
def undo_verifications(self, height):
|
def undo_verifications(self, height):
|
||||||
@@ -473,7 +473,7 @@ class Abstract_Wallet(object):
|
|||||||
"return position, even if the tx is unverified"
|
"return position, even if the tx is unverified"
|
||||||
with self.lock:
|
with self.lock:
|
||||||
x = self.verified_tx.get(tx_hash)
|
x = self.verified_tx.get(tx_hash)
|
||||||
y = self.unverified_tx.get(tx_hash)
|
y = self.unverified_tx.get(tx_hash)
|
||||||
if x:
|
if x:
|
||||||
height, timestamp, pos = x
|
height, timestamp, pos = x
|
||||||
return height, pos
|
return height, pos
|
||||||
|
|||||||
Reference in New Issue
Block a user