twallet: towards restoring previous performance - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 2ad73050b383adca1dba50afe7cbdb8377a6cbd3 DIR parent 8b2c586d3077c98b29cbdf462876336a706aa943 HTML Author: SomberNight <somber.night@protonmail.com> Date: Fri, 1 Mar 2019 16:57:19 +0100 wallet: towards restoring previous performance Diffstat: M electrum/address_synchronizer.py | 21 ++++++++++----------- M electrum/json_db.py | 7 +++++-- M electrum/storage.py | 1 - M electrum/synchronizer.py | 2 +- M electrum/wallet.py | 4 ++-- 5 files changed, 18 insertions(+), 17 deletions(-) --- DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py t@@ -183,7 +183,7 @@ class AddressSynchronizer(PrintError): if spending_tx_hash is None: continue # this outpoint has already been spent, by spending_tx - assert spending_tx_hash in self.db.list_transactions() + assert self.db.get_transaction(spending_tx_hash) conflicting_txns |= {spending_tx_hash} if tx_hash in conflicting_txns: # this tx is already in history, so it conflicts with itself t@@ -374,22 +374,21 @@ class AddressSynchronizer(PrintError): def remove_local_transactions_we_dont_have(self): for txid in itertools.chain(self.db.list_txi(), self.db.list_txo()): tx_height = self.get_tx_height(txid).height - if tx_height == TX_HEIGHT_LOCAL and txid not in self.db.list_transactions(): + if tx_height == TX_HEIGHT_LOCAL and not self.db.get_transaction(txid): self.remove_transaction(txid) def clear_history(self): with self.lock: with self.transaction_lock: self.db.clear_history() - self.storage.modified = True # FIXME hack.. self.storage.write() def get_txpos(self, tx_hash): """Returns (height, txpos) tuple, even if the tx is unverified.""" with self.lock: - if tx_hash in self.db.list_verified_tx(): - info = self.db.get_verified_tx(tx_hash) - return info.height, info.txpos + verified_tx_mined_info = self.db.get_verified_tx(tx_hash) + if verified_tx_mined_info: + return verified_tx_mined_info.height, verified_tx_mined_info.txpos elif tx_hash in self.unverified_tx: height = self.unverified_tx[tx_hash] return (height, 0) if height > 0 else ((1e9 - height), 0) t@@ -485,7 +484,7 @@ class AddressSynchronizer(PrintError): await self._address_history_changed_events[addr].wait() def add_unverified_tx(self, tx_hash, tx_height): - if tx_hash in self.db.list_verified_tx(): + if self.db.is_in_verified_tx(tx_hash): if tx_height in (TX_HEIGHT_UNCONFIRMED, TX_HEIGHT_UNCONF_PARENT): with self.lock: self.db.remove_verified_tx(tx_hash) t@@ -548,10 +547,10 @@ class AddressSynchronizer(PrintError): def get_tx_height(self, tx_hash: str) -> TxMinedInfo: with self.lock: - if tx_hash in self.db.list_verified_tx(): - info = self.db.get_verified_tx(tx_hash) - conf = max(self.get_local_height() - info.height + 1, 0) - return info._replace(conf=conf) + verified_tx_mined_info = self.db.get_verified_tx(tx_hash) + if verified_tx_mined_info: + conf = max(self.get_local_height() - verified_tx_mined_info.height + 1, 0) + return verified_tx_mined_info._replace(conf=conf) elif tx_hash in self.unverified_tx: height = self.unverified_tx[tx_hash] return TxMinedInfo(height=height, conf=0) DIR diff --git a/electrum/json_db.py b/electrum/json_db.py t@@ -28,7 +28,7 @@ import json import copy import threading from collections import defaultdict -from typing import Dict +from typing import Dict, Optional from . import util, bitcoin from .util import PrintError, profiler, WalletFileException, multisig_type, TxMinedInfo t@@ -585,7 +585,7 @@ class JsonDB(PrintError): return Transaction(tx) if tx else None @locked - def get_transaction(self, tx_hash): + def get_transaction(self, tx_hash) -> Optional[Transaction]: tx = self.transactions.get(tx_hash) return Transaction(tx) if tx else None t@@ -632,6 +632,9 @@ class JsonDB(PrintError): def remove_verified_tx(self, txid): self.verified_tx.pop(txid, None) + def is_in_verified_tx(self, txid): + return txid in self.verified_tx + @modifier def update_tx_fees(self, d): return self.tx_fees.update(d) DIR diff --git a/electrum/storage.py b/electrum/storage.py t@@ -234,7 +234,6 @@ class WalletStorage(PrintError): storage = WalletStorage(path) storage.db.data = data storage.db.upgrade() - storage.modified = True storage.write() out.append(path) return out DIR diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py t@@ -175,7 +175,7 @@ class Synchronizer(SynchronizerBase): for tx_hash, tx_height in hist: if tx_hash in self.requested_tx: continue - if tx_hash in self.wallet.db.list_transactions(): + if self.wallet.db.get_transaction(tx_hash): continue transaction_hashes.append(tx_hash) self.requested_tx[tx_hash] = tx_height DIR diff --git a/electrum/wallet.py b/electrum/wallet.py t@@ -278,7 +278,7 @@ class Abstract_Wallet(AddressSynchronizer): return changed def set_fiat_value(self, txid, ccy, text, fx, value_sat): - if txid not in self.db.list_transactions(): + if not self.db.get_transaction(txid): return # since fx is inserting the thousands separator, # and not util, also have fx remove it t@@ -360,7 +360,7 @@ class Abstract_Wallet(AddressSynchronizer): height = conf = timestamp = None tx_hash = tx.txid() if tx.is_complete(): - if tx_hash in self.db.list_transactions(): + if self.db.get_transaction(tx_hash): label = self.get_label(tx_hash) tx_mined_status = self.get_tx_height(tx_hash) height, conf = tx_mined_status.height, tx_mined_status.conf