Skip to content

Commit

Permalink
feat: add Neutrino to Litecoin LND
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Mar 25, 2020
1 parent 9a00ccb commit 03b3d12
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 26 deletions.
21 changes: 21 additions & 0 deletions images/lnd/0.9.0-beta-ltc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.13.9-alpine3.10 as builder
RUN apk add --no-cache bash git make gcc musl-dev
RUN git clone -b v0.9.0-beta https://github.com/ltcsuite/lnd $GOPATH/src/github.com/ltcsuite/lnd
WORKDIR $GOPATH/src/github.com/ltcsuite/lnd
ADD patches /tmp/patches/
RUN go mod vendor
RUN patch vendor/github.com/ltcsuite/neutrino/chainsync/filtercontrol.go /tmp/patches/checkpoints.patch
RUN go install -v -mod=vendor -tags="invoicesrpc" ./cmd/lnd ./cmd/lncli

# Final stage
FROM alpine:3.10
RUN apk add --no-cache bash expect supervisor tor
COPY --from=builder /go/bin/lnd /go/bin/lncli /usr/local/bin/
COPY entrypoint.sh wait-file.sh start_tor.sh /
COPY lnd.conf /root
COPY supervisord.conf /etc/supervisor/conf.d/
COPY torrc /etc/tor/
VOLUME [ "/root/.lnd" ]
RUN mkdir -p /root/.lnd/tor
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 10009 9735 19735 10735 20735
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,46 @@ LND_DIR="/root/.lnd"
mkdir -p $LND_DIR

if [[ ! -e $LND_DIR/lnd.conf ]]; then
if [ "$CHAIN" = "bitcoin" ]; then
echo "[DEBUG] Using configuration for bitcoin"
cp /root/lnd-btc.conf $LND_DIR/lnd.conf
else
echo "[DEBUG] Using configuration for litecoin"
cp /root/lnd-ltc.conf $LND_DIR/lnd.conf
fi
cp /root/lnd.conf $LND_DIR/lnd.conf
fi

NEUTRINO=${NEUTRINO:-}

if [ ! -z ${NEUTRINO} ]; then
PEERS="[neutrino]\n"

case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.addpeer=159.203.125.125:18333\nneutrino.addpeer=64.79.152.132:18333"
case $CHAIN in
bitcoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=159.203.125.125:18333\nneutrino.connect=64.79.152.132:18333\nneutrino.connect=167.71.109.195:18333\nneutrino.connect=178.128.0.29:18333"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=69.143.97.89:8333\nneutrino.connect=73.31.42.95:8333\nneutrino.connect=96.9.244.139:8333\nneutrino.connect=138.68.244.82:8333"
;;
esac
;;
mainnet)
PEERS="${PEERS}neutrino.addpeer=78.46.126.167:8333\nneutrino.addpeer=144.76.68.78:8333"
litecoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:19335\nneutrino.connect=ltcd.servebeer.com:54795"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:9333\nneutrino.connect=ltcd.servebeer.com:9333"
;;
esac
;;
esac

echo "[DEBUG] Enabling neutrino"
sed -i "s/bitcoin.node=bitcoind/bitcoin.node=neutrino\n\n${PEERS}/g" $LND_DIR/lnd.conf
case $CHAIN in
bitcoin)
sed -i "s/bitcoin.node=bitcoind/bitcoin.node=neutrino\n\n${PEERS}/g" $LND_DIR/lnd.conf
;;
litecoin)
sed -i "s/litecoin.node=litecoind/litecoin.node=neutrino\n\n${PEERS}/g" $LND_DIR/lnd.conf
;;
esac
fi

