2016-03-08 00:59:15 +01:00
|
|
|
#! /bin/sh -e
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-02 08:32:56 +02:00
|
|
|
# Wherever we are, we want to be in daemon/test dir.
|
|
|
|
cd `git rev-parse --show-toplevel`/daemon/test
|
2016-01-21 21:15:27 +01:00
|
|
|
|
|
|
|
. scripts/vars.sh
|
|
|
|
|
|
|
|
scripts/setup.sh
|
|
|
|
|
2016-08-18 06:55:08 +02:00
|
|
|
# Bash variables for in-depth debugging.
|
|
|
|
#set -vx
|
|
|
|
#export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
|
|
|
|
|
2016-01-21 21:15:27 +01:00
|
|
|
DIR1=/tmp/lightning.$$.1
|
|
|
|
DIR2=/tmp/lightning.$$.2
|
2016-06-30 01:38:11 +02:00
|
|
|
DIR3=/tmp/lightning.$$.3
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-01-21 21:15:27 +01:00
|
|
|
REDIR1="$DIR1/output"
|
|
|
|
REDIR2="$DIR2/output"
|
2016-03-08 01:03:15 +01:00
|
|
|
REDIRERR1="$DIR1/errors"
|
|
|
|
REDIRERR2="$DIR2/errors"
|
2016-03-08 00:59:15 +01:00
|
|
|
FGREP="fgrep -q"
|
|
|
|
|
2016-04-12 05:37:04 +02:00
|
|
|
# We inject 0.01 bitcoin, but then fees (estimatefee fails and we use a
|
2016-08-18 06:53:46 +02:00
|
|
|
# fee rate as per the default).
|
|
|
|
AMOUNT=991880000
|
2016-03-24 02:42:43 +01:00
|
|
|
|
|
|
|
# Default fee rate per kb.
|
|
|
|
FEE_RATE=200000
|
|
|
|
|
|
|
|
# Fee in millisatoshi if we have no htlcs (note rounding to make it even)
|
|
|
|
NO_HTLCS_FEE=$((338 * $FEE_RATE / 2000 * 2000))
|
|
|
|
ONE_HTLCS_FEE=$(( (338 + 32) * $FEE_RATE / 2000 * 2000))
|
|
|
|
EXTRA_FEE=$(($ONE_HTLCS_FEE - $NO_HTLCS_FEE))
|
|
|
|
|
2016-05-17 06:19:54 +02:00
|
|
|
# Always use valgrind if available.
|
|
|
|
[ -n "$NO_VALGRIND" ] || PREFIX="valgrind -q --error-exitcode=7"
|
2016-03-08 01:04:15 +01:00
|
|
|
|
|
|
|
while [ $# != 0 ]; do
|
|
|
|
case x"$1" in
|
|
|
|
x"--valgrind-vgdb")
|
2016-05-17 06:19:54 +02:00
|
|
|
[ -n "$NO_VALGRIND" ] || PREFIX="valgrind --vgdb-error=1"
|
2016-03-08 01:04:15 +01:00
|
|
|
REDIR1="/dev/tty"
|
|
|
|
REDIRERR1="/dev/tty"
|
|
|
|
REDIR2="/dev/tty"
|
|
|
|
REDIRERR2="/dev/tty"
|
|
|
|
;;
|
|
|
|
x"--gdb1")
|
|
|
|
GDB1=1
|
|
|
|
;;
|
|
|
|
x"--gdb2")
|
|
|
|
GDB2=1
|
|
|
|
;;
|
|
|
|
x"--timeout-anchor")
|
|
|
|
TIMEOUT_ANCHOR=1
|
|
|
|
;;
|
2016-05-04 08:44:22 +02:00
|
|
|
x"--dump-onchain")
|
|
|
|
DUMP_ONCHAIN=1
|
|
|
|
;;
|
2016-05-06 04:30:30 +02:00
|
|
|
x"--steal")
|
|
|
|
STEAL=1
|
|
|
|
;;
|
2016-05-09 23:00:11 +02:00
|
|
|
x"--manual-commit")
|
|
|
|
MANUALCOMMIT=1
|
|
|
|
;;
|
2016-05-26 07:55:24 +02:00
|
|
|
x"--mutual-close-with-htlcs")
|
|
|
|
CLOSE_WITH_HTLCS=1
|
|
|
|
;;
|
2016-05-30 03:42:20 +02:00
|
|
|
x"--different-fee-rates")
|
|
|
|
DIFFERENT_FEES=1
|
|
|
|
;;
|
2016-05-06 08:52:47 +02:00
|
|
|
x"--normal")
|
|
|
|
;;
|
2016-08-18 06:55:08 +02:00
|
|
|
x"--reconnect")
|
2016-08-18 06:55:14 +02:00
|
|
|
RECONNECT=reconnect
|
|
|
|
;;
|
|
|
|
x"--restart")
|
|
|
|
RECONNECT=restart
|
2016-08-18 06:55:08 +02:00
|
|
|
;;
|
2016-05-26 07:55:25 +02:00
|
|
|
x"--crash")
|
|
|
|
CRASH_ON_FAIL=1
|
|
|
|
;;
|
2016-03-08 01:05:15 +01:00
|
|
|
x"--verbose")
|
|
|
|
VERBOSE=1
|
|
|
|
;;
|
2016-03-08 01:04:15 +01:00
|
|
|
*)
|
|
|
|
echo Unknown arg "$1" >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
2016-01-21 21:15:28 +01:00
|
|
|
shift
|
2016-03-08 01:04:15 +01:00
|
|
|
done
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-02 08:32:56 +02:00
|
|
|
LCLI1="../lightning-cli --lightning-dir=$DIR1"
|
|
|
|
LCLI2="../lightning-cli --lightning-dir=$DIR2"
|
2016-06-30 01:38:11 +02:00
|
|
|
LCLI3="../lightning-cli --lightning-dir=$DIR3"
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
FGREP="fgrep"
|
2016-08-18 06:55:14 +02:00
|
|
|
SHOW="cat >&2"
|
2016-03-08 01:05:15 +01:00
|
|
|
else
|
|
|
|
# Suppress command output.
|
|
|
|
exec >/dev/null
|
2016-08-18 06:55:14 +02:00
|
|
|
SHOW="cat"
|
2016-03-08 01:05:15 +01:00
|
|
|
fi
|
|
|
|
|
2016-08-30 12:41:57 +02:00
|
|
|
# Peer $1 -> $2's htlc $3 is in state $4
|
|
|
|
htlc_is_state()
|
|
|
|
{
|
|
|
|
if [ $# != 4 ]; then echo "htlc_is_state got $# ARGS: $@" >&2; exit 1; fi
|
|
|
|
$1 gethtlcs $2 true | tr -s '\012\011\" ' ' ' | $FGREP "id : $3, state : $4 ," >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
# Peer $1 -> $2's htlc $3 exists
|
|
|
|
htlc_exists()
|
|
|
|
{
|
|
|
|
$1 gethtlcs $2 true | tr -s '\012\011\" ' ' ' | $FGREP "id : $3," >&2
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
lcli1()
|
|
|
|
{
|
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
echo $LCLI1 "$@" >&2
|
|
|
|
fi
|
2016-08-30 12:40:57 +02:00
|
|
|
# Make sure we output if it fails; we need to capture it otherwise.
|
|
|
|
if ! OUT=`$LCLI1 "$@"`; then
|
|
|
|
echo "$OUT"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo "$OUT"
|
2016-08-18 06:55:08 +02:00
|
|
|
if [ -n "$DO_RECONNECT" ]; then
|
|
|
|
case "$1" in
|
|
|
|
# Don't restart on every get* command.
|
|
|
|
get*)
|
|
|
|
;;
|
|
|
|
dev-mocktime*)
|
|
|
|
;;
|
2016-08-18 06:55:14 +02:00
|
|
|
dev-disconnect)
|
|
|
|
;;
|
2016-08-18 06:55:08 +02:00
|
|
|
stop)
|
|
|
|
;;
|
|
|
|
*)
|
2016-08-18 06:55:14 +02:00
|
|
|
case "$RECONNECT" in
|
|
|
|
reconnect)
|
|
|
|
[ -z "$VERBOSE" ] || echo RECONNECTING >&2
|
|
|
|
$LCLI1 dev-reconnect $ID2 >/dev/null
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
[ -z "$VERBOSE" ] || echo RESTARTING >&2
|
|
|
|
$LCLI1 -- dev-restart $LIGHTNINGD1 >/dev/null 2>&1 || true
|
|
|
|
if ! check "$LCLI1 getlog 2>/dev/null | fgrep -q Hello"; then
|
|
|
|
echo "dev-restart failed!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2016-08-30 12:41:57 +02:00
|
|
|
# Wait for reconnect;
|
|
|
|
if ! check "$LCLI1 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
|
|
|
echo "Failed to reconnect!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "newhtlc" ]; then
|
|
|
|
# It might have gotten committed, or might be forgotten.
|
|
|
|
ID=`echo "$OUT" | extract_id`
|
|
|
|
if ! htlc_exists "$LCLI1" $2 $ID; then
|
|
|
|
if [ -z "$VERBOSE" ]; then
|
|
|
|
$LCLI1 "$@" >/dev/null 2>&1 || true
|
|
|
|
else
|
|
|
|
echo "Rerunning $LCLI1 $@" >&2
|
|
|
|
$LCLI1 "$@" >&2 || true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# Make sure it's confirmed before we run next command,
|
|
|
|
# in case *that* restarts (unless manual commit)
|
|
|
|
[ -n "$MANUALCOMMIT" ] || check ! htlc_is_state \'"$LCLI1"\' $2 $ID SENT_ADD_HTLC
|
|
|
|
# Removals may also be forgotten.
|
|
|
|
elif [ "$1" = "fulfillhtlc" -o "$1" = "failhtlc" ]; then
|
|
|
|
ID="$3"
|
|
|
|
if htlc_is_state "$LCLI1" $2 $ID RCVD_ADD_ACK_REVOCATION; then
|
|
|
|
if [ -z "$VERBOSE" ]; then
|
|
|
|
$LCLI1 "$@" >/dev/null 2>&1 || true
|
|
|
|
else
|
|
|
|
echo "Rerunning $LCLI1 $@" >&2
|
|
|
|
$LCLI1 "$@" >&2 || true
|
|
|
|
fi
|
|
|
|
# Make sure it's confirmed before we run next command,
|
|
|
|
# in case *that* restarts.
|
|
|
|
[ -n "$MANUALCOMMIT" ] || check ! htlc_is_state \'"$LCLI1"\' $2 $ID SENT_REMOVE_HTLC
|
|
|
|
fi
|
|
|
|
fi
|
2016-08-18 06:55:08 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2016-03-08 01:05:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lcli2()
|
|
|
|
{
|
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
echo $LCLI2 "$@" >&2
|
|
|
|
fi
|
|
|
|
$LCLI2 "$@"
|
|
|
|
}
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
lcli3()
|
|
|
|
{
|
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
echo $LCLI3 "$@" >&2
|
|
|
|
fi
|
|
|
|
$LCLI3 "$@"
|
|
|
|
}
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
blockheight()
|
|
|
|
{
|
|
|
|
$CLI getblockcount
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Usage: <cmd to test>...
|
2016-05-05 06:53:36 +02:00
|
|
|
check()
|
|
|
|
{
|
|
|
|
local i=0
|
|
|
|
while ! eval "$@"; do
|
2016-05-09 23:00:11 +02:00
|
|
|
# Try making time pass for the nodes (if on mocktime), then sleeping.
|
2016-05-05 06:53:36 +02:00
|
|
|
if [ -n "$MOCKTIME" ]; then
|
|
|
|
MOCKTIME=$(($MOCKTIME + 1))
|
2016-05-26 07:55:25 +02:00
|
|
|
lcli1 dev-mocktime $MOCKTIME
|
|
|
|
lcli2 dev-mocktime $MOCKTIME
|
2016-05-05 06:53:36 +02:00
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
i=$(($i + 1))
|
|
|
|
if [ $i = 20 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
check_balance_single()
|
|
|
|
{
|
|
|
|
lcli="$1"
|
|
|
|
us_pay=$2
|
|
|
|
us_fee=$3
|
|
|
|
them_pay=$4
|
|
|
|
them_fee=$5
|
|
|
|
|
|
|
|
if check "$lcli getpeers | tr -s '\012\011\" ' ' ' | $FGREP \"our_amount : $us_pay, our_fee : $us_fee, their_amount : $them_pay, their_fee : $them_fee,\""; then :; else
|
|
|
|
echo Cannot find $lcli output: "our_amount : $us_pay, our_fee : $us_fee, their_amount : $them_pay, their_fee : $them_fee," >&2
|
|
|
|
$lcli getpeers | tr -s '\012\011" ' ' ' >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:04:15 +01:00
|
|
|
check_status_single()
|
|
|
|
{
|
2016-03-08 01:05:15 +01:00
|
|
|
lcli="$1"
|
2016-03-08 01:04:15 +01:00
|
|
|
us_pay=$2
|
|
|
|
us_fee=$3
|
|
|
|
us_htlcs="$4"
|
|
|
|
them_pay=$5
|
|
|
|
them_fee=$6
|
|
|
|
them_htlcs="$7"
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
check_balance_single "$lcli" $us_pay $us_fee $them_pay $them_fee
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
if check "$lcli getpeers | tr -s '\012\011\" ' ' ' | $FGREP \"our_htlcs : [ $us_htlcs], their_htlcs : [ $them_htlcs]\""; then :; else
|
2016-08-18 06:53:45 +02:00
|
|
|
echo Cannot find $lcli output: "our_htlcs : [ $us_htlcs], their_htlcs : [ $them_htlcs]" >&2
|
|
|
|
$lcli getpeers | tr -s '\012\011" ' ' ' >&2
|
2016-03-08 01:04:15 +01:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
# SEND_ -> RCVD_ and RCVD_ -> SEND_
|
|
|
|
swap_status()
|
|
|
|
{
|
|
|
|
echo "$@" | sed -e 's/state : RCVD_/@@/g' -e 's/state : SENT_/state : RCVD_/g' -e 's/@@/state : SENT_/g'
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
check_status()
|
|
|
|
{
|
|
|
|
us_pay=$1
|
|
|
|
us_fee=$2
|
|
|
|
us_htlcs="$3"
|
|
|
|
them_pay=$4
|
|
|
|
them_fee=$5
|
|
|
|
them_htlcs="$6"
|
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
check_status_single lcli1 "$us_pay" "$us_fee" "$us_htlcs" "$them_pay" "$them_fee" "$them_htlcs"
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status_single lcli2 "$them_pay" "$them_fee" "`swap_status \"$them_htlcs\"`" "$us_pay" "$us_fee" "`swap_status \"$us_htlcs\"`"
|
2016-03-31 08:43:20 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
check_tx_spend()
|
|
|
|
{
|
2016-05-09 23:00:11 +02:00
|
|
|
if check "$CLI getrawmempool | $FGREP '\"'"; then :;
|
2016-01-21 21:15:28 +01:00
|
|
|
else
|
2016-05-05 06:53:36 +02:00
|
|
|
echo "No tx in mempool:" >&2
|
|
|
|
$CLI getrawmempool >&2
|
2016-01-21 21:15:28 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:04:13 +02:00
|
|
|
check_peerstate()
|
|
|
|
{
|
2016-05-09 23:00:11 +02:00
|
|
|
if check "$1 getpeers | $FGREP -w $2"; then :
|
2016-04-24 12:04:13 +02:00
|
|
|
else
|
|
|
|
echo "$1" not in state "$2": >&2
|
|
|
|
$1 getpeers >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-05-04 08:44:22 +02:00
|
|
|
check_peerconnected()
|
|
|
|
{
|
2016-05-09 23:00:11 +02:00
|
|
|
if check "$1 getpeers | tr -s '\012\011\" ' ' ' | $FGREP -w 'connected : '$2"; then :
|
2016-05-04 08:44:22 +02:00
|
|
|
else
|
|
|
|
echo "$1" not connected "$2": >&2
|
|
|
|
$1 getpeers >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-04-24 12:04:13 +02:00
|
|
|
check_no_peers()
|
|
|
|
{
|
2016-05-09 23:00:11 +02:00
|
|
|
if check "$1 getpeers | tr -s '\012\011\" ' ' ' | $FGREP 'peers : [ ]'"; then :
|
2016-04-24 12:04:13 +02:00
|
|
|
else
|
|
|
|
echo "$1" still has peers: >&2
|
|
|
|
$1 getpeers >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2016-08-18 06:53:46 +02:00
|
|
|
|
|
|
|
extract_id()
|
|
|
|
{
|
|
|
|
XID=`tr -s '\012\011\" ' ' ' | sed -n 's/{ id : \([0-9]*\) }/\1/p'`
|
|
|
|
case "$XID" in
|
|
|
|
[0-9]*)
|
|
|
|
echo $XID;;
|
|
|
|
*)
|
|
|
|
return 1;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
all_ok()
|
|
|
|
{
|
2016-03-08 01:03:15 +01:00
|
|
|
# Look for valgrind errors.
|
|
|
|
if grep ^== $DIR1/errors; then exit 1; fi
|
|
|
|
if grep ^== $DIR2/errors; then exit 1; fi
|
2016-06-30 01:38:11 +02:00
|
|
|
if grep ^== $DIR3/errors; then exit 1; fi
|
2016-01-21 21:15:28 +01:00
|
|
|
scripts/shutdown.sh
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
trap "rm -rf $DIR1 $DIR2 $DIR3" EXIT
|
2016-01-21 21:15:28 +01:00
|
|
|
exit 0
|
|
|
|
}
|
2016-03-08 01:03:15 +01:00
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
if [ -n "$CRASH_ON_FAIL" ]; then
|
|
|
|
trap "$LCLI1 dev-crash 2>/dev/null || true; $LCLI2 dev-crash 2>/dev/null || true; echo Crash results in $DIR1 and $DIR2 >&2; cat $DIR1/errors $DIR2/errors >&2" EXIT
|
|
|
|
else
|
|
|
|
trap "echo Results in $DIR1 and $DIR2 >&2; cat $DIR1/errors $DIR2/errors >&2" EXIT
|
|
|
|
fi
|
2016-06-30 01:38:11 +02:00
|
|
|
mkdir $DIR1 $DIR2 $DIR3
|
2016-05-02 08:33:56 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
if [ -n "$MANUALCOMMIT" ]; then
|
|
|
|
# Aka. never.
|
|
|
|
COMMIT_TIME=1h
|
|
|
|
else
|
|
|
|
COMMIT_TIME=10ms
|
|
|
|
fi
|
|
|
|
|
2016-05-02 08:33:56 +02:00
|
|
|
cat > $DIR1/config <<EOF
|
|
|
|
log-level=debug
|
2016-05-09 22:59:12 +02:00
|
|
|
bitcoind-poll=1s
|
2016-07-01 03:49:28 +02:00
|
|
|
deadline-blocks=5
|
2016-06-28 23:19:21 +02:00
|
|
|
min-htlc-expiry=6
|
2016-05-02 08:33:56 +02:00
|
|
|
bitcoin-datadir=$DATADIR
|
2016-06-28 23:19:21 +02:00
|
|
|
locktime-blocks=6
|
2016-05-09 23:00:11 +02:00
|
|
|
commit-time=$COMMIT_TIME
|
2016-05-02 08:33:56 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > $DIR2/config <<EOF
|
|
|
|
log-level=debug
|
2016-05-09 22:59:12 +02:00
|
|
|
bitcoind-poll=1s
|
2016-07-01 03:49:28 +02:00
|
|
|
deadline-blocks=5
|
2016-06-28 23:19:21 +02:00
|
|
|
min-htlc-expiry=6
|
2016-05-02 08:33:56 +02:00
|
|
|
bitcoin-datadir=$DATADIR
|
2016-06-28 23:19:21 +02:00
|
|
|
locktime-blocks=6
|
2016-05-09 23:00:11 +02:00
|
|
|
commit-time=$COMMIT_TIME
|
2016-05-02 08:33:56 +02:00
|
|
|
EOF
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
cp $DIR2/config $DIR3/config
|
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
if [ x"$RECONNECT" = xrestart ]; then
|
2016-09-06 06:17:33 +02:00
|
|
|
# Make sure node2 & 3 restart on same port, by setting in config.
|
2016-08-18 06:55:14 +02:00
|
|
|
# Find a free TCP port.
|
2016-08-26 08:14:04 +02:00
|
|
|
echo port=`findport 4000` >> $DIR2/config
|
2016-09-06 06:17:33 +02:00
|
|
|
echo port=`findport 4010` >> $DIR3/config
|
2016-08-18 06:55:14 +02:00
|
|
|
fi
|
|
|
|
|
2016-05-30 03:42:20 +02:00
|
|
|
if [ -n "$DIFFERENT_FEES" ]; then
|
2016-08-18 06:53:46 +02:00
|
|
|
# Simply override default fee (estimatefee fails on regtest anyway)
|
2016-08-26 08:03:47 +02:00
|
|
|
DEFAULT_FEE_RATE2=50000
|
2016-08-18 06:53:46 +02:00
|
|
|
# We use 5x fee rate for commits, by defailt.
|
2016-08-26 08:03:47 +02:00
|
|
|
FEE_RATE2=$(($DEFAULT_FEE_RATE2 * 5))
|
|
|
|
echo "default-fee-rate=$DEFAULT_FEE_RATE2" >> $DIR2/config
|
2016-05-30 03:42:20 +02:00
|
|
|
fi
|
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
# Need absolute path for re-exec testing.
|
|
|
|
LIGHTNINGD1="$(readlink -f `pwd`/../lightningd) --lightning-dir=$DIR1"
|
2016-03-08 01:04:15 +01:00
|
|
|
if [ -n "$GDB1" ]; then
|
2016-08-18 06:55:14 +02:00
|
|
|
echo Press return once you run: gdb --args $LIGHTNINGD1 >&2
|
|
|
|
|
2016-03-08 01:04:15 +01:00
|
|
|
read REPLY
|
|
|
|
else
|
2016-08-18 06:55:14 +02:00
|
|
|
LIGHTNINGD1="$PREFIX $LIGHTNINGD1"
|
|
|
|
$LIGHTNINGD1 > $REDIR1 2> $REDIRERR1 &
|
2016-03-08 01:04:15 +01:00
|
|
|
fi
|
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
LIGHTNINGD2="$(readlink -f `pwd`/../lightningd) --lightning-dir=$DIR2"
|
2016-03-08 01:04:15 +01:00
|
|
|
if [ -n "$GDB2" ]; then
|
2016-08-18 06:55:14 +02:00
|
|
|
echo Press return once you run: gdb --args $LIGHTNINGD2 >&2
|
2016-03-08 01:04:15 +01:00
|
|
|
read REPLY
|
|
|
|
else
|
2016-08-18 06:55:14 +02:00
|
|
|
LIGHTNINGD2="$PREFIX $LIGHTNINGD2"
|
|
|
|
$LIGHTNINGD2 > $REDIR2 2> $REDIRERR2 &
|
2016-03-08 01:04:15 +01:00
|
|
|
fi
|
2016-09-06 06:17:33 +02:00
|
|
|
LIGHTNINGD3="$PREFIX $(readlink -f `pwd`/../lightningd) --lightning-dir=$DIR3"
|
|
|
|
$LIGHTNINGD3 > $DIR3/output 2> $DIR3/errors &
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
if ! check "$LCLI1 getlog 2>/dev/null | $FGREP Hello"; then
|
2016-05-05 06:53:36 +02:00
|
|
|
echo Failed to start daemon 1 >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
if ! check "$LCLI2 getlog 2>/dev/null | $FGREP Hello"; then
|
2016-05-05 06:53:36 +02:00
|
|
|
echo Failed to start daemon 2 >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
if ! check "$LCLI3 getlog 2>/dev/null | $FGREP Hello"; then
|
|
|
|
echo Failed to start daemon 3 >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-01-21 21:15:27 +01:00
|
|
|
ID1=`$LCLI1 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'`
|
|
|
|
ID2=`$LCLI2 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'`
|
2016-06-30 01:38:11 +02:00
|
|
|
ID3=`$LCLI3 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'`
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-01-21 21:15:27 +01:00
|
|
|
PORT2=`$LCLI2 getlog | sed -n 's/.*on port \([0-9]*\).*/\1/p'`
|
2016-06-30 01:38:11 +02:00
|
|
|
PORT3=`$LCLI3 getlog | sed -n 's/.*on port \([0-9]*\).*/\1/p'`
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-04-12 05:37:04 +02:00
|
|
|
# Make a payment into a P2SH for anchor.
|
|
|
|
P2SHADDR=`$LCLI1 newaddr | sed -n 's/{ "address" : "\(.*\)" }/\1/p'`
|
|
|
|
TXID=`$CLI sendtoaddress $P2SHADDR 0.01`
|
|
|
|
TX=`$CLI getrawtransaction $TXID`
|
2016-05-05 06:53:36 +02:00
|
|
|
$CLI generate 1
|
2016-04-12 05:37:04 +02:00
|
|
|
|
|
|
|
lcli1 connect localhost $PORT2 $TX
|
2016-01-21 21:15:27 +01:00
|
|
|
|
|
|
|
# Expect them to be waiting for anchor.
|
2016-04-24 12:04:13 +02:00
|
|
|
check_peerstate lcli1 STATE_OPEN_WAITING_OURANCHOR
|
|
|
|
check_peerstate lcli2 STATE_OPEN_WAITING_THEIRANCHOR
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-08-18 06:55:08 +02:00
|
|
|
DO_RECONNECT=$RECONNECT
|
|
|
|
|
2016-03-08 01:04:15 +01:00
|
|
|
if [ -n "$TIMEOUT_ANCHOR" ]; then
|
2016-05-05 06:53:36 +02:00
|
|
|
# Check anchor emitted, not mined deep enough.
|
|
|
|
check_tx_spend lcli1
|
|
|
|
$CLI generate 2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
# Timeout before anchor committed.
|
|
|
|
MOCKTIME=$((`date +%s` + 7200 + 3 * 1200 + 1))
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
lcli1 dev-mocktime $MOCKTIME
|
2016-05-26 07:55:25 +02:00
|
|
|
lcli2 dev-mocktime $MOCKTIME
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
# Node2 should have gone via STATE_ERR_ANCHOR_TIMEOUT, then closed.
|
|
|
|
lcli2 getlog | grep STATE_ERR_ANCHOR_TIMEOUT
|
|
|
|
check_no_peers lcli2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
# Node1 should be disconnected.
|
2016-05-04 08:44:22 +02:00
|
|
|
check_peerconnected lcli1 false
|
2016-05-05 06:53:36 +02:00
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
# Node1 should send out commit tx; mine it.
|
2016-05-05 06:53:36 +02:00
|
|
|
check_tx_spend lcli1
|
|
|
|
$CLI generate 1
|
2016-05-04 08:44:22 +02:00
|
|
|
|
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
# Now "wait" for 1 day, which is what node2 asked for on commit.
|
2016-05-05 06:53:36 +02:00
|
|
|
MOCKTIME=$(($MOCKTIME + 24 * 60 * 60 - 1))
|
|
|
|
lcli1 dev-mocktime $MOCKTIME
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-04-11 09:04:29 +02:00
|
|
|
# Move bitcoind median time as well, so CSV moves.
|
2016-05-05 06:53:36 +02:00
|
|
|
$CLI setmocktime $MOCKTIME
|
2016-04-11 09:04:29 +02:00
|
|
|
$CLI generate 6
|
2016-05-05 06:53:36 +02:00
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
# Now it should have spent the commit tx.
|
2016-05-05 06:53:36 +02:00
|
|
|
check_tx_spend lcli1
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
# 100 blocks pass...
|
|
|
|
$CLI generate 100
|
|
|
|
MOCKTIME=$(($MOCKTIME + 1))
|
|
|
|
lcli1 dev-mocktime $MOCKTIME
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Considers it all done now.
|
2016-04-24 12:04:13 +02:00
|
|
|
check_no_peers lcli1
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
lcli1 stop
|
2016-05-26 07:55:25 +02:00
|
|
|
lcli2 stop
|
2016-01-21 21:15:28 +01:00
|
|
|
all_ok
|
|
|
|
fi
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
# Now make it pass anchor (should be in mempool: three blocks bury it)
|
|
|
|
check_tx_spend lcli1
|
|
|
|
$CLI generate 3
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-04-24 12:04:13 +02:00
|
|
|
check_peerstate lcli1 STATE_NORMAL
|
|
|
|
check_peerstate lcli2 STATE_NORMAL
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-06-30 01:38:10 +02:00
|
|
|
# We turn off routing failure for the moment.
|
|
|
|
lcli1 dev-routefail false
|
|
|
|
lcli2 dev-routefail false
|
|
|
|
|
2016-05-30 03:42:20 +02:00
|
|
|
if [ -n "$DIFFERENT_FEES" ]; then
|
|
|
|
# This is 100,000 satoshi, so covers fees.
|
|
|
|
HTLC_AMOUNT=100000000
|
|
|
|
|
|
|
|
# Asymmetry, since fee rates different.
|
|
|
|
NO_HTLCS_FEE2=$((338 * $FEE_RATE2 / 2000 * 2000))
|
|
|
|
ONE_HTLCS_FEE2=$(( (338 + 32) * $FEE_RATE2 / 2000 * 2000))
|
|
|
|
|
|
|
|
A_AMOUNT1=$(($AMOUNT - $NO_HTLCS_FEE))
|
|
|
|
A_FEE1=$NO_HTLCS_FEE
|
|
|
|
A_AMOUNT2=$(($AMOUNT - $NO_HTLCS_FEE2))
|
|
|
|
A_FEE2=$NO_HTLCS_FEE2
|
|
|
|
B_AMOUNT=0
|
|
|
|
B_FEE=0
|
|
|
|
|
|
|
|
check_status_single lcli1 $A_AMOUNT1 $A_FEE1 "" $B_AMOUNT $B_FEE ""
|
|
|
|
check_status_single lcli2 $B_AMOUNT $B_FEE "" $(($A_AMOUNT2)) $(($A_FEE2)) ""
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
EXPIRY=$(( $(blockheight) + 10))
|
2016-05-30 03:42:20 +02:00
|
|
|
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd
|
|
|
|
RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-05-30 03:42:20 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status_single lcli2 0 0 "" $(($AMOUNT - $HTLC_AMOUNT - $ONE_HTLCS_FEE2)) $(($ONE_HTLCS_FEE2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } "
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
|
2016-05-30 03:42:20 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
check_status_single lcli1 $(($AMOUNT - $HTLC_AMOUNT - $NO_HTLCS_FEE / 2)) $(($NO_HTLCS_FEE / 2)) "" $(($HTLC_AMOUNT - $NO_HTLCS_FEE / 2)) $(($NO_HTLCS_FEE / 2)) ""
|
|
|
|
check_status_single lcli2 $(($HTLC_AMOUNT - $NO_HTLCS_FEE2 / 2)) $(($NO_HTLCS_FEE2 / 2)) "" $(($AMOUNT - $HTLC_AMOUNT - $NO_HTLCS_FEE2 / 2)) $(($NO_HTLCS_FEE2 / 2)) ""
|
|
|
|
|
2016-08-26 08:03:47 +02:00
|
|
|
# Change fee rate on node2 to same as node1.
|
|
|
|
lcli2 dev-feerate 40000
|
|
|
|
$CLI generate 1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
check_status $(($AMOUNT - $HTLC_AMOUNT - $NO_HTLCS_FEE / 2)) $(($NO_HTLCS_FEE / 2)) "" $(($HTLC_AMOUNT - $NO_HTLCS_FEE / 2)) $(($NO_HTLCS_FEE / 2)) ""
|
|
|
|
|
2016-05-30 03:42:20 +02:00
|
|
|
lcli1 close $ID2
|
|
|
|
# Make sure they notice it.
|
|
|
|
check_peerstate lcli1 STATE_MUTUAL_CLOSING
|
|
|
|
check_peerstate lcli2 STATE_MUTUAL_CLOSING
|
|
|
|
$CLI generate 1
|
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
# Give it 100 blocks.
|
|
|
|
$CLI generate 100
|
|
|
|
check_no_peers lcli1
|
|
|
|
check_no_peers lcli2
|
|
|
|
|
|
|
|
lcli1 stop
|
|
|
|
lcli2 stop
|
|
|
|
|
|
|
|
all_ok
|
|
|
|
fi
|
|
|
|
|
2016-03-24 02:42:43 +01:00
|
|
|
A_AMOUNT=$(($AMOUNT - $NO_HTLCS_FEE))
|
|
|
|
A_FEE=$NO_HTLCS_FEE
|
|
|
|
B_AMOUNT=0
|
|
|
|
B_FEE=0
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
# This is 10,000 satoshi, so not dust!
|
2016-05-02 08:37:56 +02:00
|
|
|
HTLC_AMOUNT=10000000
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
EXPIRY=$(( $(blockheight) + 10))
|
2016-01-21 21:15:27 +01:00
|
|
|
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd
|
2016-03-08 01:05:15 +01:00
|
|
|
RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
2016-06-28 23:19:20 +02:00
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
if [ -n "$MANUALCOMMIT" ]; then
|
2016-08-18 06:53:45 +02:00
|
|
|
# They should register a staged htlc.
|
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_HTLC } " $B_AMOUNT $B_FEE ""
|
2016-03-31 08:43:20 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Now commit it.
|
|
|
|
lcli1 commit $ID2
|
2016-03-31 08:43:20 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Node 1 hasn't got it committed, but node2 should have told it to stage.
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status_single lcli1 $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-03-31 08:43:20 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Check channel status
|
|
|
|
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
|
|
|
|
A_FEE=$(($A_FEE + $EXTRA_FEE))
|
2016-03-31 08:43:20 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Node 2 has it committed.
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status_single lcli2 $B_AMOUNT $B_FEE "" $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } "
|
2016-05-09 23:00:11 +02:00
|
|
|
|
2016-06-28 23:19:20 +02:00
|
|
|
# There should be no "both committed" here yet
|
|
|
|
if lcli1 getlog debug | $FGREP "Both committed"; then
|
|
|
|
echo "Node1 thinks they are both committed";
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if lcli2 getlog debug | $FGREP "Both committed"; then
|
|
|
|
echo "Node2 thinks they are both committed";
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Now node2 gives commitment to node1.
|
|
|
|
lcli2 commit $ID1
|
2016-06-28 23:19:20 +02:00
|
|
|
|
|
|
|
# After revocation, they should know they're both committed.
|
|
|
|
check lcli1 "getlog debug | $FGREP 'Both committed to ADD of our HTLC'"
|
|
|
|
check lcli2 "getlog debug | $FGREP 'Both committed to ADD of their HTLC'"
|
2016-05-09 23:00:11 +02:00
|
|
|
else
|
|
|
|
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
|
|
|
|
A_FEE=$(($A_FEE + $EXTRA_FEE))
|
|
|
|
fi
|
2016-03-31 08:43:20 +02:00
|
|
|
|
2016-05-09 23:00:11 +02:00
|
|
|
# Both should have committed tx.
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-06 04:30:30 +02:00
|
|
|
if [ -n "$STEAL" ]; then
|
|
|
|
STEAL_TX=`$LCLI1 dev-signcommit $ID2 | cut -d\" -f4`
|
|
|
|
fi
|
|
|
|
|
2016-05-04 08:44:22 +02:00
|
|
|
if [ -n "$DUMP_ONCHAIN" ]; then
|
|
|
|
# make node1 disconnect with node2.
|
|
|
|
lcli1 dev-disconnect $ID2
|
|
|
|
check_peerconnected lcli1 false
|
|
|
|
|
|
|
|
# lcli1 should have sent out commitment tx
|
2016-05-05 06:53:36 +02:00
|
|
|
check_peerstate lcli1 STATE_ERR_BREAKDOWN
|
|
|
|
check_tx_spend lcli1
|
2016-05-04 08:44:22 +02:00
|
|
|
|
2016-05-05 06:53:36 +02:00
|
|
|
# Mine it.
|
|
|
|
$CLI generate 1
|
2016-05-04 08:44:22 +02:00
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_THEIR_UNILATERAL
|
|
|
|
|
|
|
|
# both still know about htlc
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-05-04 08:44:22 +02:00
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
# Generate 6 blocks so CSV timeout has expired.
|
2016-05-04 08:44:22 +02:00
|
|
|
$CLI generate 6
|
|
|
|
|
|
|
|
# Now, lcli1 should spend its own output.
|
2016-05-05 06:53:36 +02:00
|
|
|
check_tx_spend lcli1
|
2016-05-04 08:44:22 +02:00
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
|
|
|
|
2016-06-28 23:19:21 +02:00
|
|
|
while [ $(blockheight) != $EXPIRY ]; do
|
|
|
|
$CLI generate 1
|
|
|
|
done
|
2016-05-04 08:44:22 +02:00
|
|
|
|
|
|
|
# lcli1 should have gotten HTLC back.
|
2016-05-05 06:53:36 +02:00
|
|
|
check_tx_spend lcli1
|
2016-05-04 08:44:22 +02:00
|
|
|
|
|
|
|
# Now, after 100 blocks, should all be concluded.
|
|
|
|
$CLI generate 100
|
|
|
|
|
|
|
|
# Both consider it all done now.
|
|
|
|
check_no_peers lcli1
|
|
|
|
|
|
|
|
lcli1 stop
|
|
|
|
all_ok
|
|
|
|
fi
|
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
|
2016-05-09 23:00:11 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
2016-06-28 23:19:20 +02:00
|
|
|
|
|
|
|
# Without manual commit, this check is racy.
|
|
|
|
if [ -n "$MANUALCOMMIT" ]; then
|
|
|
|
if lcli1 getlog debug | $FGREP 'Both committed to FULFILL'; then
|
|
|
|
echo "Node1 thinks they are both committed";
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if lcli2 getlog debug | $FGREP 'Both committed to FULFILL'; then
|
|
|
|
echo "Node2 thinks they are both committed";
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2016-05-09 23:00:11 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-06-28 23:19:20 +02:00
|
|
|
check lcli1 "getlog debug | $FGREP 'Both committed to FULFILL of our HTLC'"
|
|
|
|
check lcli2 "getlog debug | $FGREP 'Both committed to FULFILL of their HTLC'"
|
|
|
|
|
2016-03-24 02:42:43 +01:00
|
|
|
# We've transferred the HTLC amount to 2, who now has to pay fees,
|
|
|
|
# so no net change for A who saves on fees.
|
2016-05-02 08:37:56 +02:00
|
|
|
B_FEE=$HTLC_AMOUNT
|
2016-03-24 02:42:43 +01:00
|
|
|
# With no HTLCs, extra fee no longer required.
|
|
|
|
A_FEE=$(($A_FEE - $EXTRA_FEE - $B_FEE))
|
2016-05-02 08:37:56 +02:00
|
|
|
A_AMOUNT=$(($A_AMOUNT + $EXTRA_FEE + $HTLC_AMOUNT))
|
2016-03-24 02:42:43 +01:00
|
|
|
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
# A new one, at 10x the amount.
|
2016-05-02 08:37:56 +02:00
|
|
|
HTLC_AMOUNT=100000000
|
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-05-09 23:00:11 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Check channel status
|
2016-05-02 08:37:56 +02:00
|
|
|
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
|
2016-03-24 02:42:43 +01:00
|
|
|
A_FEE=$(($A_FEE + $EXTRA_FEE))
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-08-31 07:21:41 +02:00
|
|
|
lcli2 failhtlc $ID1 $HTLCID 695
|
2016-05-09 23:00:11 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Back to how we were before.
|
2016-05-02 08:37:56 +02:00
|
|
|
A_AMOUNT=$(($A_AMOUNT + $EXTRA_FEE + $HTLC_AMOUNT))
|
2016-03-24 02:42:43 +01:00
|
|
|
A_FEE=$(($A_FEE - $EXTRA_FEE))
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
# Same again, but this time it expires.
|
2016-05-02 08:37:56 +02:00
|
|
|
HTLC_AMOUNT=10000001
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-05-09 23:00:11 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Check channel status
|
2016-05-02 08:37:56 +02:00
|
|
|
A_AMOUNT=$(($A_AMOUNT - $EXTRA_FEE - $HTLC_AMOUNT))
|
2016-03-24 02:42:43 +01:00
|
|
|
A_FEE=$(($A_FEE + $EXTRA_FEE))
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Make sure node1 accepts the expiry packet.
|
2016-06-28 23:19:21 +02:00
|
|
|
while [ $(blockheight) != $EXPIRY ]; do
|
|
|
|
$CLI generate 1
|
|
|
|
done
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# This should make node2 send it.
|
2016-06-28 23:19:21 +02:00
|
|
|
$CLI generate 1
|
|
|
|
|
|
|
|
if [ -n "$MANUALCOMMIT" ]; then
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_REMOVE_HTLC } " $B_AMOUNT $B_FEE ""
|
2016-06-28 23:19:21 +02:00
|
|
|
|
|
|
|
lcli2 commit $ID1
|
|
|
|
lcli1 commit $ID2
|
|
|
|
fi
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Back to how we were before.
|
2016-05-02 08:37:56 +02:00
|
|
|
A_AMOUNT=$(($A_AMOUNT + $EXTRA_FEE + $HTLC_AMOUNT))
|
2016-03-24 02:42:43 +01:00
|
|
|
A_FEE=$(($A_FEE - $EXTRA_FEE))
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-06 04:30:30 +02:00
|
|
|
if [ -n "$STEAL" ]; then
|
|
|
|
# Send out old commit tx from peer 1.
|
|
|
|
$CLI sendrawtransaction $STEAL_TX
|
|
|
|
$CLI generate 1
|
|
|
|
|
|
|
|
# Node1 should get really upset; node2 should steal the transaction.
|
|
|
|
check_peerstate lcli1 STATE_ERR_INFORMATION_LEAK
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_CHEATED
|
2016-05-06 08:26:47 +02:00
|
|
|
check_tx_spend lcli2
|
2016-05-06 04:30:30 +02:00
|
|
|
|
|
|
|
# Give it 100 blocks.
|
|
|
|
$CLI generate 100
|
|
|
|
|
|
|
|
check_no_peers lcli2
|
|
|
|
|
|
|
|
lcli1 stop
|
|
|
|
lcli2 stop
|
|
|
|
|
|
|
|
all_ok
|
|
|
|
fi
|
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
# First, give more money to node2, so it can offer HTLCs.
|
2016-06-28 23:19:21 +02:00
|
|
|
EXPIRY=$(( $(blockheight) + 10))
|
2016-05-26 07:55:24 +02:00
|
|
|
HTLC_AMOUNT=100000000
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-05-26 07:55:24 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $B_AMOUNT $B_FEE ""
|
2016-05-26 07:55:24 +02:00
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
|
2016-05-26 07:55:24 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
# Both now pay equal fees.
|
|
|
|
A_FEE=$(($NO_HTLCS_FEE / 2))
|
|
|
|
B_FEE=$(($NO_HTLCS_FEE / 2))
|
|
|
|
# We transferred 10000000 before, and $HTLC_AMOUNT now.
|
|
|
|
A_AMOUNT=$(($AMOUNT - 10000000 - $HTLC_AMOUNT - $A_FEE))
|
|
|
|
B_AMOUNT=$((10000000 + $HTLC_AMOUNT - $B_FEE))
|
|
|
|
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
2016-08-31 07:21:44 +02:00
|
|
|
# Two failures crossover
|
|
|
|
SECRET2=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfe
|
|
|
|
RHASH2=`lcli1 dev-rhash $SECRET2 | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
|
2016-08-31 08:36:32 +02:00
|
|
|
# This means B will *just* afford it (but can't cover increased fees)
|
|
|
|
HTLC_AMOUNT=$(($B_AMOUNT - $EXTRA_FEE / 2))
|
2016-08-31 07:21:44 +02:00
|
|
|
HTLCID=`lcli2 newhtlc $ID1 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-08-31 08:36:32 +02:00
|
|
|
# Make sure that's committed, in case lcli1 restarts.
|
|
|
|
lcli2 commit $ID1 >/dev/null || true
|
2016-08-31 07:21:44 +02:00
|
|
|
|
2016-08-31 08:36:32 +02:00
|
|
|
HTLCID2=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
|
2016-08-31 07:21:44 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
2016-08-31 08:36:32 +02:00
|
|
|
# A covers the extra part of the fee.
|
|
|
|
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE - $EXTRA_FEE / 2)) $(($A_FEE + $EXTRA_FEE + $EXTRA_FEE / 2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } " 0 $(($B_FEE + $EXTRA_FEE / 2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } "
|
2016-08-31 07:21:44 +02:00
|
|
|
|
|
|
|
# Fail both, to reset.
|
|
|
|
lcli1 failhtlc $ID2 $HTLCID 830
|
|
|
|
lcli2 failhtlc $ID1 $HTLCID2 829
|
|
|
|
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
# Now, two HTLCs at once, one from each direction.
|
|
|
|
# Both sides can afford this.
|
|
|
|
HTLC_AMOUNT=1000000
|
2016-08-30 12:41:57 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID2=`lcli2 newhtlc $ID1 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
|
2016-05-26 07:55:24 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
2016-08-30 12:41:57 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
2016-05-26 07:55:24 +02:00
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
check_status $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } " $(($B_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } "
|
2016-05-26 07:55:24 +02:00
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
if [ -n "$CLOSE_WITH_HTLCS" ]; then
|
|
|
|
# Now begin close
|
|
|
|
lcli1 close $ID2
|
|
|
|
|
|
|
|
# They should be waiting for it to clear up.
|
2016-08-18 06:53:46 +02:00
|
|
|
check_peerstate lcli1 STATE_SHUTDOWN
|
|
|
|
check_peerstate lcli2 STATE_SHUTDOWN
|
2016-05-26 07:55:24 +02:00
|
|
|
|
|
|
|
# Fail one, still waiting.
|
2016-08-31 07:21:41 +02:00
|
|
|
lcli2 failhtlc $ID1 $HTLCID 800
|
2016-08-18 06:53:46 +02:00
|
|
|
check_peerstate lcli1 STATE_SHUTDOWN
|
|
|
|
check_peerstate lcli2 STATE_SHUTDOWN
|
2016-05-26 07:55:24 +02:00
|
|
|
|
|
|
|
# Fulfill the other causes them to actually complete the close.
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli1 fulfillhtlc $ID2 $HTLCID2 $SECRET2
|
2016-05-26 07:55:24 +02:00
|
|
|
check_peerstate lcli1 STATE_MUTUAL_CLOSING
|
|
|
|
check_peerstate lcli2 STATE_MUTUAL_CLOSING
|
|
|
|
|
|
|
|
$CLI generate 1
|
|
|
|
|
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
|
|
|
|
# Give it 100 blocks.
|
|
|
|
$CLI generate 99
|
|
|
|
|
|
|
|
check_no_peers lcli1
|
|
|
|
check_no_peers lcli2
|
|
|
|
|
|
|
|
lcli1 stop
|
|
|
|
lcli2 stop
|
|
|
|
|
|
|
|
all_ok
|
|
|
|
fi
|
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli1 fulfillhtlc $ID2 $HTLCID2 $SECRET2
|
2016-08-31 07:21:41 +02:00
|
|
|
lcli2 failhtlc $ID1 $HTLCID 849
|
2016-05-26 07:55:24 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
|
|
|
# We transferred amount from B to A.
|
|
|
|
A_AMOUNT=$(($A_AMOUNT + $HTLC_AMOUNT))
|
|
|
|
B_AMOUNT=$(($B_AMOUNT - $HTLC_AMOUNT))
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
# Now, test making more changes before receiving commit reply.
|
2016-08-18 06:55:08 +02:00
|
|
|
DO_RECONNECT=""
|
2016-05-26 07:55:25 +02:00
|
|
|
lcli2 dev-output $ID1 false
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH | extract_id`
|
2016-05-26 07:55:25 +02:00
|
|
|
|
|
|
|
# Make sure node1 sends commit (in the background, since it will block!)
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2 &
|
2016-08-18 06:53:45 +02:00
|
|
|
|
|
|
|
if [ -n "$MANUALCOMMIT" ]; then
|
|
|
|
# node2 will consider this committed.
|
|
|
|
check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_REVOCATION } "
|
|
|
|
else
|
|
|
|
# It will start committing by itself
|
|
|
|
check_status_single lcli2 $(($B_AMOUNT - $EXTRA_FEE/2)) $(($B_FEE + $EXTRA_FEE/2)) "" $(($A_AMOUNT - $HTLC_AMOUNT - $EXTRA_FEE/2)) $(($A_FEE + $EXTRA_FEE/2)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_COMMIT } "
|
|
|
|
fi
|
|
|
|
|
|
|
|
# node1 will still be awaiting node2's revocation reply.
|
|
|
|
check_status_single lcli1 $(($A_AMOUNT)) $(($A_FEE)) "{ msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_COMMIT } " $B_AMOUNT $B_FEE ""
|
2016-05-26 07:55:25 +02:00
|
|
|
|
|
|
|
# Now send another offer, and enable node2 output.
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID2=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH2 | extract_id`
|
2016-05-26 07:55:25 +02:00
|
|
|
lcli2 dev-output $ID1 true
|
|
|
|
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
2016-08-18 06:55:08 +02:00
|
|
|
DO_RECONNECT=$RECONNECT
|
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
# Both sides should be committed to htlcs
|
2016-08-18 06:53:45 +02:00
|
|
|
# We open-code check_status here: HTLCs could be in either order.
|
|
|
|
check_balance_single lcli1 $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE)) $(($B_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE))
|
|
|
|
check_balance_single lcli2 $(($B_AMOUNT - $EXTRA_FEE)) $(($B_FEE + $EXTRA_FEE)) $(($A_AMOUNT - $HTLC_AMOUNT*2 - $EXTRA_FEE)) $(($A_FEE + $EXTRA_FEE))
|
|
|
|
|
|
|
|
# Once both balances are correct, this should be right.
|
2016-08-18 06:53:45 +02:00
|
|
|
lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]" || lcli1 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : SENT_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : SENT_ADD_ACK_REVOCATION } ], their_htlcs : [ ]"
|
2016-08-18 06:53:45 +02:00
|
|
|
|
2016-08-18 06:53:45 +02:00
|
|
|
lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION } ]" || lcli2 getpeers | tr -s '\012\011" ' ' ' | $FGREP "our_htlcs : [ ], their_htlcs : [ { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH2 , state : RCVD_ADD_ACK_REVOCATION }, { msatoshis : $HTLC_AMOUNT, expiry : { block : $EXPIRY }, rhash : $RHASH , state : RCVD_ADD_ACK_REVOCATION } ]"
|
2016-05-26 07:55:25 +02:00
|
|
|
|
2016-08-18 06:55:14 +02:00
|
|
|
# Just for once, reconnect/restart node 2.
|
|
|
|
case "$RECONNECT" in
|
|
|
|
reconnect)
|
|
|
|
echo RECONNECTING NODE2
|
|
|
|
$LCLI2 dev-reconnect $ID1 >/dev/null
|
|
|
|
sleep 1
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
echo RESTARTING NODE2
|
|
|
|
$LCLI2 -- dev-restart $LIGHTNINGD2 >/dev/null 2>&1 || true
|
|
|
|
if ! check "$LCLI2 getlog 2>/dev/null | fgrep -q Hello"; then
|
|
|
|
echo "Node2 dev-restart failed!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-08-30 12:41:57 +02:00
|
|
|
if ! check "$LCLI2 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
|
|
|
echo "Failed to reconnect!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-05-26 07:55:25 +02:00
|
|
|
# Node2 collects the HTLCs.
|
2016-08-18 06:53:46 +02:00
|
|
|
lcli2 fulfillhtlc $ID1 $HTLCID $SECRET
|
|
|
|
lcli2 fulfillhtlc $ID1 $HTLCID2 $SECRET2
|
2016-05-26 07:55:25 +02:00
|
|
|
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
# We transferred 2 * amount from A to B.
|
|
|
|
A_AMOUNT=$(($A_AMOUNT - $HTLC_AMOUNT * 2))
|
|
|
|
B_AMOUNT=$(($B_AMOUNT + $HTLC_AMOUNT * 2))
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
2016-06-28 23:19:20 +02:00
|
|
|
# Now, use automatic payment redemption
|
2016-06-30 01:38:10 +02:00
|
|
|
lcli1 dev-routefail true
|
|
|
|
lcli2 dev-routefail true
|
2016-06-28 23:19:20 +02:00
|
|
|
RHASH3=`lcli2 accept-payment $HTLC_AMOUNT | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID3=`lcli1 newhtlc $ID2 $HTLC_AMOUNT $EXPIRY $RHASH3 | extract_id`
|
2016-06-28 23:19:20 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
|
|
|
# We transferred amount from A to B.
|
|
|
|
A_AMOUNT=$(($A_AMOUNT - $HTLC_AMOUNT))
|
|
|
|
B_AMOUNT=$(($B_AMOUNT + $HTLC_AMOUNT))
|
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
|
|
|
# Now, failed payment (didn't pay enough)
|
|
|
|
RHASH4=`lcli2 accept-payment $HTLC_AMOUNT | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
|
2016-06-30 01:38:10 +02:00
|
|
|
# Shouldn't have this already.
|
|
|
|
if lcli2 getlog | $FGREP 'Short payment for HTLC'; then exit 1; fi
|
|
|
|
|
2016-08-18 06:53:46 +02:00
|
|
|
HTLCID4=`lcli1 newhtlc $ID2 $(($HTLC_AMOUNT - 1)) $EXPIRY $RHASH4 | extract_id`
|
2016-06-28 23:19:20 +02:00
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli2 commit $ID1
|
|
|
|
[ ! -n "$MANUALCOMMIT" ] || lcli1 commit $ID2
|
|
|
|
|
2016-06-30 01:38:10 +02:00
|
|
|
check lcli2 "getlog | $FGREP 'Short payment for HTLC'"
|
2016-06-28 23:19:20 +02:00
|
|
|
check_status $A_AMOUNT $A_FEE "" $B_AMOUNT $B_FEE ""
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
if [ ! -n "$MANUALCOMMIT" ]; then
|
|
|
|
# Test routing to a third node.
|
|
|
|
P2SHADDR2=`$LCLI2 newaddr | sed -n 's/{ "address" : "\(.*\)" }/\1/p'`
|
|
|
|
TXID2=`$CLI sendtoaddress $P2SHADDR2 0.01`
|
|
|
|
TX2=`$CLI getrawtransaction $TXID2`
|
|
|
|
$CLI generate 1
|
|
|
|
|
|
|
|
lcli2 connect localhost $PORT3 $TX2
|
|
|
|
check_tx_spend lcli2
|
|
|
|
$CLI generate 3
|
|
|
|
|
|
|
|
# Make sure it's STATE_NORMAL.
|
|
|
|
check_peerstate lcli3 STATE_NORMAL
|
|
|
|
|
|
|
|
# More than enough to cover commit fees.
|
|
|
|
HTLC_AMOUNT=100000000
|
|
|
|
|
|
|
|
# Tell node 1 about the 2->3 route.
|
2016-08-18 06:55:14 +02:00
|
|
|
# Add to config in case we are restaring.
|
|
|
|
echo "add-route=$ID2/$ID3/546000/10/36/36" >> $DIR1/config
|
2016-08-30 12:40:57 +02:00
|
|
|
lcli1 add-route $ID2 $ID3 546000 10 36 36
|
2016-06-30 01:38:11 +02:00
|
|
|
RHASH5=`lcli3 accept-payment $HTLC_AMOUNT | sed 's/.*"\([0-9a-f]*\)".*/\1/'`
|
|
|
|
|
2016-08-31 08:36:08 +02:00
|
|
|
# Get route.
|
|
|
|
ROUTE=`lcli1 getroute $ID3 $HTLC_AMOUNT`
|
|
|
|
ROUTE=`echo $ROUTE | sed 's/^{ "route" : \(.*\) }$/\1/'`
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
# Try wrong hash.
|
2016-08-31 08:36:08 +02:00
|
|
|
if lcli1 sendpay "$ROUTE" $RHASH4; then
|
2016-06-30 01:38:11 +02:00
|
|
|
echo Paid with wrong hash? >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Try underpaying.
|
2016-08-31 08:36:08 +02:00
|
|
|
PAID=`echo "$ROUTE" | sed -n 's/.*"msatoshis" : \([0-9]*\),.*/\1/p'`
|
|
|
|
UNDERPAY=`echo "$ROUTE" | sed "s/: $PAID,/: $(($PAID - 1)),/"`
|
|
|
|
if lcli1 sendpay "$UNDERPAY" $RHASH5; then
|
2016-06-30 01:38:11 +02:00
|
|
|
echo Paid with too little? >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-09-06 06:17:33 +02:00
|
|
|
# If restarting, make sure node3 remembers incoming payment.
|
|
|
|
if [ "$RECONNECT" = restart ]; then
|
|
|
|
$LCLI3 -- dev-restart $LIGHTNINGD3 >/dev/null 2>&1 || true
|
|
|
|
if ! check "$LCLI3 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
|
|
|
echo "Failed to reconnect!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
# Pay correctly.
|
2016-08-31 08:36:08 +02:00
|
|
|
lcli1 sendpay "$ROUTE" $RHASH5
|
2016-06-30 01:38:11 +02:00
|
|
|
|
|
|
|
# Node 3 should end up with that amount (minus 1/2 tx fee)
|
|
|
|
# Note that it is delayed a little, since node2 fulfils as soon as fulfill
|
|
|
|
# starts.
|
|
|
|
check lcli3 "getpeers | $FGREP \"\\\"our_amount\\\" : $(($HTLC_AMOUNT - $NO_HTLCS_FEE / 2))\""
|
2016-09-06 06:17:33 +02:00
|
|
|
|
|
|
|
# If restarting, make sure node3 remembers completed payment.
|
|
|
|
if [ "$RECONNECT" = restart ]; then
|
|
|
|
echo RESTARTING NODE3
|
|
|
|
$LCLI3 -- dev-restart $LIGHTNINGD3 >/dev/null 2>&1 || true
|
|
|
|
if ! check "$LCLI3 getpeers 2>/dev/null | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
|
|
|
echo "Failed to reconnect!">&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Can't pay twice (try from node2)
|
|
|
|
ROUTE2=`lcli2 getroute $ID3 $HTLC_AMOUNT`
|
|
|
|
ROUTE2=`echo $ROUTE2 | sed 's/^{ "route" : \(.*\) }$/\1/'`
|
|
|
|
if lcli2 sendpay "$ROUTE2" $RHASH5; then
|
|
|
|
echo "Paying twice worked?" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-06-30 01:38:11 +02:00
|
|
|
lcli3 close $ID2
|
2016-08-31 08:34:59 +02:00
|
|
|
|
|
|
|
# Re-send should be a noop (doesn't matter that node3 is down!)
|
2016-08-31 08:36:08 +02:00
|
|
|
lcli1 sendpay "$ROUTE" $RHASH5
|
2016-08-31 08:34:59 +02:00
|
|
|
|
|
|
|
# Re-send to different id or amount should complain.
|
2016-08-31 08:36:08 +02:00
|
|
|
SHORTROUTE=`echo "$ROUTE" | sed 's/, { "id" : .* }//' | sed 's/"msatoshis" : [0-9]*,/"msatoshis" : '$HTLC_AMOUNT,/`
|
|
|
|
lcli1 sendpay "$SHORTROUTE" $RHASH5 | $FGREP "already succeeded to $ID3"
|
|
|
|
lcli1 sendpay "$UNDERPAY" $RHASH5 | $FGREP "already succeeded with amount $HTLC_AMOUNT"
|
2016-08-31 08:34:59 +02:00
|
|
|
|
2016-08-31 08:40:17 +02:00
|
|
|
# Now node2 should fail to route.
|
|
|
|
if lcli1 sendpay "$ROUTE" $RHASH4 | $FGREP "failed: error code 404 node $ID2 reason Unknown peer"; then : ;
|
|
|
|
else
|
|
|
|
echo "Pay to node3 didn't give 404" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Now node1 should fail to route (route deleted)
|
|
|
|
if lcli1 getroute $ID3 $HTLC_AMOUNT | $FGREP "no route found"; then : ;
|
|
|
|
else
|
|
|
|
echo "Pay to node3 didn't fail instantly second time" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-06-30 01:38:11 +02:00
|
|
|
fi
|
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
lcli1 close $ID2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-26 07:55:24 +02:00
|
|
|
# They should be negotiating the close.
|
|
|
|
check_peerstate lcli1 STATE_MUTUAL_CLOSING
|
|
|
|
check_peerstate lcli2 STATE_MUTUAL_CLOSING
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-05-04 08:44:22 +02:00
|
|
|
$CLI generate 1
|
2016-05-05 06:53:36 +02:00
|
|
|
|
2016-05-04 08:44:22 +02:00
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
|
|
|
|
# Give it 99 blocks.
|
|
|
|
$CLI generate 98
|
|
|
|
|
|
|
|
# Make sure they saw it!
|
|
|
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_MUTUAL
|
|
|
|
check_peerstate lcli2 STATE_CLOSE_ONCHAIN_MUTUAL
|
2016-01-21 21:15:28 +01:00
|
|
|
|
|
|
|
# Now the final one.
|
|
|
|
$CLI generate 1
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-04-24 12:04:13 +02:00
|
|
|
check_no_peers lcli1
|
|
|
|
check_no_peers lcli2
|
2016-01-21 21:15:28 +01:00
|
|
|
|
2016-03-08 01:05:15 +01:00
|
|
|
lcli1 stop
|
|
|
|
lcli2 stop
|
2016-01-21 21:15:27 +01:00
|
|
|
|
2016-01-21 21:15:28 +01:00
|
|
|
all_ok
|