Skip to content

Commit e1fa1e2

Browse files
committed
update
1 parent 8b4a082 commit e1fa1e2

File tree

9 files changed

+70
-38
lines changed

9 files changed

+70
-38
lines changed

images/utils/launcher/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from launcher.close_other_utils import Action as CloseOtherUtilsAction
77
from launcher.config import Config
8-
from launcher.errors import FatalError, ConfigError, ConfigErrorScope
9-
from launcher.node import NodeManager, ServiceNotFound, ContainerNotFound, NoWaiting
8+
from launcher.errors import FatalError, ConfigError, ConfigErrorScope, NoWaiting
9+
from launcher.node import NodeManager, ServiceNotFound, ContainerNotFound
1010
from launcher.utils import ArgumentError
1111
import docker.errors
1212
import os
@@ -190,11 +190,9 @@ def pre_shell(self):
190190
try:
191191
# FIXME pty signal only works in main thread
192192
xud.ensure_ready(stop)
193-
except KeyboardInterrupt:
193+
except (KeyboardInterrupt, NoWaiting):
194194
stop.set()
195195
raise
196-
except NoWaiting:
197-
pass
198196

199197
self.close_other_utils()
200198

@@ -255,3 +253,5 @@ def launch(self):
255253
env.start()
256254
except KeyboardInterrupt:
257255
print()
256+
except NoWaiting:
257+
pass

images/utils/launcher/config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def parse_command_line_arguments(self):
463463
help="Expose proxy service ports to your host machine"
464464
)
465465

466-
self.args = parser.parse_args()
466+
self.args, unknown = parser.parse_known_args()
467467
self.logger.info("Parsed command-line arguments: %r", self.args)
468468

469469
def update_volume(self, volumes, container_dir, host_dir):

images/utils/launcher/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ def __init__(self, scope: ConfigErrorScope, conf_file: Optional[str] = None):
1717
super().__init__(scope)
1818
self.scope = scope
1919
self.conf_file = conf_file
20+
21+
22+
class NoWaiting(Exception):
23+
pass

images/utils/launcher/node/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from launcher.utils import ArgumentParser, yes_or_no, parallel
1717
from .DockerTemplate import DockerTemplate
1818
from .arby import Arby
19-
from .base import Node, ContainerNotFound, NoWaiting
19+
from .base import Node, ContainerNotFound
2020
from .bitcoind import Bitcoind, Litecoind
2121
from .boltz import Boltz
2222
from .connext import Connext

images/utils/launcher/node/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class ContainerNotFound(Exception):
3535
pass
3636

3737

38-
class NoWaiting(Exception):
39-
pass
40-
41-
4238
class ContainerSpec:
4339
def __init__(self, name: str, image: Image, hostname: str, environment: List[str], command: List[str],
4440
volumes: Dict, ports: Dict):
@@ -202,8 +198,13 @@ def _get_volumes(self, spec_volumes: Dict):
202198
def create(self):
203199
spec = self.container_spec
204200
api = self.client.api
201+
202+
image = spec.image.use_image
203+
204+
logger.debug("Creating container %s with image %s", self.container_name, image)
205+
205206
resp = api.create_container(
206-
image=spec.image.use_image,
207+
image=image,
207208
command=spec.command,
208209
hostname=spec.hostname,
209210
detach=True,

images/utils/launcher/node/lnd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def update_cfheader(self, state: CFHeaderState, stop: Event):
217217
m = p0.match(line)
218218

219219
if m:
220+
#logger.debug("[%s] (match 1) %s", self.name, line)
220221
state.current = int(m.group(1))
221222
state.ready = True
222223
h = max(state.current, state.total)
@@ -226,13 +227,17 @@ def update_cfheader(self, state: CFHeaderState, stop: Event):
226227

227228
m = p1.match(line)
228229
if m:
230+
#logger.debug("[%s] (match 2) %s", self.name, line)
229231
state.current = int(m.group(1))
230232
continue
231233

232234
m = p2.match(line)
233235
if m:
236+
#logger.debug("[%s] (match 3) %s", self.name, line)
234237
state.total = int(m.group(1))
235238

239+
logger.debug("[%s] update_cfheader ends" % self.name)
240+
236241

237242
class Lndbtc(Lnd):
238243
def __init__(self, *args):

images/utils/launcher/node/xud.py

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import logging
66
import os
77
import re
8-
from concurrent.futures import wait
9-
from threading import Event
8+
from concurrent.futures import wait, TimeoutError
9+
import threading
1010
from typing import List, Optional
1111
import docker.errors
1212

1313
from launcher.table import ServiceTable
1414
from launcher.utils import yes_or_no, normalize_path
15+
from launcher.errors import NoWaiting
1516
from .base import Node, CliBackend, CliError
1617
from .lnd import CFHeaderState
1718

@@ -78,7 +79,6 @@ def _get_environment(self) -> List[str]:
7879
]
7980

8081
lndbtc = self.config.nodes["lndbtc"]
81-
env.append("LNDBTC_MODE={}".format(lndbtc["mode"]))
8282
if lndbtc["mode"] == "external":
8383
env.extend([
8484
"LNDBTC_RPC_HOST={}".format(lndbtc["rpc_host"]),
@@ -88,7 +88,6 @@ def _get_environment(self) -> List[str]:
8888
])
8989