set +e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
debuglevel=debug
rpclisten=0.0.0.0:10009
restlisten=0.0.0.0:8080
max-cltv-expiry=20000
Expand Down
34 changes: 34 additions & 0 deletions images/lnd/0.9.0-beta-ltc/patches/checkpoints.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/chainsync/filtercontrol.go b/chainsync/filtercontrol.go
index b710cd0d..be7ab155 100644
--- a/chainsync/filtercontrol.go
+++ b/chainsync/filtercontrol.go
@@ -37,9 +37,9 @@ var filterHeaderCheckpoints = map[wire.BitcoinNet]map[uint32]*chainhash.Hash{
1301000: hashFromStr("0074cd8e4c41407320ca0b3d640265114ec184ae29970a9ab04d6d7e6c67cc43"),
1403000: hashFromStr("b99e248cea04bdcf8cc988ea5ebc91b6e7a190c6896a9df718f1b702cf636b28"),
1505000: hashFromStr("ffdf8b4637b533a5848563d8541a116c3cf1584bef07a05fd11ed4ba0b61e10c"),
- 1603000: hashFromStr("c2c90fb353716039127ca73f8535c35e706247eb3d8a11d87fb4f16b9d65bd7e"),
- 1701000: hashFromStr("d7e61b0749447415ee235ce0ca1f470a43da9ffa6d896ffb516f0a60ce8e3830"),
- 1781000: hashFromStr("a65460c214fa771ee389cf50b5b586b2bba42a9ed70f6d93a172b553f5331987"),
+ 1603000: hashFromStr("c9c115714f37e5e325effc9a386a5659844a5abfa6c25695fd591c4a61933b13"),
+ 1701000: hashFromStr("f6bee45920a347c2b245a5c9796c20268c27bc7143c7c62ac0ac2cc9b5dcdace"),
+ 1781000: hashFromStr("6d2505ff9d8ecaa573db0bb3aa34fc48986de30a39d29c3137333d753ae2b868"),
},

// Testnet filter header checkpoints.
@@ -48,11 +48,11 @@ var filterHeaderCheckpoints = map[wire.BitcoinNet]map[uint32]*chainhash.Hash{
101000: hashFromStr("8b54ceec6cde1f1b20e6ac2b28dcf3d72c51799760e625b156fca8b7c5c0a558"),
303000: hashFromStr("3ff217c2f372bc3bb7273e085906183f8afac1858922c710e05d2f961357b21f"),
505000: hashFromStr("1b7ebeabbcc37731932b09a68f36b4a3a54aa6067805a3ea6c057d866e8549d1"),
- 707000: hashFromStr("8655245633fb4970c1bd1138510d77fa2ca46dd562595ce16fb7858ee16c326b"),
- 909000: hashFromStr("d1970e74d93cb8d57e8f68b73bbe75081d965019b9e0e0974e2c379cc33074d7"),
- 1111000: hashFromStr("211dd22de8fcfde9fba0dbecc609ec8f757ec72f886d6a541a31859a3bc4567d"),
- 1313000: hashFromStr("d7390b6fb9387d1222f98d0f8f3c47708b018d03f4ebb6df1951c1a73197df81"),
- 1351000: hashFromStr("2cf080309f34762bb630b9be46da3dd110cd272f6045092f1f255a4d179192f6"),
+ 707000: hashFromStr("ec15c1a28981cb19096b5b9aea2f2389fc41e755a1b0228f27f2976d50851e21"),
+ 909000: hashFromStr("cd51428ecfbe42bcd3920c42eaa1ad14d5b2eecff7d8a57d70df9e0b247f5b4a"),
+ 1111000: hashFromStr("52a74833414ded5b7bdc7e274b0107569adcdb09cdd9f75bf25ad8793aac437c"),
+ 1313000: hashFromStr("c81c0db37c5bcf27ba973215770a8a17630cb85db5035f898c94d1964b9b856a"),
+ 1351000: hashFromStr("fd0d8cd62d0ce53ae003c5bd32db4943f330e4a1cc9ea09be6a34325085016e4"),
},
}

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.12-alpine3.10 as builder
FROM golang:1.13.9-alpine3.10 as builder
RUN apk add --no-cache bash git make gcc musl-dev
RUN git clone -b v0.9.0-beta https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd
RUN git clone -b v0.9.2-beta https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd
WORKDIR $GOPATH/src/github.com/lightningnetwork/lnd
RUN make tags="invoicesrpc" install

