Skip to content

Commit d9e0545

Browse files
committed
fix waiting for light clients
1 parent 23ad29d commit d9e0545

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

images/utils/launcher/check_wallets.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import docker
55
import time
6-
from concurrent.futures import ThreadPoolExecutor
6+
from concurrent.futures import ThreadPoolExecutor, wait
77
from docker.models.containers import Container
88
from datetime import datetime
99
import re
@@ -276,7 +276,10 @@ def ensure_layer2_ready(self) -> None:
276276
nodes = self.config.nodes
277277
if self.node_manager.newly_installed:
278278
if self.network == "simnet":
279-
self.lnd_cfheaders["bitcoin"] = CFHeaderState()
279+
if self.config.nodes["lndbtc"]["mode"] == "native":
280+
self.lnd_cfheaders["bitcoin"] = CFHeaderState()
281+
if self.config.nodes["lndltc"]["mode"] == "native":
282+
self.lnd_cfheaders["litecoin"] = CFHeaderState()
280283
self.lnd_cfheaders["litecoin"] = CFHeaderState()
281284
if "bitcoind" in nodes and nodes["bitcoind"]["mode"] in ["neutrino", "light"]:
282285
self.lnd_cfheaders["bitcoin"] = CFHeaderState()
@@ -287,27 +290,18 @@ def ensure_layer2_ready(self) -> None:
287290
print("Syncing light clients:")
288291
self._print_lnd_cfheaders(erase_last_line=False)
289292

290-
with ThreadPoolExecutor(max_workers=2, thread_name_prefix="LndReady") as executor:
291-
native_lndbtc = self.config.nodes["lndbtc"]["mode"] == "native"
292-
native_lndltc = self.config.nodes["lndltc"]["mode"] == "native"
293-
294-
if native_lndbtc:
295-
f1 = executor.submit(self.ensure_lnd_ready, "bitcoin")
293+
with ThreadPoolExecutor(max_workers=len(self.lnd_cfheaders), thread_name_prefix="LndReady") as executor:
294+
futs = {}
295+
for chain in self.lnd_cfheaders:
296+
futs[executor.submit(self.ensure_lnd_ready, chain)] = chain
296297

297-
if native_lndltc:
298-
f2 = executor.submit(self.ensure_lnd_ready, "litecoin")
298+
done, not_done = wait(futs)
299299

300-
if native_lndbtc:
301-
try:
302-
f1.result()
303-
except Exception as e:
304-
raise FatalError("Failed to wait for lndbtc to be ready") from e
305-
306-
if native_lndltc:
307-
try:
308-
f2.result()
309-
except Exception as e:
310-
raise FatalError("Failed to wait for lndltc to be ready") from e
300+
if len(not_done) > 0:
301+
for f in not_done:
302+
f.cancel()
303+
lnds = ", ".join([futs[f] for f in not_done])
304+
raise FatalError("Failed to wait for {} to be ready".format(lnds))
311305

312306
if self.node_manager.newly_installed:
313307
print()

0 commit comments

Comments
 (0)