Skip to content

Commit 37622e1

Browse files
committed
feat: add --xud.debug option
This option will run xud with NodeJS --inspect option on 0.0.0.0:9229 by default. But you could use --xud.debug=<any port> to customize it.
1 parent 178b477 commit 37622e1

File tree

9 files changed

+90
-39
lines changed

9 files changed

+90
-39
lines changed

images/utils/launcher/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import shlex
33
import traceback
4-
import os
54

65
from .config import Config, ConfigLoader
76
from .shell import Shell
@@ -266,17 +265,17 @@ def launch(self):
266265
print()
267266
except ConfigError as e:
268267
if e.scope == ConfigErrorScope.COMMAND_LINE_ARGS:
269-
print("Failed to parse command-line arguments, exiting.")
270-
print(f"Error details: {e.__cause__}")
268+
print("Failed to parse command-line arguments, exiting.")
269+
traceback.print_exc()
271270
elif e.scope == ConfigErrorScope.GENERAL_CONF:
272-
print("Failed to parse config file {}, exiting.".format(e.conf_file))
273-
print(f"Error details: {e.__cause__}")
271+
print("Failed to parse config file {}, exiting.".format(e.conf_file))
272+
traceback.print_exc()
274273
elif e.scope == ConfigErrorScope.NETWORK_CONF:
275-
print("Failed to parse config file {}, exiting.".format(e.conf_file))
276-
print(f"Error details: {e.__cause__}")
274+
print("Failed to parse config file {}, exiting.".format(e.conf_file))
275+
traceback.print_exc()
277276
except FatalError as e:
278277
if config and config.logfile:
279-
print(f"Error: {e}. For more details, see {config.logfile}")
278+
print(f"Error: {e}. For more details, see {config.logfile}")
280279
else:
281280
traceback.print_exc()
282281
except Exception: # exclude system exceptions like SystemExit

images/utils/launcher/config/config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ def parse_command_line_arguments(self):
279279
action="store_true",
280280
help="Preserve xud xud.conf file during updates"
281281
)
282+
group.add_argument(
283+
"--xud.debug",
284+
nargs='?',
285+
metavar="<port>",
286+
help="Run xud with NodeJS --inspect option on specific port (default: 9229)"
287+
)
282288