Expand All @@ -9,7 +9,7 @@ FROM alpine:3.10
RUN apk add --no-cache bash expect supervisor tor
COPY --from=builder /go/bin/lnd /go/bin/lncli /usr/local/bin/
COPY entrypoint.sh wait-file.sh start_tor.sh /
COPY lnd-btc.conf lnd-ltc.conf /root/
COPY lnd.conf /root
COPY supervisord.conf /etc/supervisor/conf.d/
COPY torrc /etc/tor/
VOLUME [ "/root/.lnd" ]
Expand Down
96 changes: 96 additions & 0 deletions images/lnd/0.9.2-beta/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash
set -euo pipefail
set -m
. /wait-file.sh

SCRIPT_PATH=$(dirname "$0")
cd "$SCRIPT_PATH" || exit 1

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

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

NEUTRINO=${NEUTRINO:-}

if [ ! -z ${NEUTRINO} ]; then
PEERS="[neutrino]\n"

case $CHAIN in
bitcoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=159.203.125.125:18333\nneutrino.connect=64.79.152.132:18333\nneutrino.connect=167.71.109.195:18333\nneutrino.connect=178.128.0.29:18333"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=69.143.97.89:8333\nneutrino.connect=73.31.42.95:8333\nneutrino.connect=96.9.244.139:8333\nneutrino.connect=138.68.244.82:8333"
;;
esac
;;
litecoin)
case $NETWORK in
testnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:19335\nneutrino.connect=ltcd.servebeer.com:54795"
;;
mainnet)
PEERS="${PEERS}neutrino.connect=ltcd.michael1011.at:9333\nneutrino.connect=ltcd.servebeer.com:9333"
;;
esac
;;
esac

echo "[DEBUG] Enabling neutrino"
case $CHAIN in
bitcoin)
sed -i "s/bitcoin.node=bitcoind/bitcoin.node=neutrino\n\n${PEERS}/g" $LND_DIR/lnd.conf
;;
litecoin)
sed -i "s/litecoin.node=litecoind/litecoin.node=neutrino\n\n${PEERS}/g" $LND_DIR/lnd.conf
;;
esac
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..."

wait_file "$LND_HOSTNAME" && {
LND_ONION_ADDRESS=$(cat "$LND_HOSTNAME")
echo "Onion address for lnd-$CHAIN is $LND_ONION_ADDRESS"
# mark lnd as locked before starting
touch "$HOME/.lnd/wallet.lock"
# notify peers.sh to bootstrap peers
touch "$HOME/.lnd/peers.lock"

case $CHAIN in
bitcoin)
PORT=9735
;;
litecoin)
PORT=10735
;;
esac

case $NETWORK in
testnet)
PORT=$((PORT + 10000))
;;
esac

if [ -z ${EXTERNAL_IP+x} ]; then
lnd --$CHAIN.$NETWORK --lnddir=$LND_DIR --externalip="$LND_ONION_ADDRESS:$PORT" --listen="0.0.0.0:$PORT"
else
lnd --$CHAIN.$NETWORK --lnddir=$LND_DIR --externalip="$LND_ONION_ADDRESS:$PORT" --externalip="$EXTERNAL_IP:$PORT" --listen="0.0.0.0:$PORT"
fi
} || exit 1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
debuglevel=debug
rpclisten=0.0.0.0:10009
restlisten=0.0.0.0:8080
max-cltv-expiry=5000
Expand Down
18 changes: 18 additions & 0 deletions images/lnd/0.9.2-beta/start_tor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

case $CHAIN in
bitcoin)
PORT=9735
;;
litecoin)
PORT=10735
;;
esac

if [[ $NETWORK == "testnet" ]]; then
PORT=$((PORT + 10000))
fi

