diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 72904bdfc..702ce6612 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -32,7 +32,7 @@ from aiorpcx import TaskGroup from . import bitcoin, util from .bitcoin import COINBASE_MATURITY -from .util import profiler, bfh, TxMinedInfo, UnrelatedTransactionException +from .util import profiler, bfh, TxMinedInfo, UnrelatedTransactionException, with_lock from .transaction import Transaction, TxOutput, TxInput, PartialTxInput, TxOutpoint, PartialTransaction from .synchronizer import Synchronizer from .verifier import SPV @@ -98,12 +98,6 @@ class AddressSynchronizer(Logger): self.load_and_cleanup() - def with_lock(func): - def func_wrapper(self: 'AddressSynchronizer', *args, **kwargs): - with self.lock: - return func(self, *args, **kwargs) - return func_wrapper - def with_transaction_lock(func): def func_wrapper(self: 'AddressSynchronizer', *args, **kwargs): with self.transaction_lock: diff --git a/electrum/blockchain.py b/electrum/blockchain.py index 4571d0c1a..f911d4b1e 100644 --- a/electrum/blockchain.py +++ b/electrum/blockchain.py @@ -29,7 +29,7 @@ from . import util from .bitcoin import hash_encode, int_to_hex, rev_hex from .crypto import sha256d from . import constants -from .util import bfh, bh2u +from .util import bfh, bh2u, with_lock from .simple_config import SimpleConfig from .logging import get_logger, Logger @@ -195,12 +195,6 @@ class Blockchain(Logger): self.lock = threading.RLock() self.update_size() - def with_lock(func): - def func_wrapper(self, *args, **kwargs): - with self.lock: - return func(self, *args, **kwargs) - return func_wrapper - @property def checkpoints(self): return constants.net.CHECKPOINTS diff --git a/electrum/lnhtlc.py b/electrum/lnhtlc.py index 45b1cf739..40416bbea 100644 --- a/electrum/lnhtlc.py +++ b/electrum/lnhtlc.py @@ -3,7 +3,7 @@ from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, Set import threading from .lnutil import SENT, RECEIVED, LOCAL, REMOTE, HTLCOwner, UpdateAddHtlc, Direction, FeeUpdate -from .util import bh2u, bfh +from .util import bh2u, bfh, with_lock if TYPE_CHECKING: from .json_db import StoredDict @@ -50,12 +50,6 @@ class HTLCManager: self._init_maybe_active_htlc_ids() - def with_lock(func): - def func_wrapper(self, *args, **kwargs): - with self.lock: - return func(self, *args, **kwargs) - return func_wrapper - @with_lock def ctn_latest(self, sub: HTLCOwner) -> int: """Return the ctn for the latest (newest that has a valid sig) ctx of sub""" diff --git a/electrum/util.py b/electrum/util.py index 59fd43393..8fb9ca0d6 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -776,7 +776,7 @@ mainnet_block_explorers = { 'mempool.space': ('https://mempool.space/', {'tx': 'tx/', 'addr': 'address/'}), 'mempool.emzy.de': ('https://mempool.emzy.de/', - {'tx': 'tx/', 'addr': 'address/'}), + {'tx': 'tx/', 'addr': 'address/'}), 'OXT.me': ('https://oxt.me/', {'tx': 'transaction/', 'addr': 'address/'}), 'smartbit.com.au': ('https://www.smartbit.com.au/', @@ -797,7 +797,7 @@ testnet_block_explorers = { 'Blockstream.info': ('https://blockstream.info/testnet/', {'tx': 'tx/', 'addr': 'address/'}), 'mempool.space': ('https://mempool.space/testnet/', - {'tx': 'tx/', 'addr': 'address/'}), + {'tx': 'tx/', 'addr': 'address/'}), 'smartbit.com.au': ('https://testnet.smartbit.com.au/', {'tx': 'tx/', 'addr': 'address/'}), 'system default': ('blockchain://000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943/', @@ -1116,6 +1116,14 @@ def ignore_exceptions(func): return wrapper +def with_lock(func): + """Decorator to enforce a lock on a function call.""" + def func_wrapper(self, *args, **kwargs): + with self.lock: + return func(self, *args, **kwargs) + return func_wrapper + + class TxMinedInfo(NamedTuple): height: int # height of block that mined tx conf: Optional[int] = None # number of confirmations, SPV verified (None means unknown)