Skip to content

Commit

Permalink
let xud use different ports for different networks
Browse files Browse the repository at this point in the history
  • Loading branch information
reliveyy committed Apr 3, 2020
1 parent 3943ce0 commit 705bb01
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 129 deletions.
3 changes: 2 additions & 1 deletion images/raiden/0.100.5a1.dev162-2217bcb/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ ADDRESS=$(get_addr)
OPTS=(
"--rpc"
"--accept-disclaimer"
"--resolver-endpoint http://xud:8887/resolveraiden"
"--eth-rpc-endpoint $RPC_ENDPOINT"
"--password-file $RAIDEN_DIR/passphrase.txt"
"--datadir $RAIDEN_DIR"
Expand All @@ -70,6 +69,7 @@ testnet)
"--user-deposit-contract-address 0x3A17B96809258523c4DED8e7F3f9364D13eBc2C5"
"--monitoring-service-contract-address 0x9F50cEA29307d7D91c5176Af42f3aB74f0190dD3"
"--one-to-n-contract-address 0xA102879b6AE21B93432160532DeB8f0EA1C50b30"
"--resolver-endpoint http://xud:18887/resolveraiden"
)
;;
mainnet)
Expand All @@ -85,6 +85,7 @@ mainnet)
"--user-deposit-contract-address 0x4F26957E8fd331D53DD60feE77533FBE7564F5Fe"
"--monitoring-service-contract-address 0x37cC37D7703554183aE544391945e7D0588b7693"
"--one-to-n-contract-address 0x3dda5BE50Af796618d9f48c021Cf0C9FD64FFeb1"
"--resolver-endpoint http://xud:8887/resolveraiden"
)
;;
esac
Expand Down
7 changes: 7 additions & 0 deletions images/utils/launcher/node/xud.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def __init__(self, name, ctx):
super().__init__(name, ctx)

self._cli = "xucli"
if self.network == "simnet":
self._cli = "xucli --rpcport=28886"
elif self.network == "testnet":
self._cli = "xucli --rpcport=18886"
elif self.network == "mainnet":
self._cli = "xucli --rpcport=8886"

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

def status(self):
Expand Down
8 changes: 2 additions & 6 deletions images/xud/1.0.0-beta.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
FROM node:12-alpine3.11 AS builder
ARG REPO=ExchangeUnion/xud
ARG BRANCH=v1.0.0-beta.2
# Use pure JS implemented secp256k1 bindings
RUN apk add --no-cache git rsync bash musl-dev go python3 make g++
# This is a "hack" to automatically invalidate the cache in case there are new commits
#ADD https://api.github.com/repos/$REPO/commits/$BRANCH /dev/null
ADD https://api.github.com/repos/$REPO/commits/$BRANCH /dev/null
RUN git clone -b $BRANCH --depth=2 https://github.com/$REPO
WORKDIR /xud
RUN git show HEAD > git_head.txt
RUN npm install
RUN npm run compile
RUN npm run compile:seedutil
Expand All @@ -18,7 +16,6 @@ RUN rm -rf seedutil/go
FROM node:12-alpine3.11
RUN apk add --no-cache bash supervisor tor
COPY --from=builder /xud /app
COPY xud.conf /tmp/
COPY entrypoint.sh xud-backup.sh /app/
COPY start_tor.sh update-backup-dir.sh /
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
Expand All @@ -27,5 +24,4 @@ RUN ln -s /app/bin/xucli /usr/local/bin/xucli
RUN mkdir -p /root/.xud/tor
WORKDIR /app
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
VOLUME [ "/root/.xud" ]
EXPOSE 8885 18885 8887
EXPOSE 8887 18887 28887
6 changes: 2 additions & 4 deletions images/xud/1.0.0-beta.2/Dockerfile.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ RUN apk add --no-cache git rsync bash musl-dev go python3 make g++
# python: not found
RUN apk add --no-cache python
# This is a "hack" to automatically invalidate the cache in case there are new commits
#ADD https://api.github.com/repos/$REPO/commits/$BRANCH /dev/null
ADD https://api.github.com/repos/$REPO/commits/$BRANCH /dev/null
RUN git clone -b $BRANCH --depth=2 https://github.com/$REPO
WORKDIR /xud
RUN git show HEAD > git_head.txt
RUN cp package.json /tmp/package.json
RUN sed -Ei 's/"grpc-tools": "1.8.0",//g' package.json
RUN npm install
Expand All @@ -24,7 +23,6 @@ RUN rm -rf seedutil/go
FROM node:12-alpine3.11
RUN apk add --no-cache bash supervisor tor
COPY --from=builder /xud /app
COPY xud.conf /tmp/
COPY entrypoint.sh xud-backup.sh /app/
COPY start_tor.sh update-backup-dir.sh /
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
Expand All @@ -34,4 +32,4 @@ RUN mkdir -p /root/.xud/tor
WORKDIR /app
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
VOLUME [ "/root/.xud" ]
EXPOSE 8885 18885 8887
EXPOSE 8887 18887 28887
85 changes: 53 additions & 32 deletions images/xud/1.0.0-beta.2/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
#!/bin/bash

