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
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user