tfix race between network and lnwatcher (network.add_job does not always work) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 9362130fba5001021c2061150e1e28c33883f7bf DIR parent e761f5b876785cb2f6b8329ea84454491677fc75 HTML Author: ThomasV <thomasv@electrum.org> Date: Sat, 13 Oct 2018 14:12:30 +0200 fix race between network and lnwatcher (network.add_job does not always work) Diffstat: M electrum/daemon.py | 6 ++++-- M electrum/lnwatcher.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) --- DIR diff --git a/electrum/daemon.py b/electrum/daemon.py t@@ -155,8 +155,6 @@ class Daemon(DaemonThread): self.network = Network(config) self.network._loop_thread = self._loop_thread self.fx = FxThread(config, self.network) - if self.network: - self.network.start([self.fx.run]) self.gui = None # path -> wallet; make sure path is standardized. self.wallets = {} # type: Dict[str, Abstract_Wallet] t@@ -164,7 +162,11 @@ class Daemon(DaemonThread): self.server = None if listen_jsonrpc: self.init_server(config, fd) + # server-side watchtower self.watchtower = WatchTower(self.config, self.network.lnwatcher) if self.config.get('watchtower_host') else None + # client-side + if self.network: + self.network.start([self.fx.run, self.network.lnwatcher.watchtower_task]) self.start() def init_server(self, config: SimpleConfig, fd): DIR diff --git a/electrum/lnwatcher.py b/electrum/lnwatcher.py t@@ -19,6 +19,7 @@ class LNWatcher(PrintError): # TODO if verifier gets an incorrect merkle proof, that tx will never verify!! # similarly, what if server ignores request for merkle proof? # maybe we should disconnect from server in these cases + verbosity_filter = 'W' def __init__(self, network): self.network = network t@@ -47,7 +48,6 @@ 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.network.add_job(self.watchtower_task), self.network.asyncio_loop) def with_watchtower(func): def wrapper(self, *args, **kwargs): t@@ -59,8 +59,11 @@ class LNWatcher(PrintError): @ignore_exceptions @log_exceptions async def watchtower_task(self): + self.print_error('watchtower task started') while True: name, args, kwargs = await self.watchtower_queue.get() + if self.watchtower is None: + continue func = getattr(self.watchtower, name) try: r = func(*args, **kwargs)