From 8039cd660c5ed976b9c2236d8b163c75f515b934 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Fri, 16 Oct 2020 14:44:24 +0800 Subject: [PATCH] fix waiting for light clients --- images/utils/launcher/check_wallets.py | 36 +++++++++++--------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/images/utils/launcher/check_wallets.py b/images/utils/launcher/check_wallets.py index d4f720654..9b884d32f 100644 --- a/images/utils/launcher/check_wallets.py +++ b/images/utils/launcher/check_wallets.py @@ -3,7 +3,7 @@ import os import docker import time -from concurrent.futures import ThreadPoolExecutor +from concurrent.futures import ThreadPoolExecutor, wait from docker.models.containers import Container from datetime import datetime import re @@ -276,7 +276,10 @@ def ensure_layer2_ready(self) -> None: nodes = self.config.nodes if self.node_manager.newly_installed: if self.network == "simnet": - self.lnd_cfheaders["bitcoin"] = CFHeaderState() + if self.config.nodes["lndbtc"]["mode"] == "native": + self.lnd_cfheaders["bitcoin"] = CFHeaderState() + if self.config.nodes["lndltc"]["mode"] == "native": + self.lnd_cfheaders["litecoin"] = CFHeaderState() self.lnd_cfheaders["litecoin"] = CFHeaderState() if "bitcoind" in nodes and nodes["bitcoind"]["mode"] in ["neutrino", "light"]: self.lnd_cfheaders["bitcoin"] = CFHeaderState() @@ -287,27 +290,18 @@ def ensure_layer2_ready(self) -> None: print("Syncing light clients:") self._print_lnd_cfheaders(erase_last_line=False) - with ThreadPoolExecutor(max_workers=2, thread_name_prefix="LndReady") as executor: - native_lndbtc = self.config.nodes["lndbtc"]["mode"] == "native" - native_lndltc = self.config.nodes["lndltc"]["mode"] == "native" - - if native_lndbtc: - f1 = executor.submit(self.ensure_lnd_ready, "bitcoin") + with ThreadPoolExecutor(max_workers=len(self.lnd_cfheaders), thread_name_prefix="LndReady") as executor: + futs = {} + for chain in self.lnd_cfheaders: + futs[executor.submit(self.ensure_lnd_ready, chain)] = chain - if native_lndltc: - f2 = executor.submit(self.ensure_lnd_ready, "litecoin") + done, not_done = wait(futs) - if native_lndbtc: - try: - f1.result() - except Exception as e: - raise FatalError("Failed to wait for lndbtc to be ready") from e - - if native_lndltc: - try: - f2.result() - except Exception as e: - raise FatalError("Failed to wait for lndltc to be ready") from e + if len(not_done) > 0: + for f in not_done: + f.cancel() + lnds = ", ".join([futs[f] for f in not_done]) + raise FatalError("Failed to wait for {} to be ready".format(lnds)) if self.node_manager.newly_installed: print()