283289
group = parser.add_argument_group("arby")
284290
group.add_argument(
@@ -425,6 +431,29 @@ def update_ports(self, node, parsed, mapping=None):
425431
if p not in node["ports"]:
426432
node["ports"].append(p)
427433

434+
def update_debug(self, node, parsed):
435+
node_name = node["name"]
436+
437+
def process(value):
438+
if not value:
439+
if node_name == "xud":
440+
value = 9229
441+
else:
442+
raise RuntimeError("No default debug port for node %s" % node_name)
443+
if isinstance(value, str):
444+
value = int(value)
445+
assert isinstance(value, int)
446+
node["debug"] = value
447+
p = PortPublish("%s" % value)
448+
if p not in node["ports"]:
449+
node["ports"].append(p)
450+
451+
if "debug" in parsed:
452+
process(parsed["debug"])
453+
opt = "{}.debug".format(node_name)
454+
if hasattr(self.args, opt):
455+
process(getattr(self.args, opt))
456+
428457
def update_bitcoind_kind(self, node, parsed):
429458
if "external" in parsed:
430459
print("Warning: Using deprecated option \"external\". Please use \"mode\" instead.")
@@ -655,6 +684,7 @@ def update_xud(self, parsed):
655684
"""
656685
node = self.nodes["xud"]
657686
self.update_ports(node, parsed)
687+
self.update_debug(node, parsed)
658688

659689
def update_disabled(self, node, parsed, opt):
660690
if "disabled" in parsed:

images/utils/launcher/config/mainnet.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
# 8886 - gRPC port
120120
# 8080 - webproxy port
121121
#expose-ports = ["8885", "8886", "8080"]
122+
#debug = 9229
122123

123124
[arby]
124125
#live-cex="false"

images/utils/launcher/config/simnet.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# 28886 - gRPC port
3333
# 28080 - webproxy port
3434
#expose-ports = ["28885", "28886", "28080:8080"]
35+
#debug = 9229
3536

3637
[arby]
3738
#live-cex="false"

images/utils/launcher/config/testnet.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
# 18886 - gRPC port
120120
# 18080 - webproxy port
121121
#expose-ports = ["18885", "18886", "18080:8080"]
122+
#debug = 9229
122123

123124
[arby]
124125
#live-cex="false"

images/utils/launcher/node/xud.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, name, ctx):
4242

4343
self.container_spec.environment.append("NODE_ENV=production")
4444

45+
if "debug" in self.node_config:
46+
debug_port = self.node_config["debug"]
47+
self.container_spec.environment.append(f"DEBUG_PORT={debug_port}")
48+
4549
self._cli = "xucli"
4650

4751
self.api = XudApi(CliBackend(self.client, self.container_name, self._logger, self._cli))

images/xud/entrypoint.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ cat $XUD_CONF
109109
/xud-backup.sh &
110110

111111
# use exec to properly respond to SIGINT
112-
exec xud $@
112+
if [[ -e ${DEBUG_PORT:-} ]]; then
113+
export NODE_ENV=development
114+
exec node --inspect-brk=0.0.0.0:$DEBUG_PORT bin/xud
115+
else
116+
exec xud $@
117+
fi
118+

setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Connext options:
7272
Xud options:
7373
--xud.expose-ports <port>[,<port>] Expose xud service ports to your host machine
7474
--xud.preserve-config Preserve xud xud.conf file during updates
75+
--xud.debug [<port>] Run xud with NodeJS --inspect option on specific port (default: 9229)
7576
7677
Arby options:
7778
--arby.live-cex [true|false] Production/Demo mode (default: false)

tools/core/image.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,44 @@ def repo(self) -> Optional[str]:
140140
def _run_command(self, cmd):
141141
self._logger.info(cmd)
142142

143-
stop = threading.Event()
144-
145-
def f():
146-
nonlocal stop
147-
counter = 0
148-
on_travis = "TRAVIS_BRANCH" in os.environ
149-
while not stop.is_set():
150-
counter = counter + 1
151-
152-
if on_travis:
153-
print("Still building... ({})".format(counter), flush=True)
154-
stop.wait(10)
155-
continue
156-
157-
print(".", end="", flush=True)
158-
stop.wait(1)
159-
if not on_travis:
160-
print()
161-
threading.Thread(target=f).start()
162-
try:
163-
output = execute(cmd)
164-
self._logger.debug("$ %s\n%s", cmd, output)
165-
stop.set()
166-
except CalledProcessError as e:
167-
stop.set()
168-
print(e.output.decode(), end="", flush=True)
169-
raise SystemExit(1)
170-
except:
171-
stop.set()
172-
raise
143+
on_travis = "TRAVIS_BRANCH" in os.environ
144+
145+
if on_travis:
146+
stop = threading.Event()
147+
148+
def f():
149+
nonlocal stop
150+
counter = 0
151+
152+
while not stop.is_set():
153+
counter = counter + 1
154+
155+
if on_travis:
156+
print("Still building... ({})".format(counter), flush=True)
157+
stop.wait(10)
158+
continue
159+
160+
print(".", end="", flush=True)
161+
stop.wait(1)
162+
if not on_travis:
163+
print()
164+
threading.Thread(target=f).start()
165+
try:
166+
output = execute(cmd)
167+
self._logger.debug("$ %s\n%s", cmd, output)
168+
stop.set()
169+
except CalledProcessError as e:
170+
stop.set()
171+
print(e.output.decode(), end="", flush=True)
172+
raise SystemExit(1)
173+
except:
174+
stop.set()
175+
raise
176+
else:
177+
print("\033[1m$ %s\033[0m" % cmd)
178+
exit_code = os.system(cmd)
179+
if exit_code != 0:
180+
raise RuntimeError("The command exits with non-zero code %s" % exit_code)
173181

174182
def _build(self, args: List[str], build_dir: str, build_tag: str) -> None:
175183
cmd = "docker build {} {}".format(" ".join(args), build_dir)

0 commit comments

Comments
 (0)