electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 30753ed4756a49b45c201f714022e4765908b717
parent 680b129b4a92f619e6be85ce75901aef291eeff8
Author: ThomasV <thomasv@electrum.org>
Date:   Fri, 12 Oct 2018 16:23:53 +0200

watchtower: use network job, catch exceptions

Diffstat:
Melectrum/lnwatcher.py | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py @@ -47,7 +47,7 @@ class LNWatcher(PrintError): watchtower_url = self.config.get('watchtower_url') self.watchtower = jsonrpclib.Server(watchtower_url) if watchtower_url else None 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 wrapper(self, *args, **kwargs): @@ -56,12 +56,17 @@ class LNWatcher(PrintError): return func(self, *args, **kwargs) return wrapper + @aiosafe async def watchtower_task(self): while True: name, args, kwargs = await self.watchtower_queue.get() - self.print_error('sending to watchtower', name, args) func = getattr(self.watchtower, name) - func(*args, **kwargs) + try: + 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): # FIXME: json => every update takes linear instead of constant disk write