electrum

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

commit 8ac6d3b17d221aed7bc3e3dd6a9f1e54425890ae
parent 777095fda8c7c5f27d119778fefc28de294e538d
Author: SomberNight <somber.night@protonmail.com>
Date:   Sun, 18 Oct 2020 22:21:06 +0200

wallet.get_history: take locks.

Re the check at the end: "history not synchronized" - it's not that it's not synchronized,
rather that the history is changing while being computed.

Diffstat:
Melectrum/address_synchronizer.py | 15+++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py @@ -96,8 +96,14 @@ 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, *args, **kwargs): + def func_wrapper(self: 'AddressSynchronizer', *args, **kwargs): with self.transaction_lock: return func(self, *args, **kwargs) return func_wrapper @@ -468,6 +474,8 @@ class AddressSynchronizer(Logger): self.threadlocal_cache.local_height = orig_val return f + @with_lock + @with_transaction_lock @with_local_height_cached def get_history(self, *, domain=None) -> Sequence[HistoryItem]: # get domain @@ -501,10 +509,9 @@ class AddressSynchronizer(Logger): balance=balance)) balance -= delta h2.reverse() - # fixme: this may happen if history is incomplete + if balance != 0: - self.logger.warning("history not synchronized") - return [] + raise Exception("wallet.get_history() failed balance sanity-check") return h2