Skip to content

Commit

Permalink
add initial support for eclair
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed May 10, 2019
1 parent fa6039a commit 0b259e4
Show file tree
Hide file tree
Showing 35 changed files with 624 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .idea/dictionaries/darwin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions _defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ export FIRST_BITCOIND_RPC_PORT_ON_HOST=${FIRST_BITCOIND_RPC_PORT_ON_HOST:-13300}
export FIRST_LIGHTNING_SERVER_PORT_ON_HOST=${FIRST_LIGHTNING_SERVER_PORT_ON_HOST:-14000}
export FIRST_LIGHTNING_RPC_PORT_ON_HOST=${FIRST_LIGHTNING_RPC_PORT_ON_HOST:-14300}
export FIRST_LIGHTNING_REST_PORT_ON_HOST=${FIRST_LIGHTNING_REST_PORT_ON_HOST:-14600}
export FIRST_ECLAIR_SERVER_PORT_ON_HOST=${FIRST_ECLAIR_SERVER_PORT_ON_HOST:-15000}
export FIRST_ECLAIR_RPC_PORT_ON_HOST=${FIRST_ECLAIR_RPC_PORT_ON_HOST:-15300}

export LND_AUTO_NAME_PREFIX=${LND_AUTO_NAME_PREFIX:-lnd}
export BTCD_AUTO_NAME_PREFIX=${BTCD_AUTO_NAME_PREFIX:-btcd}
export BITCOIND_AUTO_NAME_PREFIX=${BITCOIND_AUTO_NAME_PREFIX:-bitcoind}
export LIGHTNING_AUTO_NAME_PREFIX=${LIGHTNING_AUTO_NAME_PREFIX:-lightning}
export ECLAIR_AUTO_NAME_PREFIX=${ECLAIR_AUTO_NAME_PREFIX:-eclair}

