electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 1e06b1921e324ba41803f6e970a629be30037340
parent 060404e17c806e363a6f512e2f544f5c12821dd3
Author: SomberNight <somber.night@protonmail.com>
Date:   Wed, 30 May 2018 19:01:47 +0200

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.

Diffstat:
Mlib/wallet.py | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/wallet.py b/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'''