Skip to content

Commit

Permalink
fix waiting for light clients
Browse files Browse the repository at this point in the history
  • Loading branch information
reliveyy committed Oct 16, 2020
1 parent be2cfa6 commit 8039cd6
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions images/utils/launcher/check_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 8039cd6

Please sign in to comment.