Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --xud.debug option #730

Draft
wants to merge 6 commits into
base: fix-lnd-mode-switching
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 41 additions & 47 deletions images/lndbtc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,55 @@ SCRIPT_PATH=$(dirname "$0")
cd "$SCRIPT_PATH" || exit 1

LND_DIR="/root/.lnd"
LND_CONF="$LND_DIR/lnd.conf"
mkdir -p $LND_DIR

if [[ ! -e $LND_DIR/lnd.conf ]]; then
cp /root/lnd.conf $LND_DIR/lnd.conf
if [[ ! -e $LND_CONF ]]; then
cp /root/lnd.conf "$LND_CONF"
fi

NEUTRINO=${NEUTRINO:-}
echo "[entrypoint] Enabling $MODE mode"
if [[ $MODE == "light" || $MODE == "neutrino" ]]; then
sed -i "s/bitcoin.node.*/bitcoin.node=neutrino/g" "$LND_CONF"
sed -i '/routing/,$d' "$LND_CONF"
if [[ $NETWORK == "testnet" ]]; then
cat <<EOF >> "$LND_CONF"
[routing]
routing.assumechanvalid=1

if [ ! -z ${NEUTRINO} ]; then
PEERS="[neutrino]\n"
[neutrino]
neutrino.addpeer=bitcoin.michael1011.at:18333
neutrino.addpeer=btc.kilrau.com:18333
EOF
elif [[ $NETWORK == "mainnet" ]]; then
cat << EOF >> "$LND_CONF"
[routing]
routing.assumechanvalid=1

case $CHAIN in
bitcoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.addpeer=bitcoin.michael1011.at:18333\nneutrino.addpeer=btc.kilrau.com:18333"
;;
mainnet)
PEERS="${PEERS}neutrino.addpeer=bitcoin.michael1011.at:8333\nneutrino.addpeer=btc.kilrau.com:8333\nneutrino.addpeer=thun.droidtech.it:8333"
;;
esac
;;
litecoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:19335\nneutrino.connect=ltc.kilrau.com:19335"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:9333\nneutrino.connect=ltc.kilrau.com:9333"
;;
esac
;;
esac

echo "[DEBUG] Enabling neutrino"
case $CHAIN in
bitcoin)
sed -i "s/bitcoin.node=bitcoind/bitcoin.node=neutrino\n\n${PEERS}\n\n[routing]\nrouting.assumechanvalid=1/g" $LND_DIR/lnd.conf
;;
litecoin)
sed -i "s/litecoin.node=litecoind/litecoin.node=neutrino\n\n${PEERS}\n\n[routing]\nrouting.assumechanvalid=1/g" $LND_DIR/lnd.conf
;;
esac
[neutrino]
neutrino.addpeer=bitcoin.michael1011.at:8333
neutrino.addpeer=btc.kilrau.com:8333
neutrino.addpeer=thun.droidtech.it:8333
EOF
fi
elif [[ $MODE == "native" ]]; then
sed -i '/routing/,$d' "$LND_CONF"
sed -i "s/bitcoin.node=.*/bitcoin.node=bitcoind/g" "$LND_CONF"
sed -i "s/rpchost.*/rpchost=bitcoind/g" "$LND_CONF"
sed -i "s/rpcuser.*/rpcuser=xu/g" "$LND_CONF"
sed -i "s/rpcpass.*/rpcpass=xu/g" "$LND_CONF"
sed -i "s|zmqpubrawblock.*|zmqpubrawblock=tcp://bitcoind:28332|g" "$LND_CONF"
sed -i "s|zmqpubrawtx.*|zmqpubrawtx=tcp://bitcoind:28333|g" "$LND_CONF"
elif [[ $MODE == "external" ]]; then
sed -i '/routing/,$d' "$LND_CONF"
sed -i "s/bitcoin.node=.*/bitcoin.node=bitcoind/g" "$LND_CONF"
sed -i "s/rpchost.*/rpchost=$RPCHOST/g" "$LND_CONF"
sed -i "s/rpcuser.*/rpcuser=$RPCUSER/g" "$LND_CONF"
sed -i "s/rpcpass.*/rpcpass=$RPCPASS/g" "$LND_CONF"
sed -i "s|zmqpubrawblock.*|zmqpubrawblock=$ZMQPUBRAWBLOCK|g" "$LND_CONF"
sed -i "s|zmqpubrawtx.*|zmqpubrawtx=$ZMQPUBRAWTX|g" "$LND_CONF"
fi

