commit 25c372a3e0c7d03ded5bb537e48cbe9337168014
parent 509df9ddaf411a3fe2f6d96cee59d4ab0373de4c
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 6 Sep 2019 18:27:47 +0200
lnworker.invoices access now uses lock
(qt gui thread vs asyncio thread race)
Traceback (most recent call last):
File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1685, in do_send
self.pay_lightning_invoice(self.payto_e.lightning_invoice)
File "/home/user/wspace/electrum/electrum/gui/qt/main_window.py", line 1667, in pay_lightning_invoice
self.invoice_list.update()
File "/home/user/wspace/electrum/electrum/gui/qt/invoice_list.py", line 73, in update
_list = self.parent.wallet.get_invoices()
File "/home/user/wspace/electrum/electrum/wallet.py", line 525, in get_invoices
out += self.lnworker.get_invoices()
File "/home/user/wspace/electrum/electrum/util.py", line 401, in
return lambda *args, **kw_args: do_profile(args, kw_args)
File "/home/user/wspace/electrum/electrum/util.py", line 397, in do_profile
o = func(*args, **kw_args)
File "/home/user/wspace/electrum/electrum/lnworker.py", line 1007, in get_invoices
for key, (invoice, direction, status) in self.invoices.items():
RuntimeError: dictionary changed size during iteration
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
@@ -958,7 +958,8 @@ class LNWallet(LNWorker):
def save_invoice(self, payment_hash:bytes, invoice, direction, status):
key = bh2u(payment_hash)
- self.invoices[key] = invoice, direction, status
+ with self.lock:
+ self.invoices[key] = invoice, direction, status
self.storage.put('lightning_invoices', self.invoices)
self.storage.write()
@@ -1004,7 +1005,9 @@ class LNWallet(LNWorker):
def get_invoices(self):
# invoices = outgoing
out = []
- for key, (invoice, direction, status) in self.invoices.items():
+ with self.lock:
+ invoice_items = list(self.invoices.items())
+ for key, (invoice, direction, status) in invoice_items:
if direction == SENT and status != PR_PAID:
out.append(self.get_request(key))
return out
@@ -1013,7 +1016,9 @@ class LNWallet(LNWorker):
def get_requests(self):
# requests = incoming
out = []
- for key, (invoice, direction, status) in self.invoices.items():
+ with self.lock:
+ invoice_items = list(self.invoices.items())
+ for key, (invoice, direction, status) in invoice_items:
if direction == RECEIVED and status != PR_PAID:
out.append(self.get_request(key))
return out
@@ -1062,7 +1067,8 @@ class LNWallet(LNWorker):
def delete_invoice(self, payment_hash_hex: str):
try:
- del self.invoices[payment_hash_hex]
+ with self.lock:
+ del self.invoices[payment_hash_hex]
except KeyError:
return
self.storage.put('lightning_invoices', self.invoices)