2019-04-12 05:13:00 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-08-28 04:01:08 +02:00
|
|
|
## Short script to startup some local nodes with
|
2019-04-12 05:13:00 +02:00
|
|
|
## bitcoind, all running on regtest
|
2019-04-12 05:25:02 +02:00
|
|
|
## Makes it easier to test things out, by hand.
|
2019-04-12 05:13:00 +02:00
|
|
|
|
|
|
|
## Should be called by source since it sets aliases
|
2019-04-12 05:25:02 +02:00
|
|
|
##
|
2019-04-12 21:06:21 +02:00
|
|
|
## First load this file up.
|
|
|
|
##
|
2019-04-12 05:25:02 +02:00
|
|
|
## $ source contrib/startup_regtest.sh
|
2019-04-12 21:06:21 +02:00
|
|
|
##
|
|
|
|
## Start up the nodeset
|
|
|
|
##
|
2020-08-28 04:01:08 +02:00
|
|
|
## $ start_ln 3
|
2019-04-12 21:03:59 +02:00
|
|
|
##
|
2019-04-12 05:25:02 +02:00
|
|
|
## Let's connect the nodes.
|
|
|
|
##
|
|
|
|
## $ l2-cli getinfo | jq .id
|
|
|
|
## "02b96b03e42d9126cb5228752c575c628ad09bdb7a138ec5142bbca21e244ddceb"
|
|
|
|
## $ l2-cli getinfo | jq .binding[0].port
|
|
|
|
## 9090
|
|
|
|
## $ l1-cli connect 02b96b03e42d9126cb5228752c575c628ad09bdb7a138ec5142bbca21e244ddceb@localhost:9090
|
|
|
|
## {
|
|
|
|
## "id" : "030b02fc3d043d2d47ae25a9306d98d2abb7fc9bee824e68b8ce75d6d8f09d5eb7"
|
|
|
|
## }
|
|
|
|
##
|
2019-04-12 21:06:21 +02:00
|
|
|
## When you're finished, clean up or stop
|
2019-04-12 05:25:02 +02:00
|
|
|
##
|
2019-04-12 21:06:21 +02:00
|
|
|
## $ stop_ln # stops the services, keeps the aliases
|
2019-04-12 05:25:02 +02:00
|
|
|
##
|
2019-04-12 05:13:00 +02:00
|
|
|
|
2019-08-09 07:22:24 +02:00
|
|
|
# Do the Right Thing if we're currently in top of srcdir.
|
|
|
|
if [ -z "$PATH_TO_LIGHTNING" ] && [ -x cli/lightning-cli ] && [ -x lightningd/lightningd ]; then
|
|
|
|
PATH_TO_LIGHTNING=$(pwd)
|
2019-04-12 05:13:00 +02:00
|
|
|
fi
|
|
|
|
|
2019-08-09 07:22:24 +02:00
|
|
|
if [ -z "$PATH_TO_LIGHTNING" ]; then
|
|
|
|
# Already installed maybe? Prints
|
2019-08-21 09:18:05 +02:00
|
|
|
# shellcheck disable=SC2039
|
2019-08-09 07:22:24 +02:00
|
|
|
type lightning-cli || return
|
2019-08-21 09:18:05 +02:00
|
|
|
# shellcheck disable=SC2039
|
2019-08-09 07:22:24 +02:00
|
|
|
type lightningd || return
|
|
|
|
LCLI=lightning-cli
|
|
|
|
LIGHTNINGD=lightningd
|
|
|
|
else
|
|
|
|
LCLI="$PATH_TO_LIGHTNING"/cli/lightning-cli
|
|
|
|
LIGHTNINGD="$PATH_TO_LIGHTNING"/lightningd/lightningd
|
|
|
|
# This mirrors "type" output above.
|
|
|
|
echo lightning-cli is "$LCLI"
|
|
|
|
echo lightningd is "$LIGHTNINGD"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$PATH_TO_BITCOIN" ]; then
|
|
|
|
if [ -d "$HOME/.bitcoin" ]; then
|
|
|
|
PATH_TO_BITCOIN="$HOME/.bitcoin"
|
2021-03-03 09:37:05 +01:00
|
|
|
elif [ -d "$HOME/Library/Application Support/Bitcoin/" ]; then
|
|
|
|
PATH_TO_BITCOIN="$HOME/Library/Application Support/Bitcoin/"
|
2019-08-09 07:22:24 +02:00
|
|
|
else
|
|
|
|
echo "\$PATH_TO_BITCOIN not set to a .bitcoin dir?" >&2
|
|
|
|
return
|
|
|
|
fi
|
2019-04-12 05:13:00 +02:00
|
|
|
fi
|
|
|
|
|
2020-09-09 03:18:04 +02:00
|
|
|
start_nodes() {
|
|
|
|
if [ -z "$1" ]; then
|
2020-08-28 04:01:08 +02:00
|
|
|
node_count=2
|
|
|
|
else
|
|
|
|
node_count=$1
|
|
|
|
fi
|
|
|
|
if [ "$node_count" -gt 100 ]; then
|
|
|
|
node_count=100
|
|
|
|
fi
|
2020-09-09 03:18:04 +02:00
|
|
|
if [ -z "$2" ]; then
|
|
|
|
network=regtest
|
|
|
|
else
|
|
|
|
network=$2
|
|
|
|
fi
|
2019-04-12 21:06:21 +02:00
|
|
|
|
2020-08-28 04:01:08 +02:00
|
|
|
LN_NODES=$node_count
|
|
|
|
|
|
|
|
for i in $(seq $node_count); do
|
|
|
|
socket=$(( 7070 + i * 101))
|
2020-09-09 03:18:04 +02:00
|
|
|
mkdir -p "/tmp/l$i-$network"
|
2020-08-28 04:01:08 +02:00
|
|
|
# Node config
|
2020-09-09 03:18:04 +02:00
|
|
|
cat <<- EOF > "/tmp/l$i-$network/config"
|
|
|
|
network=$network
|
2020-08-28 04:01:08 +02:00
|
|
|
log-level=debug
|
2020-09-09 03:18:04 +02:00
|
|
|
log-file=/tmp/l$i-$network/log
|
2020-08-28 04:01:08 +02:00
|
|
|
addr=localhost:$socket
|
|
|
|
EOF
|
|
|
|
|
2021-03-11 22:15:31 +01:00
|
|
|
# If we've configured to use developer, add dev options
|
|
|
|
if $LIGHTNINGD --help | grep -q dev-fast-gossip; then
|
2021-04-23 23:59:08 +02:00
|
|
|
cat <<- EOF >> "/tmp/l$i-$network/config"
|
|
|
|
dev-fast-gossip
|
|
|
|
dev-bitcoind-poll=5
|
|
|
|
experimental-dual-fund
|
|
|
|
funder-policy=match
|
2021-05-06 22:39:13 +02:00
|
|
|
funder-policy-mod=100
|
2021-04-23 23:59:08 +02:00
|
|
|
funder-min-their-funding=10000
|
|
|
|
funder-per-channel-max=100000
|
|
|
|
funder-fuzz-percent=0
|
2021-05-29 21:01:19 +02:00
|
|
|
lease-fee-base-msat=2sat
|
|
|
|
lease-fee-basis=50
|
2021-04-23 23:59:08 +02:00
|
|
|
EOF
|
2021-03-11 22:15:31 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-08-28 04:01:08 +02:00
|
|
|
# Start the lightning nodes
|
2020-09-09 03:18:04 +02:00
|
|
|
test -f "/tmp/l$i-$network/lightningd-$network.pid" || \
|
2021-07-06 20:48:35 +02:00
|
|
|
"$LIGHTNINGD" "--lightning-dir=/tmp/l$i-$network" &
|
2020-08-28 04:01:08 +02:00
|
|
|
# shellcheck disable=SC2139 disable=SC2086
|
2020-09-09 03:18:04 +02:00
|
|
|
alias l$i-cli="$LCLI --lightning-dir=/tmp/l$i-$network"
|
2020-08-28 04:01:08 +02:00
|
|
|
# shellcheck disable=SC2139 disable=SC2086
|
2020-09-09 03:18:04 +02:00
|
|
|
alias l$i-log="less /tmp/l$i-$network/log"
|
2020-08-28 04:01:08 +02:00
|
|
|
done
|
|
|
|
|
2019-08-09 07:42:32 +02:00
|
|
|
# Give a hint.
|
2020-08-28 04:01:08 +02:00
|
|
|
echo "Commands: "
|
|
|
|
for i in $(seq $node_count); do
|
|
|
|
echo " l$i-cli, l$i-log,"
|
|
|
|
done
|
2019-04-12 21:06:21 +02:00
|
|
|
}
|
|
|
|
|
2020-09-09 03:18:04 +02:00
|
|
|
start_ln() {
|
|
|
|
# Start bitcoind in the background
|
|
|
|
test -f "$PATH_TO_BITCOIN/regtest/bitcoind.pid" || \
|
|
|
|
bitcoind -regtest -txindex -fallbackfee=0.00000253 -daemon
|
|
|
|
|
|
|
|
# Wait for it to start.
|
|
|
|
while ! bitcoin-cli -regtest ping 2> /tmp/null; do echo "awaiting bitcoind..." && sleep 1; done
|
|
|
|
|
|
|
|
# Kick it out of initialblockdownload if necessary
|
|
|
|
if bitcoin-cli -regtest getblockchaininfo | grep -q 'initialblockdownload.*true'; then
|
2021-02-18 00:37:09 +01:00
|
|
|
# Modern bitcoind needs createwallet
|
2021-03-13 04:05:40 +01:00
|
|
|
bitcoin-cli -regtest createwallet default >/dev/null 2>&1
|
2020-09-09 03:18:04 +02:00
|
|
|
bitcoin-cli -regtest generatetoaddress 1 "$(bitcoin-cli -regtest getnewaddress)" > /dev/null
|
|
|
|
fi
|
|
|
|
alias bt-cli='bitcoin-cli -regtest'
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
nodes=2
|
|
|
|
else
|
|
|
|
nodes="$1"
|
|
|
|
fi
|
|
|
|
start_nodes "$nodes" regtest
|
|
|
|
echo " bt-cli, stop_ln"
|
|
|
|
}
|
|
|
|
|
|
|
|
stop_nodes() {
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
network=regtest
|
|
|
|
else
|
|
|
|
network="$2"
|
|
|
|
fi
|
|
|
|
if [ -n "$LN_NODES" ]; then
|
2020-08-28 04:01:08 +02:00
|
|
|
for i in $(seq $LN_NODES); do
|
2020-09-09 03:18:04 +02:00
|
|
|
test ! -f "/tmp/l$i-$network/lightningd-$network.pid" || \
|
|
|
|
(kill "$(cat "/tmp/l$i-$network/lightningd-$network.pid")"; \
|
|
|
|
rm "/tmp/l$i-$network/lightningd-$network.pid")
|
2020-08-28 04:01:08 +02:00
|
|
|
unalias "l$i-cli"
|
|
|
|
unalias "l$i-log"
|
|
|
|
done
|
|
|
|
fi
|
2020-09-09 03:18:04 +02:00
|
|
|
}
|
2020-08-28 04:01:08 +02:00
|
|
|
|
2020-09-09 03:18:04 +02:00
|
|
|
stop_ln() {
|
|
|
|
stop_nodes "$1" regtest
|
2019-04-12 05:13:00 +02:00
|
|
|
test ! -f "$PATH_TO_BITCOIN/regtest/bitcoind.pid" || \
|
2019-05-24 01:34:31 +02:00
|
|
|
(kill "$(cat "$PATH_TO_BITCOIN/regtest/bitcoind.pid")"; \
|
2019-04-12 05:13:00 +02:00
|
|
|
rm "$PATH_TO_BITCOIN/regtest/bitcoind.pid")
|
2019-04-12 21:06:21 +02:00
|
|
|
|
2020-08-28 04:01:08 +02:00
|
|
|
unset LN_NODES
|
2019-04-12 05:13:00 +02:00
|
|
|
unalias bt-cli
|
|
|
|
}
|
2020-09-09 03:18:04 +02:00
|
|
|
|
|
|
|
start_elem() {
|
|
|
|
if [ -z "$PATH_TO_ELEMENTS" ]; then
|
|
|
|
if [ -d "$HOME/.elements" ]; then
|
|
|
|
PATH_TO_ELEMENTS="$HOME/.elements"
|
|
|
|
else
|
|
|
|
echo "\$PATH_TO_ELEMENTS not set to a .elements dir" >&2
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
test -f "$PATH_TO_ELEMENTS/liquid-regtest/bitcoin.pid" || \
|
|
|
|
elementsd -chain=liquid-regtest -printtoconsole -logtimestamps -nolisten -validatepegin=0 -con_blocksubsidy=5000000000 -daemon
|
|
|
|
|
|
|
|
# Wait for it to start.
|
|
|
|
while ! elements-cli -chain=liquid-regtest ping 2> /tmp/null; do echo "awaiting elementsd..." && sleep 1; done
|
|
|
|
|
|
|
|
# Kick it out of initialblockdownload if necessary
|
|
|
|
if elements-cli -chain=liquid-regtest getblockchaininfo | grep -q 'initialblockdownload.*true'; then
|
|
|
|
elements-cli -chain=liquid-regtest generatetoaddress 1 "$(elements-cli -chain=liquid-regtest getnewaddress)" > /dev/null
|
|
|
|
fi
|
|
|
|
alias et-cli='elements-cli -chain=liquid-regtest'
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
nodes=2
|
|
|
|
else
|
|
|
|
nodes="$1"
|
|
|
|
fi
|
|
|
|
start_nodes "$nodes" liquid-regtest
|
|
|
|
echo " et-cli, stop_elem"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stop_elem() {
|
|
|
|
stop_nodes "$1" liquid-regtest
|
|
|
|
test ! -f "$PATH_TO_ELEMENTS/liquid-regtest/bitcoind.pid" || \
|
|
|
|
(kill "$(cat "$PATH_TO_ELEMENTS/liquid-regtest/bitcoind.pid")"; \
|
|
|
|
rm "$PATH_TO_ELEMENTS/liquid-regtest/bitcoind.pid")
|
|
|
|
|
|
|
|
unset LN_NODES
|
|
|
|
unalias et-cli
|
|
|
|
}
|