9090
lndltc = self.config.nodes["lndltc"]
91-
env.append("LNDLTC_MODE={}".format(lndltc["mode"]))
9291
if lndltc["mode"] == "external":
9392
env.extend([
9493
"LNDLTC_RPC_HOST={}".format(lndbtc["rpc_host"]),
@@ -178,7 +177,7 @@ def extract_exception(self, cmd: str, output: str):
178177
print("^C")
179178
raise KeyboardInterrupt()
180179

181-
def _ensure_dependencies_ready(self, stop: Event):
180+
def _ensure_dependencies_ready(self, stop: threading.Event):
182181
deps = [
183182
self.get_service("lndbtc"),
184183
self.get_service("lndltc"),
@@ -428,9 +427,13 @@ def _ensure_lnds_synced(self, stop):
428427

429428
if len(lnds) > 0:
430429
def all_ready():
430+
nonlocal lnds
431+
431432
return functools.reduce(lambda r, item: r and item.ready, lnds.values(), True)
432433

433-
def print_syncing(stop):
434+
def print_syncing(stop: threading.Event):
435+
nonlocal lnds
436+
434437
print("Syncing light clients:")
435438

436439
rows = {}
@@ -443,6 +446,7 @@ def print_syncing(stop):
443446

444447
while not stop.is_set():
445448
i = 0
449+
logger.debug("lnds %r", lnds)
446450
for lnd, state in lnds.items():
447451
old_msg = rows[lnd.name]
448452
msg = state.message
@@ -461,44 +465,72 @@ def print_syncing(stop):
461465

462466
stop.wait(1)
463467

464-
futs = []
468+
logger.debug("Light clients syncing ends")
465469

466470
executor = self.config.executor
467471

472+
f = executor.submit(print_syncing, stop)
473+
468474
for lnd in lnds:
469-
futs.append(executor.submit(lnd.update_cfheader, lnds[lnd], stop))
475+
executor.submit(lnd.update_cfheader, lnds[lnd], stop)
470476

471-
# Thread(target=print_syncing, args=(stop,)).start()
472-
futs.append(executor.submit(print_syncing, stop))
477+
f.result()
478+
logger.debug("print_syncing ends")
473479

474-
wait(futs)
480+
def _wait_tls_cert(self, stop: threading.Event):
481+
tls_file = os.path.join(self.data_dir, "tls.cert")
482+
while not stop.is_set():
483+
if os.path.exists(tls_file):
484+
break
485+
stop.wait(1)
475486

476-
def ensure_ready(self, stop: Event):
477-
logger.info("Ensuring ready")
487+
def ensure_ready(self, stop: threading.Event):
488+
logger.info("Ensuring XUD is ready")
478489

479490
if self.node_manager.newly_installed:
491+
logger.info("Ensuring LNDs are synced (light)")
480492
self._ensure_lnds_synced(stop)
481493

494+
logger.info("Ensuring XUD dependencies are ready (lndbtc, lndltc and connext)")
482495
self._ensure_dependencies_ready(stop)
483496

497+
logger.info("Waiting for XUD to be ready")
498+
executor = self.config.executor
499+
f = executor.submit(self._wait_tls_cert, stop)
500+
501+
while not stop.is_set():
502+
logger.info("Waiting for XUD tls.cert to be created")
503+
try:
504+
f.result(30)
505+
except TimeoutError:
506+
print("XUD should not take so much time to create \"tls.cert\" file. please check container \"%s\" logs for more details." % self.container_name)
507+
reply = yes_or_no("Would you like to keep waiting?")
508+
if reply == "no":
509+
raise NoWaiting
510+
484511
# Error: ENOENT: no such file or directory, open '/root/.xud/tls.cert'
485512
# xud is starting... try again in a few seconds
486513
# xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again
514+
cmd = self._cli + " getinfo -j"
487515
while not stop.is_set():
488516
try:
489-
exit_code, output = self.exec(self._cli + " getinfo -j")
517+
exit_code, output = self.exec(cmd)
490518
if exit_code == 0:
491519
break
492520
if "xud is locked" in output:
493521
break
522+
logger.debug("[Execute] %s (exit_code=%s)\n%s", cmd, exit_code, output.rstrip())
494523
except docker.errors.APIError:
495524
logger.exception("Failed to getinfo")
496-
stop.wait(3)
525+
stop.wait(1)
497526

498527
if not self.has_wallets():
528+
logger.info("Setting up XUD wallets")
499529
self._setup_wallets()
500530

531+
logger.info("Setting up XUD backup")
501532
self._setup_backup()
502533

503534
if self._is_locked():
535+
logger.info("Unlock XUD")
504536
self._unlock()

images/utils/launcher/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def yes_or_no(prompt, default="yes"):
6969
return default
7070
if reply in ["y", "yes"]:
7171
return "yes"
72-
if reply == ["n", "no"]:
72+
if reply in ["n", "no"]:
7373
return "no"
7474

7575

images/xud/entrypoint.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ CONNEXT_IP=$(getent hosts connext || echo '' | awk '{ print $1 }')
6666
echo "$CONNEXT_IP connext" >> /etc/hosts
6767

6868

69-
while [[ $LNDBTC_MODE == "native" && ! -e /root/.lndbtc/tls.cert ]]; do
70-
echo "[entrypoint] Waiting for /root/.lndbtc/tls.cert to be created..."
71-
sleep 1
72-
done
73-
74-
while [[ $LNDLTC_MODE == "native" && ! -e /root/.lndltc/tls.cert ]]; do
75-
echo "[entrypoint] Waiting for /root/.lndltc/tls.cert to be created..."
76-
sleep 1
77-
done
78-
7969
if [[ -z ${LNDBTC_RPC_HOST:-} ]]; then
8070
LNDBTC_RPC_HOST="lndbtc"
8171
fi

0 commit comments

Comments
 (0)