sed -i "s/<port>/$PORT/g" /etc/tor/torrc

tor -f /etc/tor/torrc
15 changes: 15 additions & 0 deletions images/lnd/0.9.2-beta/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[supervisord]
nodaemon=true
logfile=/root/supervisord.log
childlogdir=/root
user=root

[program:tor]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
command=/start_tor.sh

[program:lnd]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
command=/entrypoint.sh
5 changes: 5 additions & 0 deletions images/utils/launcher/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def parse_command_line_arguments(self):
parser.add_argument("--external-ip")
parser.add_argument("--backup-dir")
parser.add_argument("--bitcoin-neutrino", type=bool)
parser.add_argument("--litecoin-neutrino", type=bool)
parser.add_argument("--nodes-json")
parser.add_argument("--expose-ports")

Expand All @@ -503,6 +504,10 @@ def apply_network_args(self):
if "bitcoind" in self.nodes:
self.nodes["bitcoind"]["mode"] = "neutrino"

if hasattr(self.args, "litecoin_neutrino"):
if "litecoind" in self.nodes:
self.nodes["litecoind"]["mode"] = "neutrino"

if hasattr(self.args, "expose_ports"):
value = self.args.expose_ports
parts = value.split(",")
Expand Down
6 changes: 4 additions & 2 deletions images/utils/launcher/config/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

[litecoind]
# This option specifies the container's volume mapping data directory. It
# will be ignored if you set below `external` option to true.
# will be ignored if you set below `external` or `neutrino` option to true.
#dir = "$mainnet_dir/data/litecoind"

# 9332 - JSON-RPC port
Expand All @@ -51,8 +51,10 @@
#expose-ports = ["9332", "9333", "29332:28332", "29333:28333"]

# Set `external` option true and fill options below to enable using external
# litecoind node.
# litecoind node. Setting `neutrino` to true will use lnd's internal light client
# and ignore `external` option.
#external = false
#neutrino = false
#rpc-host = "127.0.0.1"
#rpc-port = 9332
#rpc-user = "xu"
Expand Down
6 changes: 4 additions & 2 deletions images/utils/launcher/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

[litecoind]
# This option specifies the container's volume mapping data directory. It
# will be ignored if you set below `external` option to true.
# will be ignored if you set below `external` or `neutrino` option to true.
#dir = "$testnet_dir/data/litecoind"

# 19332 - JSON-RPC port
Expand All @@ -51,8 +51,10 @@
#expose-ports = ["19332", "19333", "29332:28332", "29333:28333"]

# Set `external` option true and fill options below to enable using external
# litecoind node.
# litecoind node. Setting `neutrino` to true will use lnd's internal light client
# and ignore `external` option.
#external = false
#neutrino = false
#rpc-host = "127.0.0.1"
#rpc-port = 19332
#rpc-user = "xu"
Expand Down
8 changes: 4 additions & 4 deletions nodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"image": "exchangeunion/geth:1.9.12"
},
"lndbtc": {
"image": "exchangeunion/lnd:0.9.0-beta"
"image": "exchangeunion/lnd:0.9.2-beta"
},
"lndltc": {
"image": "exchangeunion/lnd:0.9.0-beta"
"image": "exchangeunion/lnd:0.9.0-beta-ltc"
},
"raiden": {
"image": "exchangeunion/raiden:0.100.5a1.dev162-2217bcb"
Expand All @@ -50,10 +50,10 @@
"image": "exchangeunion/geth:1.9.12"
},
"lndbtc": {
"image": "exchangeunion/lnd:0.9.0-beta"
"image": "exchangeunion/lnd:0.9.2-beta"
},
"lndltc": {
"image": "exchangeunion/lnd:0.9.0-beta"
"image": "exchangeunion/lnd:0.9.0-beta-ltc"
},
"raiden": {
"image": "exchangeunion/raiden:0.100.5a1.dev162-2217bcb"
Expand Down

0 comments on commit 03b3d12

Please sign in to comment.