Browse Source

watchtower: use network job, catch exceptions

regtest_lnd
ThomasV 6 years ago
committed by SomberNight
parent
commit
d762370c03
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/lnwatcher.py

9
electrum/lnwatcher.py

@ -47,7 +47,7 @@ class LNWatcher(PrintError):
watchtower_url = self.config.get('watchtower_url') watchtower_url = self.config.get('watchtower_url')
self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None
self.watchtower_queue = asyncio.Queue() self.watchtower_queue = asyncio.Queue()
asyncio.run_coroutine_threadsafe(self.watchtower_task(), self.network.asyncio_loop) self.network.start([self.watchtower_task])
def with_watchtower(func): def with_watchtower(func):
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
@ -56,12 +56,17 @@ class LNWatcher(PrintError):
return func(self, *args, **kwargs) return func(self, *args, **kwargs)
return wrapper return wrapper
@aiosafe
async def watchtower_task(self): async def watchtower_task(self):
while True: while True:
name, args, kwargs = await self.watchtower_queue.get() name, args, kwargs = await self.watchtower_queue.get()
self.print_error('sending to watchtower', name, args)
func = getattr(self.watchtower, name) func = getattr(self.watchtower, name)
try:
func(*args, **kwargs) func(*args, **kwargs)
except:
self.print_error('could not reach watchtower, will retry in 5s', name, args)
await asyncio.sleep(5)
await self.watchtower_queue.put((name, args, kwargs))
def write_to_disk(self): def write_to_disk(self):
# FIXME: json => every update takes linear instead of constant disk write # FIXME: json => every update takes linear instead of constant disk write

Loading…
Cancel
Save