set +e

[[ -n ${RPCHOST:-} ]] && sed -i "s/rpchost.*/rpchost=$RPCHOST/g" $LND_DIR/lnd.conf
[[ -n ${RPCUSER:-} ]] && sed -i "s/rpcuser.*/rpcuser=$RPCUSER/g" $LND_DIR/lnd.conf
[[ -n ${RPCPASS:-} ]] && sed -i "s/rpcpass.*/rpcpass=$RPCPASS/g" $LND_DIR/lnd.conf
[[ -n ${ZMQPUBRAWBLOCK:-} ]] && sed -i "s|zmqpubrawblock.*|zmqpubrawblock=$ZMQPUBRAWBLOCK|g" $LND_DIR/lnd.conf
[[ -n ${ZMQPUBRAWTX:-} ]] && sed -i "s|zmqpubrawtx.*|zmqpubrawtx=$ZMQPUBRAWTX|g" $LND_DIR/lnd.conf

set -e

LND_HOSTNAME="$HOME/.lnd/tor/hostname"
echo "Waiting for lnd-$CHAIN onion address..."

Expand Down
87 changes: 40 additions & 47 deletions images/lndltc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,54 @@ SCRIPT_PATH=$(dirname "$0")
cd "$SCRIPT_PATH" || exit 1

LND_DIR="/root/.lnd"
LND_CONF="$LND_DIR/lnd.conf"
mkdir -p $LND_DIR

if [[ ! -e $LND_DIR/lnd.conf ]]; then
cp /root/lnd.conf $LND_DIR/lnd.conf
if [[ ! -e "$LND_CONF" ]]; then
cp /root/lnd.conf "$LND_CONF"
fi

NEUTRINO=${NEUTRINO:-}
echo "[entrypoint] Enabling $MODE mode"
if [[ $MODE == "light" || $MODE == "neutrino" ]]; then
sed -i "s/litecoin.node.*/litecoin.node=neutrino/g" "$LND_CONF"
sed -i '/routing/,$d' "$LND_CONF"
if [[ $NETWORK == "testnet" ]]; then
cat <<EOF >> "$LND_CONF"
[routing]
routing.assumechanvalid=1

if [ ! -z ${NEUTRINO} ]; then
PEERS="[neutrino]\n"
[neutrino]
neutrino.connect=ltcd.michael1011.at:19335
neutrino.connect=ltc.kilrau.com:19335
EOF
elif [[ $NETWORK == "mainnet" ]]; then
cat << EOF >> "$LND_CONF"
[routing]
routing.assumechanvalid=1

case $CHAIN in
bitcoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.addpeer=bitcoin.michael1011.at:18333\nneutrino.addpeer=btc.kilrau.com:18333"
;;
mainnet)
PEERS="${PEERS}neutrino.addpeer=bitcoin.michael1011.at:8333\nneutrino.addpeer=btc.kilrau.com:8333"
;;
esac
;;
litecoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:19335\nneutrino.connect=ltc.kilrau.com:19335"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:9333\nneutrino.connect=ltc.kilrau.com:9333"
;;
esac
;;
esac

