|
|
@ -16,15 +16,6 @@ REDIRERR1="$DIR1/errors" |
|
|
|
REDIRERR2="$DIR2/errors" |
|
|
|
FGREP="fgrep -q" |
|
|
|
|
|
|
|
if [ x"$1" = x"--verbose" ]; then |
|
|
|
shift |
|
|
|
set -x |
|
|
|
FGREP="fgrep" |
|
|
|
else |
|
|
|
# Suppress command output. |
|
|
|
exec >/dev/null |
|
|
|
fi |
|
|
|
|
|
|
|
# Always use valgrind. |
|
|
|
PREFIX="valgrind -q --error-exitcode=7" |
|
|
|
|
|
|
@ -46,6 +37,9 @@ while [ $# != 0 ]; do |
|
|
|
x"--timeout-anchor") |
|
|
|
TIMEOUT_ANCHOR=1 |
|
|
|
;; |
|
|
|
x"--verbose") |
|
|
|
VERBOSE=1 |
|
|
|
;; |
|
|
|
*) |
|
|
|
echo Unknown arg "$1" >&2 |
|
|
|
exit 1 |
|
|
@ -56,9 +50,32 @@ done |
|
|
|
LCLI1="../daemon/lightning-cli --lightning-dir=$DIR1" |
|
|
|
LCLI2="../daemon/lightning-cli --lightning-dir=$DIR2" |
|
|
|
|
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
FGREP="fgrep" |
|
|
|
else |
|
|
|
# Suppress command output. |
|
|
|
exec >/dev/null |
|
|
|
fi |
|
|
|
|
|
|
|
lcli1() |
|
|
|
{ |
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
echo $LCLI1 "$@" >&2 |
|
|
|
fi |
|
|
|
$LCLI1 "$@" |
|
|
|
} |
|
|
|
|
|
|
|
lcli2() |
|
|
|
{ |
|
|
|
if [ -n "$VERBOSE" ]; then |
|
|
|
echo $LCLI2 "$@" >&2 |
|
|
|
fi |
|
|
|
$LCLI2 "$@" |
|
|
|
} |
|
|
|
|
|
|
|
check_status_single() |
|
|
|
{ |
|
|
|
lcli_cmd="$1" |
|
|
|
lcli="$1" |
|
|
|
us_pay=$2 |
|
|
|
us_fee=$3 |
|
|
|
us_htlcs="$4" |
|
|
@ -66,9 +83,9 @@ check_status_single() |
|
|
|
them_fee=$6 |
|
|
|
them_htlcs="$7" |
|
|
|
|
|
|
|
if $lcli_cmd getpeers | tr -s '\012\011 ' ' ' | $FGREP '"channel" : { "us" : { "pay" : '$us_pay', "fee" : '$us_fee', "htlcs" : [ '"$us_htlcs"'] }, "them" : { "pay" : '$them_pay', "fee" : '$them_fee', "htlcs" : [ '"$them_htlcs"'] } }'; then :; else |
|
|
|
echo Cannot find $lcli_cmd output: '"channel" : { "us" : { "pay" : '$us_pay', "fee" : '$us_fee', "htlcs" : [ '"$us_htlcs"'] }, "them" : { "pay" : '$them_pay', "fee" : '$them_fee', "htlcs" : [ '"$them_htlcs"'] } }' >&2 |
|
|
|
$lcli_cmd getpeers | tr -s '\012\011 ' ' ' >&2 |
|
|
|
if $lcli getpeers | tr -s '\012\011 ' ' ' | $FGREP '"channel" : { "us" : { "pay" : '$us_pay', "fee" : '$us_fee', "htlcs" : [ '"$us_htlcs"'] }, "them" : { "pay" : '$them_pay', "fee" : '$them_fee', "htlcs" : [ '"$them_htlcs"'] } }'; then :; else |
|
|
|
echo Cannot find $lcli output: '"channel" : { "us" : { "pay" : '$us_pay', "fee" : '$us_fee', "htlcs" : [ '"$us_htlcs"'] }, "them" : { "pay" : '$them_pay', "fee" : '$them_fee', "htlcs" : [ '"$them_htlcs"'] } }' >&2 |
|
|
|
$lcli getpeers | tr -s '\012\011 ' ' ' >&2 |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
} |
|
|
@ -82,8 +99,8 @@ check_status() |
|
|
|
them_fee=$5 |
|
|
|
them_htlcs="$6" |
|
|
|
|
|
|
|
check_status_single "$LCLI1" "$us_pay" "$us_fee" "$us_htlcs" "$them_pay" "$them_fee" "$them_htlcs" |
|
|
|
check_status_single "$LCLI2" "$them_pay" "$them_fee" "$them_htlcs" "$us_pay" "$us_fee" "$us_htlcs" |
|
|
|
check_status_single lcli1 "$us_pay" "$us_fee" "$us_htlcs" "$them_pay" "$them_fee" "$them_htlcs" |
|
|
|
check_status_single lcli2 "$them_pay" "$them_fee" "$them_htlcs" "$us_pay" "$us_fee" "$us_htlcs" |
|
|
|
} |
|
|
|
|
|
|
|
check_tx_spend() |
|
|
@ -149,12 +166,12 @@ ID2=`$LCLI2 getlog | sed -n 's/.*"ID: \([0-9a-f]*\)".*/\1/p'` |
|
|
|
|
|
|
|
PORT2=`$LCLI2 getlog | sed -n 's/.*on port \([0-9]*\).*/\1/p'` |
|
|
|
|
|
|
|
$LCLI1 connect localhost $PORT2 999999 |
|
|
|
lcli1 connect localhost $PORT2 999999 |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
# Expect them to be waiting for anchor. |
|
|
|
$LCLI1 getpeers | $FGREP STATE_OPEN_WAITING_OURANCHOR |
|
|
|
$LCLI2 getpeers | $FGREP STATE_OPEN_WAITING_THEIRANCHOR |
|
|
|
lcli1 getpeers | $FGREP STATE_OPEN_WAITING_OURANCHOR |
|
|
|
lcli2 getpeers | $FGREP STATE_OPEN_WAITING_THEIRANCHOR |
|
|
|
|
|
|
|
if [ -n "$TIMEOUT_ANCHOR" ]; then |
|
|
|
# Anchor gets 1 commit. |
|
|
@ -163,7 +180,7 @@ if [ -n "$TIMEOUT_ANCHOR" ]; then |
|
|
|
# Timeout before anchor committed deep enough. |
|
|
|
TIME=$((`date +%s` + 7200 + 3 * 1200 + 1)) |
|
|
|
|
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
|
|
|
|
# This will crash immediately |
|
|
|
if $LCLI2 dev-mocktime $TIME 2> /dev/null; then |
|
|
@ -175,27 +192,27 @@ if [ -n "$TIMEOUT_ANCHOR" ]; then |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
# It should send out commit tx. |
|
|
|
$LCLI1 getpeers | $FGREP -w STATE_CLOSE_WAIT_CLOSE_OURCOMMIT |
|
|
|
lcli1 getpeers | $FGREP -w STATE_CLOSE_WAIT_CLOSE_OURCOMMIT |
|
|
|
|
|
|
|
# Generate a block (should include commit tx) |
|
|
|
check_tx_spend |
|
|
|
|
|
|
|
# Now "wait" for 1 day, which is what node2 asked for on commit. |
|
|
|
TIME=$(($TIME + 24 * 60 * 60)) |
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
|
|
|
|
# Due to laziness, we trigger by block generation. |
|
|
|
$CLI generate 1 |
|
|
|
TIME=$(($TIME + 1)) |
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
# Sometimes it skips poll because it's busy. Do it again. |
|
|
|
TIME=$(($TIME + 1)) |
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
$LCLI1 getpeers | $FGREP -w STATE_CLOSE_WAIT_CLOSE_SPENDOURS |
|
|
|
lcli1 getpeers | $FGREP -w STATE_CLOSE_WAIT_CLOSE_SPENDOURS |
|
|
|
|
|
|
|
# Now it should have spent the commit tx. |
|
|
|
check_tx_spend |
|
|
@ -203,13 +220,13 @@ if [ -n "$TIMEOUT_ANCHOR" ]; then |
|
|
|
# 99 more blocks pass... |
|
|
|
$CLI generate 99 |
|
|
|
TIME=$(($TIME + 1)) |
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
# Considers it all done now. |
|
|
|
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
lcli1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
|
|
|
|
$LCLI1 stop |
|
|
|
lcli1 stop |
|
|
|
all_ok |
|
|
|
fi |
|
|
|
|
|
|
@ -220,80 +237,80 @@ $CLI generate 2 |
|
|
|
# They poll every second, so give them time to process. |
|
|
|
sleep 2 |
|
|
|
|
|
|
|
$LCLI1 getpeers | $FGREP STATE_NORMAL_HIGHPRIO |
|
|
|
$LCLI2 getpeers | $FGREP STATE_NORMAL_LOWPRIO |
|
|
|
lcli1 getpeers | $FGREP STATE_NORMAL_HIGHPRIO |
|
|
|
lcli2 getpeers | $FGREP STATE_NORMAL_LOWPRIO |
|
|
|
|
|
|
|
check_status 949999000 50000000 "" 0 0 "" |
|
|
|
|
|
|
|
EXPIRY=$(( $(date +%s) + 1000)) |
|
|
|
SECRET=1de08917a61cb2b62ed5937d38577f6a7bfe59c176781c6d8128018e8b5ccdfd |
|
|
|
RHASH=`$LCLI1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'` |
|
|
|
$LCLI1 newhtlc $ID2 1000000 $EXPIRY $RHASH |
|
|
|
RHASH=`lcli1 dev-rhash $SECRET | sed 's/.*"\([0-9a-f]*\)".*/\1/'` |
|
|
|
lcli1 newhtlc $ID2 1000000 $EXPIRY $RHASH |
|
|
|
|
|
|
|
# Check channel status |
|
|
|
check_status 948999000 50000000 '{ "msatoshis" : 1000000, "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' 0 0 "" |
|
|
|
|
|
|
|
$LCLI2 fulfillhtlc $ID1 $SECRET |
|
|
|
lcli2 fulfillhtlc $ID1 $SECRET |
|
|
|
|
|
|
|
# We've transferred the HTLC amount to 2, who now has to pay fees. |
|
|
|
check_status 949999000 49000000 "" 0 1000000 "" |
|
|
|
|
|
|
|
# A new one, at 10x the amount. |
|
|
|
$LCLI1 newhtlc $ID2 10000000 $EXPIRY $RHASH |
|
|
|
lcli1 newhtlc $ID2 10000000 $EXPIRY $RHASH |
|
|
|
|
|
|
|
# Check channel status |
|
|
|
check_status 939999000 49000000 '{ "msatoshis" : 10000000, "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' 0 1000000 "" |
|
|
|
|
|
|
|
$LCLI2 failhtlc $ID1 $RHASH |
|
|
|
lcli2 failhtlc $ID1 $RHASH |
|
|
|
|
|
|
|
# Back to how we were before. |
|
|
|
check_status 949999000 49000000 "" 0 1000000 "" |
|
|
|
|
|
|
|
# Same again, but this time it expires. |
|
|
|
$LCLI1 newhtlc $ID2 10000000 $EXPIRY $RHASH |
|
|
|
lcli1 newhtlc $ID2 10000000 $EXPIRY $RHASH |
|
|
|
|
|
|
|
# Check channel status |
|
|
|
check_status 939999000 49000000 '{ "msatoshis" : 10000000, "expiry" : { "second" : '$EXPIRY' }, "rhash" : "'$RHASH'" } ' 0 1000000 "" |
|
|
|
|
|
|
|
# Make sure node1 accepts the expiry packet. |
|
|
|
$LCLI1 dev-mocktime $(($EXPIRY)) |
|
|
|
lcli1 dev-mocktime $(($EXPIRY)) |
|
|
|
|
|
|
|
# This should make node2 send it. |
|
|
|
$LCLI2 dev-mocktime $(($EXPIRY + 31)) |
|
|
|
lcli2 dev-mocktime $(($EXPIRY + 31)) |
|
|
|
sleep 1 |
|
|
|
|
|
|
|
# Back to how we were before. |
|
|
|
check_status 949999000 49000000 "" 0 1000000 "" |
|
|
|
|
|
|
|
$LCLI1 close $ID2 |
|
|
|
lcli1 close $ID2 |
|
|
|
|
|
|
|
sleep 1 |
|
|
|
|
|
|
|
# They should be waiting for close. |
|
|
|
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
lcli1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
lcli2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
|
|
|
|
# Give it 99 blocks. |
|
|
|
$CLI generate 99 |
|
|
|
|
|
|
|
# Make sure they saw it! |
|
|
|
$LCLI1 dev-mocktime $(($EXPIRY + 32)) |
|
|
|
$LCLI2 dev-mocktime $(($EXPIRY + 32)) |
|
|
|
lcli1 dev-mocktime $(($EXPIRY + 32)) |
|
|
|
lcli2 dev-mocktime $(($EXPIRY + 32)) |
|
|
|
sleep 1 |
|
|
|
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
lcli1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
lcli2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"STATE_CLOSE_WAIT_CLOSE"' |
|
|
|
|
|
|
|
# Now the final one. |
|
|
|
$CLI generate 1 |
|
|
|
TIME=$(($EXPIRY + 33)) |
|
|
|
$LCLI1 dev-mocktime $TIME |
|
|
|
$LCLI2 dev-mocktime $TIME |
|
|
|
lcli1 dev-mocktime $TIME |
|
|
|
lcli2 dev-mocktime $TIME |
|
|
|
sleep 1 |
|
|
|
|
|
|
|
$LCLI1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
$LCLI2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
lcli1 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
lcli2 getpeers | tr -s '\012\011 ' ' ' | $FGREP '"peers" : [ ]' |
|
|
|
|
|
|
|
$LCLI1 stop |
|
|
|
$LCLI2 stop |
|
|
|
lcli1 stop |
|
|
|
lcli2 stop |
|
|
|
|
|
|
|
all_ok |
|
|
|