twallet.get_history: take locks. - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 8ac6d3b17d221aed7bc3e3dd6a9f1e54425890ae DIR parent 777095fda8c7c5f27d119778fefc28de294e538d HTML 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: M electrum/address_synchronizer.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) --- DIR diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py t@@ -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 t@@ -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 t@@ -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