echo "[DEBUG] Enabling neutrino"
case $CHAIN in
bitcoin)
sed -i "s/bitcoin.node=bitcoind/bitcoin.node=neutrino\n\n${PEERS}\n\n[routing]\nrouting.assumechanvalid=1/g" $LND_DIR/lnd.conf
;;
litecoin)
sed -i "s/litecoin.node=litecoind/litecoin.node=neutrino\n\n${PEERS}\n\n[routing]\nrouting.assumechanvalid=1/g" $LND_DIR/lnd.conf
;;
esac
[neutrino]
neutrino.connect=ltcd.michael1011.at:9333
neutrino.connect=ltc.kilrau.com:9333
EOF
fi
elif [[ $MODE == "native" ]]; then
sed -i '/routing/,$d' "$LND_CONF"
sed -i "s/litecoin.node=.*/litecoin.node=litecoind/g" "$LND_CONF"
sed -i "s/rpchost.*/rpchost=litecoind/g" "$LND_CONF"
sed -i "s/rpcuser.*/rpcuser=xu/g" "$LND_CONF"
sed -i "s/rpcpass.*/rpcpass=xu/g" "$LND_CONF"
sed -i "s|zmqpubrawblock.*|zmqpubrawblock=tcp://litecoind:28332|g" "$LND_CONF"
sed -i "s|zmqpubrawtx.*|zmqpubrawtx=tcp://litecoind:28333|g" "$LND_CONF"
elif [[ $MODE == "external" ]]; then
sed -i '/routing/,$d' "$LND_CONF"
sed -i "s/litecoin.node=.*/litecoin.node=litecoind/g" "$LND_CONF"
sed -i "s/rpchost.*/rpchost=$RPCHOST/g" "$LND_CONF"
sed -i "s/rpcuser.*/rpcuser=$RPCUSER/g" "$LND_CONF"
sed -i "s/rpcpass.*/rpcpass=$RPCPASS/g" "$LND_CONF"
sed -i "s|zmqpubrawblock.*|zmqpubrawblock=$ZMQPUBRAWBLOCK|g" "$LND_CONF"
sed -i "s|zmqpubrawtx.*|zmqpubrawtx=$ZMQPUBRAWTX|g" "$LND_CONF"
fi

set +e

[[ -n ${RPCHOST:-} ]] && sed -i "s/rpchost.*/rpchost=$RPCHOST/g" $LND_DIR/lnd.conf
[[ -n ${RPCUSER:-} ]] && sed -i "s/rpcuser.*/rpcuser=$RPCUSER/g" $LND_DIR/lnd.conf
[[ -n ${RPCPASS:-} ]] && sed -i "s/rpcpass.*/rpcpass=$RPCPASS/g" $LND_DIR/lnd.conf
[[ -n ${ZMQPUBRAWBLOCK:-} ]] && sed -i "s|zmqpubrawblock.*|zmqpubrawblock=$ZMQPUBRAWBLOCK|g" $LND_DIR/lnd.conf
[[ -n ${ZMQPUBRAWTX:-} ]] && sed -i "s|zmqpubrawtx.*|zmqpubrawtx=$ZMQPUBRAWTX|g" $LND_DIR/lnd.conf

set -e

LND_HOSTNAME="$HOME/.lnd/tor/hostname"
echo "Waiting for lnd-$CHAIN onion address..."

Expand Down
15 changes: 7 additions & 8 deletions images/utils/launcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import shlex
import traceback
import os

from .config import Config, ConfigLoader
from .shell import Shell
Expand Down Expand Up @@ -266,17 +265,17 @@ def launch(self):
print()
except ConfigError as e:
if e.scope == ConfigErrorScope.COMMAND_LINE_ARGS:
print("Failed to parse command-line arguments, exiting.")
print(f"Error details: {e.__cause__}")
print("Failed to parse command-line arguments, exiting.")
traceback.print_exc()
elif e.scope == ConfigErrorScope.GENERAL_CONF:
print("Failed to parse config file {}, exiting.".format(e.conf_file))
print(f"Error details: {e.__cause__}")
print("Failed to parse config file {}, exiting.".format(e.conf_file))
traceback.print_exc()
elif e.scope == ConfigErrorScope.NETWORK_CONF:
print("Failed to parse config file {}, exiting.".format(e.conf_file))
print(f"Error details: {e.__cause__}")
print("Failed to parse config file {}, exiting.".format(e.conf_file))
traceback.print_exc()
except FatalError as e:
if config and config.logfile:
print(f"Error: {e}. For more details, see {config.logfile}")
print(f"Error: {e}. For more details, see {config.logfile}")
else:
traceback.print_exc()
except Exception: # exclude system exceptions like SystemExit
Expand Down
30 changes: 30 additions & 0 deletions images/utils/launcher/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ def parse_command_line_arguments(self):
action="store_true",
help="Preserve xud xud.conf file during updates"
)
group.add_argument(
"--xud.debug",
nargs='?',
metavar="<port>",
help="Run xud with NodeJS --inspect option on specific port (default: 9229)"
)

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

