mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
test: restore anchor timeout tests.
Importantly, they're now entirely block driven. We don't use dev-setmocktime at all any more. This also fixes a bug if we run the test twice against the same bitcoind; we need to extract the time from the block header rather than assuming bitcoind is on the current time. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6f360422d4
commit
0f09605e17
@ -9,16 +9,18 @@ daemon-test.sh-1-%:
|
|||||||
daemon-test.sh-2-%:
|
daemon-test.sh-2-%:
|
||||||
NO_VALGRIND=$(NO_VALGRIND) VARIANT=2 daemon/test/test.sh --$*
|
NO_VALGRIND=$(NO_VALGRIND) VARIANT=2 daemon/test/test.sh --$*
|
||||||
|
|
||||||
# FIXME: Timeout-anchor tests.
|
|
||||||
|
|
||||||
# These don't work in parallel, so chain the deps
|
# These don't work in parallel, so chain the deps
|
||||||
daemon-test.sh-0-steal: daemon-test.sh-0-dump-onchain
|
daemon-test.sh-0-steal: daemon-test.sh-0-dump-onchain
|
||||||
daemon-test.sh-0-dump-onchain: daemon-test.sh-0-different-fee-rates
|
daemon-test.sh-0-dump-onchain: daemon-test.sh-0-timeout-anchor
|
||||||
|
daemon-test.sh-0-timeout-anchor: daemon-test.sh-0-different-fee-rates
|
||||||
daemon-test.sh-0-different-fee-rates: daemon-test.sh-0-mutual-close-with-htlcs
|
daemon-test.sh-0-different-fee-rates: daemon-test.sh-0-mutual-close-with-htlcs
|
||||||
daemon-test.sh-0-mutual-close-with-htlcs: daemon-test.sh-0-manual-commit
|
daemon-test.sh-0-mutual-close-with-htlcs: daemon-test.sh-0-manual-commit
|
||||||
daemon-test.sh-0-manual-commit: daemon-test.sh-0-normal
|
daemon-test.sh-0-manual-commit: daemon-test.sh-0-normal
|
||||||
daemon-test.sh-0-normal: daemon-test-setup-0
|
daemon-test.sh-0-normal: daemon-test-setup-0
|
||||||
|
|
||||||
|
#FIXME: daemon-test.sh-1-timeout-anchor\ --restart
|
||||||
|
# This doesn't work because we don't retransmit anchor!
|
||||||
|
|
||||||
daemon-test.sh-1-steal\ --restart: daemon-test.sh-1-dump-onchain\ --restart
|
daemon-test.sh-1-steal\ --restart: daemon-test.sh-1-dump-onchain\ --restart
|
||||||
daemon-test.sh-1-dump-onchain\ --restart: daemon-test.sh-1-different-fee-rates\ --restart
|
daemon-test.sh-1-dump-onchain\ --restart: daemon-test.sh-1-different-fee-rates\ --restart
|
||||||
daemon-test.sh-1-different-fee-rates\ --restart: daemon-test.sh-1-mutual-close-with-htlcs\ --restart
|
daemon-test.sh-1-different-fee-rates\ --restart: daemon-test.sh-1-mutual-close-with-htlcs\ --restart
|
||||||
@ -27,7 +29,8 @@ daemon-test.sh-1-manual-commit\ --restart: daemon-test.sh-1-normal\ --restart
|
|||||||
daemon-test.sh-1-normal\ --restart: daemon-test-setup-1
|
daemon-test.sh-1-normal\ --restart: daemon-test-setup-1
|
||||||
|
|
||||||
daemon-test.sh-2-steal\ --reconnect: daemon-test.sh-2-dump-onchain\ --reconnect
|
daemon-test.sh-2-steal\ --reconnect: daemon-test.sh-2-dump-onchain\ --reconnect
|
||||||
daemon-test.sh-2-dump-onchain\ --reconnect: daemon-test.sh-2-different-fee-rates\ --reconnect
|
daemon-test.sh-2-dump-onchain\ --reconnect: daemon-test.sh-2-timeout-anchor\ --reconnect
|
||||||
|
daemon-test.sh-2-timeout-anchor\ --reconnect: daemon-test.sh-2-different-fee-rates\ --reconnect
|
||||||
daemon-test.sh-2-different-fee-rates\ --reconnect: daemon-test.sh-2-mutual-close-with-htlcs\ --reconnect
|
daemon-test.sh-2-different-fee-rates\ --reconnect: daemon-test.sh-2-mutual-close-with-htlcs\ --reconnect
|
||||||
daemon-test.sh-2-mutual-close-with-htlcs\ --reconnect: daemon-test.sh-2-manual-commit\ --reconnect
|
daemon-test.sh-2-mutual-close-with-htlcs\ --reconnect: daemon-test.sh-2-manual-commit\ --reconnect
|
||||||
daemon-test.sh-2-manual-commit\ --reconnect: daemon-test.sh-2-normal\ --reconnect
|
daemon-test.sh-2-manual-commit\ --reconnect: daemon-test.sh-2-normal\ --reconnect
|
||||||
|
@ -139,8 +139,6 @@ lcli1()
|
|||||||
# Don't restart on every get* command.
|
# Don't restart on every get* command.
|
||||||
get*)
|
get*)
|
||||||
;;
|
;;
|
||||||
dev-mocktime*)
|
|
||||||
;;
|
|
||||||
dev-disconnect)
|
dev-disconnect)
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
@ -160,8 +158,8 @@ lcli1()
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Wait for reconnect;
|
# Wait for reconnect (if peer2 still there)
|
||||||
if ! check "$LCLI1 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
if [ -z "$NO_PEER2" ] && ! check "$LCLI1 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
||||||
echo "Failed to reconnect!">&2
|
echo "Failed to reconnect!">&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -226,12 +224,6 @@ check()
|
|||||||
{
|
{
|
||||||
local i=0
|
local i=0
|
||||||
while ! eval "$@"; do
|
while ! eval "$@"; do
|
||||||
# Try making time pass for the nodes (if on mocktime), then sleeping.
|
|
||||||
if [ -n "$MOCKTIME" ]; then
|
|
||||||
MOCKTIME=$(($MOCKTIME + 5))
|
|
||||||
lcli1 dev-mocktime $MOCKTIME
|
|
||||||
lcli2 dev-mocktime $MOCKTIME
|
|
||||||
fi
|
|
||||||
sleep 1
|
sleep 1
|
||||||
i=$(($i + 1))
|
i=$(($i + 1))
|
||||||
if [ $i = 60 ]; then
|
if [ $i = 60 ]; then
|
||||||
@ -473,6 +465,15 @@ TXID=`$CLI sendtoaddress $P2SHADDR 0.01`
|
|||||||
TX=`$CLI getrawtransaction $TXID`
|
TX=`$CLI getrawtransaction $TXID`
|
||||||
$CLI generate 1
|
$CLI generate 1
|
||||||
|
|
||||||
|
# Make sure they see it (for timeout we need to know what height they were)
|
||||||
|
BLOCKHEIGHT=`$CLI getblockcount`
|
||||||
|
check "$LCLI1 getinfo | $FGREP '\"blockheight\" : $BLOCKHEIGHT'"
|
||||||
|
check "$LCLI2 getinfo | $FGREP '\"blockheight\" : $BLOCKHEIGHT'"
|
||||||
|
|
||||||
|
# Prevent anchor broadcast if we want to test timeout.
|
||||||
|
if [ -n "$TIMEOUT_ANCHOR" ]; then
|
||||||
|
lcli1 dev-broadcast false
|
||||||
|
fi
|
||||||
lcli1 connect localhost $PORT2 $TX &
|
lcli1 connect localhost $PORT2 $TX &
|
||||||
|
|
||||||
# Expect them to be waiting for anchor, and ack from other side.
|
# Expect them to be waiting for anchor, and ack from other side.
|
||||||
@ -482,43 +483,57 @@ check_peerstate lcli2 STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE
|
|||||||
DO_RECONNECT=$RECONNECT
|
DO_RECONNECT=$RECONNECT
|
||||||
|
|
||||||
if [ -n "$TIMEOUT_ANCHOR" ]; then
|
if [ -n "$TIMEOUT_ANCHOR" ]; then
|
||||||
# Check anchor emitted, not mined deep enough.
|
# Blocks before anchor committed (100 to hit chain, 1 to reach depth)
|
||||||
check_tx_spend lcli1
|
$CLI generate 100
|
||||||
|
|
||||||
# Timeout before anchor committed.
|
# Still waiting.
|
||||||
MOCKTIME=$((`date +%s` + 7200 + 3 * 1200 + 1))
|
check_peerstate lcli1 STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE
|
||||||
|
check_peerstate lcli2 STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE
|
||||||
|
|
||||||
lcli1 dev-mocktime $MOCKTIME
|
# Make sure whichever times out first doesn't tell the other.
|
||||||
lcli2 dev-mocktime $MOCKTIME
|
lcli1 dev-output $ID2 false
|
||||||
|
lcli2 dev-output $ID1 false
|
||||||
|
$CLI generate 1
|
||||||
|
|
||||||
# Node2 should have gone via STATE_ERR_ANCHOR_TIMEOUT, then closed.
|
# Node1 should have gone into STATE_ERR_ANCHOR_TIMEOUT.
|
||||||
lcli2 getlog | grep STATE_ERR_ANCHOR_TIMEOUT
|
check "lcli1 getlog debug | $FGREP STATE_ERR_ANCHOR_TIMEOUT"
|
||||||
|
|
||||||
|
# Don't try to reconnect any more if we are.
|
||||||
|
if [ x"$RECONNECT" = xreconnect ]; then DO_RECONNECT=""; fi
|
||||||
|
NO_PEER2=1
|
||||||
|
|
||||||
|
# Now let them send errors if they're still trying.
|
||||||
|
lcli2 dev-output $ID1 true || true
|
||||||
|
lcli1 dev-output $ID2 true || true
|
||||||
|
|
||||||
|
# Peer 2 should give up, and have forgotten all about it.
|
||||||
|
check "lcli2 getlog debug | $FGREP STATE_CLOSED"
|
||||||
check_no_peers lcli2
|
check_no_peers lcli2
|
||||||
|
|
||||||
# Node1 should be disconnected.
|
# Node1 should be disconnected.
|
||||||
check_peerconnected lcli1 false
|
check_peerconnected lcli1 false
|
||||||
|
|
||||||
# Node1 should send out commit tx; mine it.
|
# Now let node1 broadcast anchor and unilateral close belatedly!
|
||||||
check_tx_spend lcli1
|
lcli1 dev-broadcast true
|
||||||
|
|
||||||
|
# Now mine that transaction so they see it.
|
||||||
$CLI generate 1
|
$CLI generate 1
|
||||||
|
|
||||||
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
||||||
|
|
||||||
# Now "wait" for 1 day, which is what node2 asked for on commit.
|
# Now move bitcoind 1 day, which is what node2 asked for on commit.
|
||||||
MOCKTIME=$(($MOCKTIME + 24 * 60 * 60 - 1))
|
# Get current time from last block (works if we run this twice).
|
||||||
lcli1 dev-mocktime $MOCKTIME
|
CURTIME=$($CLI getblock $($CLI getblockhash $(($BLOCKHEIGHT + 100))) | sed -n 's/ "time": \([0-9]*\),/\1/p')
|
||||||
|
$CLI setmocktime $(($CURTIME + 24 * 60 * 60))
|
||||||
|
|
||||||
# Move bitcoind median time as well, so CSV moves.
|
# Move average so CSV moves.
|
||||||
$CLI setmocktime $MOCKTIME
|
|
||||||
$CLI generate 6
|
$CLI generate 6
|
||||||
|
|
||||||
# Now it should have spent the commit tx.
|
# Now it should have spent the commit tx.
|
||||||
check_tx_spend lcli1
|
check_tx_spend lcli1
|
||||||
|
|
||||||
# 100 blocks pass...
|
# 100 blocks pass
|
||||||
$CLI generate 100
|
$CLI generate 100
|
||||||
MOCKTIME=$(($MOCKTIME + 1))
|
|
||||||
lcli1 dev-mocktime $MOCKTIME
|
|
||||||
|
|
||||||
# Considers it all done now.
|
# Considers it all done now.
|
||||||
check_no_peers lcli1
|
check_no_peers lcli1
|
||||||
|
Loading…
Reference in New Issue
Block a user