electrum

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

commit 2ad73050b383adca1dba50afe7cbdb8377a6cbd3
parent 8b2c586d3077c98b29cbdf462876336a706aa943
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri,  1 Mar 2019 16:57:19 +0100

wallet: towards restoring previous performance

Diffstat:
Melectrum/address_synchronizer.py | 21++++++++++-----------
Melectrum/json_db.py | 7+++++--
Melectrum/storage.py | 1-
Melectrum/synchronizer.py | 2+-
Melectrum/wallet.py | 4++--
5 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -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 @@ -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) @@ -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) @@ -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) diff --git a/electrum/json_db.py b/electrum/json_db.py @@ -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 @@ -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 @@ -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) diff --git a/electrum/storage.py b/electrum/storage.py @@ -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 diff --git a/electrum/synchronizer.py b/electrum/synchronizer.py @@ -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 diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -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 @@ -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