def update_debug(self, node, parsed):
node_name = node["name"]

def process(value):
if not value:
if node_name == "xud":
value = 9229
else:
raise RuntimeError("No default debug port for node %s" % node_name)
if isinstance(value, str):
value = int(value)
assert isinstance(value, int)
node["debug"] = value
p = PortPublish("%s" % value)
if p not in node["ports"]:
node["ports"].append(p)

if "debug" in parsed:
process(parsed["debug"])
opt = "{}.debug".format(node_name)
if hasattr(self.args, opt):
process(getattr(self.args, opt))

def update_bitcoind_kind(self, node, parsed):
if "external" in parsed:
print("Warning: Using deprecated option \"external\". Please use \"mode\" instead.")
Expand Down Expand Up @@ -655,6 +684,7 @@ def update_xud(self, parsed):
"""
node = self.nodes["xud"]
self.update_ports(node, parsed)
self.update_debug(node, parsed)

def update_disabled(self, node, parsed, opt):
if "disabled" in parsed:
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
# 8886 - gRPC port
# 8080 - webproxy port
#expose-ports = ["8885", "8886", "8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/simnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# 28886 - gRPC port
# 28080 - webproxy port
#expose-ports = ["28885", "28886", "28080:8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
1 change: 1 addition & 0 deletions images/utils/launcher/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
# 18886 - gRPC port
# 18080 - webproxy port
#expose-ports = ["18885", "18886", "18080:8080"]
#debug = 9229

[arby]
#live-cex="false"
Expand Down
9 changes: 4 additions & 5 deletions images/utils/launcher/node/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ def get_environment(self):
else:
layer1_node = self.config.nodes["litecoind"]

if layer1_node["mode"] == "neutrino" or layer1_node["mode"] == "light":
environment.extend([
f'NEUTRINO=True',
])
elif layer1_node["mode"] == "external":
mode = layer1_node["mode"]
environment.append(f"MODE={mode}")

if mode == "external":
environment.extend([
f'RPCHOST={layer1_node["external_rpc_host"]}',
f'RPCUSER={layer1_node["external_rpc_user"]}',
Expand Down
4 changes: 4 additions & 0 deletions images/utils/launcher/node/xud.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self, name, ctx):

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

if "debug" in self.node_config:
debug_port = self.node_config["debug"]
self.container_spec.environment.append(f"DEBUG_PORT={debug_port}")

self._cli = "xucli"

self.api = XudApi(CliBackend(self.client, self.container_name, self._logger, self._cli))
Expand Down
8 changes: 7 additions & 1 deletion images/xud/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ cat $XUD_CONF
/xud-backup.sh &

# use exec to properly respond to SIGINT
exec xud $@
if [[ -n ${DEBUG_PORT:-} ]]; then
export NODE_ENV=development
exec node --inspect-brk=0.0.0.0:$DEBUG_PORT bin/xud
else
exec xud $@
fi

1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Connext options:
Xud options:
--xud.expose-ports <port>[,<port>] Expose xud service ports to your host machine
--xud.preserve-config Preserve xud xud.conf file during updates
--xud.debug [<port>] Run xud with NodeJS --inspect option on specific port (default: 9229)
Arby options:
--arby.live-cex [true|false] Production/Demo mode (default: false)
Expand Down
Loading