# ---------------------------------------------------------------------------------------------------------------------------
# you can tweak these on per-node basis in your recipes
Expand All @@ -74,6 +77,8 @@ export DEFAULT_BTCWALLET_CONF_PATH=${DEFAULT_BTCWALLET_CONF_PATH:-docker/btcd/bt
export DEFAULT_LND_CONF_PATH=${DEFAULT_LND_CONF_PATH:-docker/lnd/lnd.conf}
export DEFAULT_LIGHTNING_CONF_PATH=${DEFAULT_LIGHTNING_CONF_PATH:-docker/lightning/config}
export DEFAULT_BITCOIND_CONF_PATH=${DEFAULT_BITCOIND_CONF_PATH:-docker/bitcoind/bitcoin.conf}
export DEFAULT_ECLAIR_REPO_PATH=${DEFAULT_ECLAIR_REPO_PATH:-repos/eclair}
export DEFAULT_ECLAIR_CONF_PATH=${DEFAULT_ECLAIR_CONF_PATH:-docker/eclair/eclair.conf}

export SIMVERSE_HOST_BIND=${SIMVERSE_HOST_BIND:-127.0.0.1:} # note the trailing colon, see https://docs.docker.com/compose/compose-file/#ports
export SIMVERSE_EXTRA_SERVICE_CONFIG=${SIMVERSE_EXTRA_SERVICE_CONFIG}
Expand Down Expand Up @@ -114,6 +119,13 @@ export LIGHTNING_P2P_PORT=${LIGHTNING_P2P_PORT:-9735}
export LIGHTNING_RPC_BIND=${LIGHTNING_RPC_BIND:-0.0.0.0}
export LIGHTNING_RPC_PORT=${LIGHTNING_RPC_PORT:-9835}

export ECLAIR_BACKEND=${ECLAIR_BACKEND}
export ECLAIR_BITCOIN_RPC_HOST=${ECLAIR_BITCOIN_RPC_HOST}
export ECLAIR_P2P_BIND=${ECLAIR_P2P_BIND:-0.0.0.0}
export ECLAIR_P2P_PORT=${ECLAIR_P2P_PORT:-9735}
export ECLAIR_RPC_BIND=${ECLAIR_RPC_BIND:-0.0.0.0}
export ECLAIR_RPC_PORT=${ECLAIR_RPC_PORT:-8080}

export BTCD_EXTRA_PARAMS=${BTCD_EXTRA_PARAMS}
export BTCWALLET_EXTRA_PARAMS=${BTCWALLET_EXTRA_PARAMS}
export BTCCTL_EXTRA_PARAMS=${BTCCTL_EXTRA_PARAMS}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ to manage the cluster and provides a set of helper scripts for your convenience.
## Features

* supports [btcd](https://github.com/btcsuite/btcd) and [bitcoind](https://github.com/bitcoin/bitcoin) as backend nodes
* supports [lnd](https://github.com/lightningnetwork/lnd) and [lightningd](https://github.com/ElementsProject/lightning) as lightning nodes
* supports [lnd](https://github.com/lightningnetwork/lnd), [lightningd](https://github.com/ElementsProject/lightning) and [eclair](https://github.com/ACINQ/eclair) as lightning nodes

## Workflow

Expand Down
10 changes: 10 additions & 0 deletions recipes/a1m2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

. cookbook/cookbook.sh

prelude

add bitcoind

add eclair alice
add eclair bob
23 changes: 23 additions & 0 deletions recipes/a1m3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

. cookbook/cookbook.sh

prelude

add bitcoind

add eclair alice
add eclair bob
add eclair charlie

# generate init script to build connections
cat > init <<EOF
#!/usr/bin/env bash
set -e -o pipefail
# connect LN nodes
connect alice charlie
connect charlie bob
EOF
chmod +x init
94 changes: 92 additions & 2 deletions recipes/cookbook/cookbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,38 @@ FIRST_BITCOIND_SERVER_PORT_ON_HOST=${FIRST_BITCOIND_SERVER_PORT_ON_HOST:?$REQUIR
FIRST_BITCOIND_RPC_PORT_ON_HOST=${FIRST_BITCOIND_RPC_PORT_ON_HOST:?$REQUIRED}
FIRST_LIGHTNING_SERVER_PORT_ON_HOST=${FIRST_LIGHTNING_SERVER_PORT_ON_HOST:?$REQUIRED}
FIRST_LIGHTNING_RPC_PORT_ON_HOST=${FIRST_LIGHTNING_RPC_PORT_ON_HOST:?$REQUIRED}
FIRST_ECLAIR_SERVER_PORT_ON_HOST=${FIRST_ECLAIR_SERVER_PORT_ON_HOST:?$REQUIRED}
FIRST_ECLAIR_RPC_PORT_ON_HOST=${FIRST_ECLAIR_RPC_PORT_ON_HOST:?$REQUIRED}

LND_AUTO_NAME_PREFIX=${LND_AUTO_NAME_PREFIX:?$REQUIRED}
BTCD_AUTO_NAME_PREFIX=${BTCD_AUTO_NAME_PREFIX:?$REQUIRED}
BITCOIND_AUTO_NAME_PREFIX=${BITCOIND_AUTO_NAME_PREFIX:?$REQUIRED}
LIGHTNING_AUTO_NAME_PREFIX=${LIGHTNING_AUTO_NAME_PREFIX:?$REQUIRED}
ECLAIR_AUTO_NAME_PREFIX=${ECLAIR_AUTO_NAME_PREFIX:?$REQUIRED}

DEFAULT_BTCD_REPO_PATH=${DEFAULT_BTCD_REPO_PATH:?$REQUIRED}
DEFAULT_BTCWALLET_REPO_PATH=${DEFAULT_BTCWALLET_REPO_PATH:?$REQUIRED}
DEFAULT_LND_REPO_PATH=${DEFAULT_LND_REPO_PATH:?$REQUIRED}
DEFAULT_BITCOIND_REPO_PATH=${DEFAULT_BITCOIND_REPO_PATH:?$REQUIRED}
DEFAULT_LIGHTNING_REPO_PATH=${DEFAULT_LIGHTNING_REPO_PATH:?$REQUIRED}
DEFAULT_ECLAIR_REPO_PATH=${DEFAULT_ECLAIR_REPO_PATH:?$REQUIRED}

DEFAULT_BTCD_CONF_PATH=${DEFAULT_BTCD_CONF_PATH:?$REQUIRED}
DEFAULT_BTCWALLET_CONF_PATH=${DEFAULT_BTCWALLET_CONF_PATH:?$REQUIRED}
DEFAULT_LND_CONF_PATH=${DEFAULT_LND_CONF_PATH:?$REQUIRED}
DEFAULT_BITCOIND_CONF_PATH=${DEFAULT_BITCOIND_CONF_PATH:?$REQUIRED}
DEFAULT_LIGHTNING_CONF_PATH=${DEFAULT_LIGHTNING_CONF_PATH:?$REQUIRED}
DEFAULT_ECLAIR_CONF_PATH=${DEFAULT_ECLAIR_CONF_PATH:?$REQUIRED}

LND_BITCOIN_RPC_HOST=${LND_BITCOIN_RPC_HOST}
LND_BACKEND=${LND_BACKEND}

LIGHTNING_BITCOIN_RPC_HOST=${LIGHTNING_BITCOIN_RPC_HOST}
LIGHTNING_BACKEND=${LIGHTNING_BACKEND}

ECLAIR_BITCOIN_RPC_HOST=${ECLAIR_BITCOIN_RPC_HOST}
ECLAIR_BACKEND=${ECLAIR_BACKEND}

# error codes
NO_ERR=0
ERR_NOT_IMPLEMENTED=10
Expand Down Expand Up @@ -123,12 +131,19 @@ init_lightning_defaults() {
LIGHTNING_REPO_PATH=${DEFAULT_LIGHTNING_REPO_PATH}
LIGHTNING_CONF_PATH=${DEFAULT_LIGHTNING_CONF_PATH}
}

init_eclair_defaults() {
ECLAIR_REPO_PATH=${DEFAULT_ECLAIR_REPO_PATH}
ECLAIR_CONF_PATH=${DEFAULT_ECLAIR_CONF_PATH}
}

init_defaults() {
init_common_defaults
init_btcd_defaults
init_lnd_defaults
init_bitcoind_defaults
init_btcd_defaults
init_lightning_defaults
init_lnd_defaults
init_eclair_defaults
}

reset_common_counters() {
Expand Down Expand Up @@ -172,12 +187,20 @@ reset_lightning_counters() {
LIGHTNING_RPC_PORT_ON_HOST=${FIRST_LIGHTNING_RPC_PORT_ON_HOST}
}

reset_eclair_counters() {
ECLAIR_COUNTER=1
ECLAIR_AUTO_NAME_COUNTER=0
ECLAIR_SERVER_PORT_ON_HOST=${FIRST_ECLAIR_SERVER_PORT_ON_HOST}
ECLAIR_RPC_PORT_ON_HOST=${FIRST_ECLAIR_RPC_PORT_ON_HOST}
}

reset_counters() {
reset_common_counters
reset_lnd_counters
reset_btcd_counters
reset_bitcoind_counters
reset_lightning_counters
reset_eclair_counters
}

advance_common_counters() {
Expand Down Expand Up @@ -220,6 +243,14 @@ advance_lightning_counters() {
((++LN_COUNTER))
}

advance_eclair_counters() {
((++ECLAIR_COUNTER))
((++ECLAIR_SERVER_PORT_ON_HOST))
((++ECLAIR_RPC_PORT_ON_HOST))

((++LN_COUNTER))
}

gen_lnd_auto_name() {
echo "${LND_AUTO_NAME_PREFIX}${LND_AUTO_NAME_COUNTER}"
}
Expand Down Expand Up @@ -252,6 +283,14 @@ advance_lightning_auto_name_counter() {
((++LIGHTNING_AUTO_NAME_COUNTER))
}

gen_eclair_auto_name() {
echo "${ECLAIR_AUTO_NAME_PREFIX}${ECLAIR_AUTO_NAME_COUNTER}"
}

advance_eclair_auto_name_counter() {
((++ECLAIR_AUTO_NAME_COUNTER))
}

eval_template() {
local template_file=$1
eval "cat <<TEMPLATE_EOF_MARKER
Expand Down Expand Up @@ -369,6 +408,11 @@ prepare_lightning_volumes() {
mkdir _volumes/lightning-data-${name}
}

prepare_eclair_volumes() {
local name=${1:?required}
mkdir _volumes/eclair-data-${name}
}

ensure_bitcoin_service() {
if [[ -z "$LAST_BITCOIN_SERVICE" ]]; then
echo_err_with_stack_trace "'add lnd' called but no prior btcd or bitcoind was added, call 'add btcd' or 'add bitcoind' prior adding lnd nodes or set LND_BITCOIN_RPC_HOST explicitly"
Expand Down Expand Up @@ -538,6 +582,51 @@ add_lightning() {
LIGHTNING_BACKEND="$prev_lightning_backend"
}

add_eclair() {
NAME=$1

# generate default name if not given
if [[ -z "$NAME" ]]; then
advance_eclair_auto_name_counter
NAME=$(gen_eclair_auto_name)
fi

# auto-provide ECLAIR_BITCOIN_RPC_HOST if not given
local prev_eclair_bitcoin_rpc_host="$ECLAIR_BITCOIN_RPC_HOST"
if [[ -z "$ECLAIR_BITCOIN_RPC_HOST" ]]; then
ECLAIR_BITCOIN_RPC_HOST="$(get_last_bitcoin_service)"
fi
local prev_eclair_backend="$ECLAIR_BACKEND"
if [[ -z "$ECLAIR_BACKEND" ]]; then
ECLAIR_BACKEND="$(get_last_bitcoin_backend)"
if [[ "$ECLAIR_BACKEND" != "bitcoind" ]]; then
echo_err "lightning node '$NAME' needs bitcoind backend, add at least one bitcoind before adding eclair nodes"
exit ${ERR_REQUIRE_BITCOIND}
fi
fi

echo_service_separator eclair ${NAME} ${ECLAIR_COUNTER}
eval_template "$TEMPLATES_DIR/eclair.yml" >> ${COMPOSE_FILE}

local alias_file="$ALIASES_DIR_NAME/$NAME"
eval_script_template "$TEMPLATES_DIR/eclair-cli-alias.sh" >> "$alias_file"
chmod +x "$alias_file"

# point generic lncli to first eclair node
local default_alias_file="$ALIASES_DIR_NAME/eclair-cli"
if [[ ! -f "$default_alias_file" ]]; then
ln -s "$NAME" ${default_alias_file}
fi

prepare_eclair_volumes "$NAME"

advance_common_counters
advance_eclair_counters

ECLAIR_BITCOIN_RPC_HOST="$prev_eclair_bitcoin_rpc_host"
ECLAIR_BACKEND="$prev_eclair_backend"
}

# -- public API -------------------------------------------------------------------------------------------------------------

prelude() {
Expand Down Expand Up @@ -570,6 +659,7 @@ add() {
"lnd") add_lnd "$@" ;;
"bitcoind") add_bitcoind "$@" ;;
"lightningd"|"lightning"|"c-lightning") add_lightning "$@" ;;
"eclair") add_eclair "$@" ;;
*) echo "unsupported service '$kind', currently allowed are 'btcd' or 'lnd'" ;;
esac
}
Expand Down
15 changes: 15 additions & 0 deletions recipes/cookbook/scaffold/docker/_aux/runtime/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ echo_err() {
printf "\e[31m%s\e[0m\n" "$*" >&2;
}

trim() {
local str
str=$(cat)
if [[ "$str" =~ [^[:space:]](.*[^[:space:]])? ]]; then
printf "%s" "$BASH_REMATCH"
else
echo -n "$str"
fi
}

wait_for_socket() {
local port=${1:?required}
local host=${2:-localhost}
Expand Down Expand Up @@ -104,4 +114,9 @@ wait_for() {
return 1
fi
done
}

strip_ansi_colors() {
# https://superuser.com/a/380778/8244
sed 's/\x1b\[[0-9;]*m//g'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
IFS=$'\n'
read COMMAND

ECLAIR_WALLET_LABEL=eclair

case "$COMMAND" in
get-chain-height) ./bitcoin-cli.sh -getinfo | jq '.blocks' ;;
get-new-address) ./bitcoin-cli.sh getnewaddress "$ECLAIR_WALLET_LABEL" bech32 ;;
get-wallet-balance) ./bitcoin-cli.sh getreceivedbylabel "$ECLAIR_WALLET_LABEL" ;;
*) echo "unknown command '$COMMAND'" ;;
esac
Loading

0 comments on commit 0b259e4

Please sign in to comment.