Browse Source

lnworker.pay: run path finding in sep. thread (don't block evt loop)

hard-fail-on-bad-server-string
ThomasV 5 years ago
parent
commit
b6cb983733
  1. 3
      electrum/lnrouter.py
  2. 7
      electrum/lnworker.py

3
electrum/lnrouter.py

@ -189,9 +189,6 @@ class LNPathFinder(Logger):
if my_channels is None: my_channels = {} if my_channels is None: my_channels = {}
# note: we don't lock self.channel_db, so while the path finding runs, # note: we don't lock self.channel_db, so while the path finding runs,
# the underlying graph could potentially change... (not good but maybe ~OK?) # the underlying graph could potentially change... (not good but maybe ~OK?)
# (but at the time of writing, we are called on the asyncio event loop,
# and the graph is also only updated from the event loop, so it will
# not change)
# FIXME paths cannot be longer than 20 edges (onion packet)... # FIXME paths cannot be longer than 20 edges (onion packet)...

7
electrum/lnworker.py

@ -927,12 +927,11 @@ class LNWallet(LNWorker):
reason = '' reason = ''
for i in range(attempts): for i in range(attempts):
try: try:
# note: this call does path-finding which takes ~1 second # note: path-finding runs in a separate thread so that we don't block the asyncio loop
# -> we will BLOCK the asyncio loop... (could just run in a thread and await, # graph updates might occur during the computation
# but then the graph could change while the path-finding runs on it)
self.set_invoice_status(key, PR_ROUTING) self.set_invoice_status(key, PR_ROUTING)
self.network.trigger_callback('invoice_status', key) self.network.trigger_callback('invoice_status', key)
route = self._create_route_from_invoice(decoded_invoice=lnaddr) route = await run_in_thread(self._create_route_from_invoice, lnaddr)
self.set_invoice_status(key, PR_INFLIGHT) self.set_invoice_status(key, PR_INFLIGHT)
self.network.trigger_callback('invoice_status', key) self.network.trigger_callback('invoice_status', key)
payment_attempt_log = await self._pay_to_route(route, lnaddr) payment_attempt_log = await self._pay_to_route(route, lnaddr)

Loading…
Cancel
Save