Skip to content

Commit

Permalink
feat: connext (#429)
Browse files Browse the repository at this point in the history
* Add Connext support

Co-authored-by: Yang Yang <[email protected]>
Co-authored-by: michael1011 <[email protected]>
Co-authored-by: kilrau <[email protected]>
Co-authored-by: raladev <[email protected]>
  • Loading branch information
5 people authored May 15, 2020
1 parent 29b3c18 commit 678c66c
Show file tree
Hide file tree
Showing 31 changed files with 403 additions and 89 deletions.
24 changes: 24 additions & 0 deletions images/connext/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:12-alpine3.11 AS builder
ARG REPO=connext/rest-api-client
ARG BRANCH=master
# Use pure JS implemented secp256k1 bindings
RUN apk add --no-cache git bash python3 make g++ 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
RUN git clone -b $BRANCH --depth=2 https://github.com/$REPO /connext
# lock connext container down to specific commit hash
WORKDIR /connext
RUN git checkout 0d9bb0f7c0aa76423e65bac27a937a612ad3eabb
RUN npm install
RUN npm run build

FROM node:12-alpine3.11
RUN apk add --no-cache bash supervisor curl
RUN mkdir /root/.connext
VOLUME [ "/root/.connext" ]
COPY --from=builder /connext /app
COPY entrypoint.sh /app
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
WORKDIR /app
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 5040
24 changes: 24 additions & 0 deletions images/connext/latest/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:12-alpine3.11 AS builder
ARG REPO=connext/rest-api-client
ARG BRANCH=master
# Use pure JS implemented secp256k1 bindings
RUN apk add --no-cache git bash python3 make g++ 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
RUN git clone -b $BRANCH --depth=2 https://github.com/$REPO /connext
# lock connext container down to specific commit hash
WORKDIR /connext
RUN git checkout 0d9bb0f7c0aa76423e65bac27a937a612ad3eabb
RUN npm install
RUN npm run build

FROM node:12-alpine3.11
RUN apk add --no-cache bash supervisor curl
RUN mkdir /root/.connext
VOLUME [ "/root/.connext" ]
COPY --from=builder /connext /app
COPY entrypoint.sh /app
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
WORKDIR /app
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
EXPOSE 5040
3 changes: 3 additions & 0 deletions images/connext/latest/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
set -m
npm run start
11 changes: 11 additions & 0 deletions images/connext/latest/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[supervisord]
nodaemon=true
logfile=/app/supervisord.log
childlogdir=/app
user=root

[program:connext]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
command=/app/entrypoint.sh
stopsignal=SIGINT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.13-alpine3.10 as builder
RUN apk add --no-cache bash git make gcc musl-dev
ARG VERSION=v0.9.2-beta
ARG VERSION=v0.10.0-beta
RUN wget https://github.com/lightningnetwork/lnd/releases/download/$VERSION/lnd-source-$VERSION.tar.gz
RUN wget https://github.com/lightningnetwork/lnd/releases/download/$VERSION/vendor.tar.gz
RUN mkdir -p $GOPATH/src/github.com/lightningnetwork/lnd
Expand All @@ -26,4 +26,4 @@ COPY --from=builder /go/bin/lnd /go/bin/lncli /usr/local/bin/
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
VOLUME ["/root/.lnd"]
EXPOSE 10009 8080 29375
EXPOSE 10009 10010 8080 29735
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
set -o errexit # -e
set -o nounset # -u
set -o pipefail
set -o monitor # -m

if [[ $CHAIN != "bitcoin" ]]; then
echo "[entrypoint] Invalid chain: $CHAIN"
Expand All @@ -15,7 +14,7 @@ TOR_DIR=$LND_DIR/tor
TOR_LOG=$LND_DIR/tor.log
TOR_DATA_DIR=$LND_DIR/tor-data
LND_HOSTNAME="$TOR_DIR/hostname"
P2P_PORT=29375
P2P_PORT=29735

[[ -e /etc/tor/torrc ]] || cat <<EOF >/etc/tor/torrc
DataDirectory $TOR_DATA_DIR
Expand All @@ -36,32 +35,42 @@ LND_ADDRESS=$(cat "$LND_HOSTNAME")
echo "[entrypoint] Onion address for lndbtc is $LND_ADDRESS"

function connect() {
local key="02db09dd366d7ba6d061502b5b6db1bbb47c0daacd36fc399ab617fd6406cf822a"
local uri="$key@xud1.simnet.exchangeunion.com:10012"
local key="0331c98ab6ec199164130cca2b2118a17e7d5e8b53d4e46ddfd4b656a30c636b70"
local uri="$key@xud1.simnet.exchangeunion.com:29735"
local result
while true; do
echo "[entrypoint] Connecting to $uri"
if lncli -n simnet -c bitcoin connect $uri >/dev/null 2>&1; then
if result=$(lncli -n simnet -c bitcoin connect $uri 2>&1); then
if lncli -n simnet -c bitcoin listpeers | grep -q $key; then
echo "[entrypoint] Connected to $uri"
break
fi
else
if echo "$result" | grep -q "cannot make connection to self"; then
break
fi
if echo "$result" | grep -q "already connected to peer"; then
break
fi
fi
sleep 5
done
}

connect &
#connect &


while ! nc -z 127.0.0.1 9050; do
echo "[entrypoint] Waiting for Tor port 9050 to be open"
sleep 1
done

lnd --externalip=$LND_ADDRESS:$P2P_PORT \
# use exec to properly respond to SIGINT
exec lnd --externalip=$LND_ADDRESS:$P2P_PORT \
--listen=0.0.0.0:$P2P_PORT \
--rpclisten=0.0.0.0:10009 \
--restlisten=0.0.0.0:8080 \
--trickledelay=1 \
--tor.active \
--tor.socks=9050 \
--tor.streamisolation \
Expand Down
4 changes: 2 additions & 2 deletions images/lnd/0.9.0-beta-ltc-patched/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN patch lnd.go /patches/lnd.patch
RUN patch vendor/github.com/ltcsuite/neutrino/blockmanager.go /patches/neutrino.patch
RUN sed -i.bak "s/\!w.isDevEnv/w.isDevEnv/" vendor/github.com/ltcsuite/ltcwallet/wallet/wallet.go
# build
RUN go install -v -mod=vendor -tags="invoicesrpc" -ldflags "-X github.com/lightningnetwork/lnd/build.Commit=$VERSION-patched" ./cmd/lnd ./cmd/lncli
RUN go install -v -mod=vendor -tags="invoicesrpc" -ldflags "-X github.com/ltcsuite/lnd/build.Commit=$VERSION-ltc-patched" ./cmd/lnd ./cmd/lncli
RUN strip /go/bin/lnd /go/bin/lncli


Expand All @@ -27,4 +27,4 @@ COPY --from=builder /go/bin/lnd /go/bin/lncli /usr/local/bin/
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
VOLUME ["/root/.lnd"]
EXPOSE 10009 8080 30375
EXPOSE 10009 10010 8080 30735
24 changes: 16 additions & 8 deletions images/lnd/0.9.0-beta-ltc-patched/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
set -o errexit # -e
set -o nounset # -u
set -o pipefail
set -o monitor # -m

if [[ $CHAIN != "litecoin" ]]; then
echo "[entrypoint] Invalid chain: $CHAIN"
Expand All @@ -15,7 +14,7 @@ TOR_DIR=$LND_DIR/tor
TOR_LOG=$LND_DIR/tor.log
TOR_DATA_DIR=$LND_DIR/tor-data
LND_HOSTNAME="$TOR_DIR/hostname"
P2P_PORT=30375
P2P_PORT=30735

[[ -e /etc/tor/torrc ]] || cat <<EOF >/etc/tor/torrc
DataDirectory $TOR_DATA_DIR
Expand All @@ -35,34 +34,43 @@ done
LND_ADDRESS=$(cat "$LND_HOSTNAME")
echo "[entrypoint] Onion address for lndbtc is $LND_ADDRESS"


function connect() {
local key="023f670b916d8b89e362f4832f8eeca4f2d578a737c97f6fd4845bb7b584647667"
local uri="$key@xud1.simnet.exchangeunion.com:10011"
local key="03af9876d7a367cd92d192c745194e91173830c9e4f0d51cfe19beb687189a99e5"
local uri="$key@xud1.simnet.exchangeunion.com:30735"
local result
while true; do
echo "[entrypoint] Connecting to $uri"
if lncli -n simnet -c litecoin connect $uri >/dev/null 2>&1; then
if result=$(lncli -n simnet -c litecoin connect $uri 2>&1); then
if lncli -n simnet -c litecoin listpeers | grep -q $key; then
echo "[entrypoint] Connected to $uri"
break
fi
else
if echo "$result" | grep -q "cannot make connection to self"; then
break
fi
if echo "$result" | grep -q "already connected to peer"; then
break
fi
fi
sleep 5
done
}

connect &
#connect &


while ! nc -z 127.0.0.1 9050; do
echo "[entrypoint] Waiting for Tor port 9050 to be open"
sleep 1
done

lnd --externalip=$LND_ADDRESS:$P2P_PORT \
# use exec to properly respond to SIGINT
exec lnd --externalip=$LND_ADDRESS:$P2P_PORT \
--listen=0.0.0.0:$P2P_PORT \
--rpclisten=0.0.0.0:10009 \
--restlisten=0.0.0.0:8080 \
--trickledelay=1 \
--tor.active \
--tor.socks=9050 \
--tor.streamisolation \
Expand Down
2 changes: 1 addition & 1 deletion images/lnd/0.9.0-beta-ltc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ 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
EXPOSE 10009 10010 10735 20735
2 changes: 1 addition & 1 deletion images/lnd/0.9.2-beta/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ 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
EXPOSE 10009 10010 9735 19735
12 changes: 10 additions & 2 deletions images/utils/launcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import toml
from shutil import copyfile
import traceback
import time

from .config import Config, ConfigLoader, ArgumentError, InvalidHomeDir, InvalidNetworkDir
from .shell import Shell
Expand All @@ -12,6 +13,7 @@

from .check_wallets import Action as CheckWalletsAction, BackupDirNotAvailable
from .close_other_utils import Action as CloseOtherUtilsAction
from .auto_unlock import Action as AutoUnlockAction



Expand Down Expand Up @@ -103,14 +105,20 @@ def wait_for_channels(self):
# TODO wait for channels
pass

def auto_unlock(self):
AutoUnlockAction(self.node_manager).execute()

def close_other_utils(self):
CloseOtherUtilsAction(self.config.network, self.shell).execute()

def pre_start(self):
if self.config.network in ["testnet", "mainnet"]:
if self.config.network in ["simnet", "testnet", "mainnet"]:
print("\n🏃 Warming up...\n")
time.sleep(5) # cool down 5 seconds in case lnd unlock stuck
self.check_wallets()
elif self.config.network == "simnet":
if self.config.network == "simnet":
self.wait_for_channels()
self.auto_unlock()
self.close_other_utils()

def start(self):
Expand Down
35 changes: 35 additions & 0 deletions images/utils/launcher/auto_unlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from .node import XudApiError

class Action:
def __init__(self, node_manager):
self.node_manager = node_manager

@property
def shell(self):
return self.node_manager.shell

def xud_is_locked(self, xud):
try:
info = xud.api.getinfo()
return False
except XudApiError as e:
if "xud is locked" in str(e):
return True
return False

def xucli_unlock_wrapper(self, xud):
while True:
try:
print()
xud.cli("unlock", self.shell)
break
except KeyboardInterrupt:
break
except:
pass

def execute(self):
xud = self.node_manager.get_node("xud")
if not self.xud_is_locked(xud):
return
self.xucli_unlock_wrapper(xud)
Loading

0 comments on commit 678c66c

Please sign in to comment.