XUD_DIR=$HOME/.xud
XUD_CONF=$XUD_DIR/xud.conf
KEYSTORE_DIR=$HOME/.raiden/keystore

[[ -e $KEYSTORE_DIR ]] || mkdir -p "$KEYSTORE_DIR"

case $NETWORK in
mainnet)
P2P_PORT=8885
RPC_PORT=8886
HTTP_PORT=8887
;;
testnet)
P2P_PORT=18885
RPC_PORT=18886
HTTP_PORT=18887
;;
simnet)
P2P_PORT=28885
RPC_PORT=28886
HTTP_PORT=28887
;;
*)
echo >&2 "Error: Unsupported network: $NETWORK"
exit 1
esac

wait_file() {
local file="$1"; shift
local wait_seconds="${1:-10}"; shift # after 10 seconds we give up
Expand All @@ -10,40 +37,34 @@ wait_file() {
}

write_config() {
echo "xud.conf not found - creating a new one..."
cp /tmp/xud.conf ~/.xud

hn="$(hostname)"
n="${hn:3}"

if [[ -z $n ]]; then
insid="0"
else
insid="$n"
fi

case $NETWORK in
mainnet)
DELTA=0
;;
testnet)
DELTA=10000
;;
esac

sed -i "s/<instance_id>/$insid/g" ~/.xud/xud.conf
sed -i "s/<network>/$NETWORK/g" ~/.xud/xud.conf
sed -i "s/<p2p_port>/$((8885 + DELTA))/g" ~/.xud/xud.conf

XUD_HOSTNAME="/root/.xud/tor/hostname"
wait_file "$XUD_HOSTNAME" && {
XUD_ONION_ADDRESS=$(cat $XUD_HOSTNAME)
echo "Onion address for xud is $XUD_ONION_ADDRESS"
sed -i "s/<onion_address>/$XUD_ONION_ADDRESS/g" ~/.xud/xud.conf
}
echo "xud.conf not found - creating a new one..."
cp /app/sample-xud.conf $XUD_CONF

XUD_HOSTNAME="/root/.xud/tor/hostname"
wait_file "$XUD_HOSTNAME" && {
XUD_ONION_ADDRESS=$(cat $XUD_HOSTNAME)
echo "Onion address for xud is $XUD_ONION_ADDRESS"
}

sed -i "s/network.*/network = \"$NETWORK\"/" $XUD_CONF
sed -i '/\[http/,/^$/s/host.*/host = "0.0.0.0"/' $XUD_CONF
sed -i "/\[http/,/^$/s/port.*/port = $HTTP_PORT/" $XUD_CONF
sed -i '/\[lnd\.BTC/,/^$/s/host.*/host = "lndbtc"/' $XUD_CONF
sed -i "/\[lnd\.BTC/,/^$/s|^$|certpath = \"/root/.lndbtc/tls.cert\"\nmacaroonpath = \"/root/.lndbtc/data/chain/bitcoin/$NETWORK/admin.macaroon\"\n|" $XUD_CONF
sed -i '/\[lnd\.LTC/,/^$/s/host.*/host = "lndltc"/' $XUD_CONF
sed -i '/\[lnd\.LTC/,/^$/s/port.*/port = 10009/' $XUD_CONF
sed -i "/\[lnd\.LTC/,/^$/s|^$|certpath = \"/root/.lndltc/tls.cert\"\nmacaroonpath = \"/root/.lndltc/data/chain/litecoin/$NETWORK/admin.macaroon\"\n|" $XUD_CONF
sed -i "/\[p2p/,/^$/s/addresses.*/addresses = \[\"$XUD_ONION_ADDRESS\"]/" $XUD_CONF
sed -i "/\[p2p/,/^$/s/port.*/port = $P2P_PORT/" $XUD_CONF
sed -i '/\[p2p/,/^$/s/tor = .*/tor = true/' $XUD_CONF
sed -i '/\[p2p/,/^$/s/torport.*/torport = 9050/' $XUD_CONF
sed -i '/\[raiden/,/^$/s/host.*/host = "raiden"/' $XUD_CONF
sed -i "/\[raiden/,/^$/s|^$|keystorepath = \"$KEYSTORE_DIR\"\n|" $XUD_CONF
sed -i '/\[rpc/,/^$/s/host.*/host = "0.0.0.0"/' $XUD_CONF
sed -i "/\[rpc/,/^$/s/port.*/port = $RPC_PORT/" $XUD_CONF
}

if [[ $XUD_REWRITE_CONFIG || ! -e ~/.xud/xud.conf ]]; then
if [[ $XUD_REWRITE_CONFIG || ! -e $XUD_CONF ]]; then
write_config
fi

Expand Down
86 changes: 0 additions & 86 deletions images/xud/1.0.0-beta.2/xud.conf

This file was deleted.

0 comments on commit 705bb01

Please sign in to comment.