mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +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-%:
|
||||
NO_VALGRIND=$(NO_VALGRIND) VARIANT=2 daemon/test/test.sh --$*
|
||||
|
||||
# FIXME: Timeout-anchor tests.
|
||||
|
||||
# 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-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-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-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-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
|
||||
@ -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-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-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
|
||||
|
@ -139,8 +139,6 @@ lcli1()
|
||||
# Don't restart on every get* command.
|
||||
get*)
|
||||
;;
|
||||
dev-mocktime*)
|
||||
;;
|
||||
dev-disconnect)
|
||||
;;
|
||||
stop)
|
||||
@ -160,8 +158,8 @@ lcli1()
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
# Wait for reconnect;
|
||||
if ! check "$LCLI1 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
||||
# Wait for reconnect (if peer2 still there)
|
||||
if [ -z "$NO_PEER2" ] && ! check "$LCLI1 getpeers | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
|
||||
echo "Failed to reconnect!">&2
|
||||
exit 1
|
||||
fi
|
||||
@ -226,12 +224,6 @@ check()
|
||||
{
|
||||
local i=0
|
||||
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
|
||||
i=$(($i + 1))
|
||||
if [ $i = 60 ]; then
|
||||
@ -473,6 +465,15 @@ TXID=`$CLI sendtoaddress $P2SHADDR 0.01`
|
||||
TX=`$CLI getrawtransaction $TXID`
|
||||
$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 &
|
||||
|
||||
# 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
|
||||
|
||||
if [ -n "$TIMEOUT_ANCHOR" ]; then
|
||||
# Check anchor emitted, not mined deep enough.
|
||||
check_tx_spend lcli1
|
||||
# Blocks before anchor committed (100 to hit chain, 1 to reach depth)
|
||||
$CLI generate 100
|
||||
|
||||
# Timeout before anchor committed.
|
||||
MOCKTIME=$((`date +%s` + 7200 + 3 * 1200 + 1))
|
||||
# Still waiting.
|
||||
check_peerstate lcli1 STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE
|
||||
check_peerstate lcli2 STATE_OPEN_WAIT_ANCHORDEPTH_AND_THEIRCOMPLETE
|
||||
|
||||
lcli1 dev-mocktime $MOCKTIME
|
||||
lcli2 dev-mocktime $MOCKTIME
|
||||
# Make sure whichever times out first doesn't tell the other.
|
||||
lcli1 dev-output $ID2 false
|
||||
lcli2 dev-output $ID1 false
|
||||
$CLI generate 1
|
||||
|
||||
# Node2 should have gone via STATE_ERR_ANCHOR_TIMEOUT, then closed.
|
||||
lcli2 getlog | grep STATE_ERR_ANCHOR_TIMEOUT
|
||||
# Node1 should have gone into 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
|
||||
|
||||
# Node1 should be disconnected.
|
||||
check_peerconnected lcli1 false
|
||||
|
||||
# Node1 should send out commit tx; mine it.
|
||||
check_tx_spend lcli1
|
||||
|
||||
# Now let node1 broadcast anchor and unilateral close belatedly!
|
||||
lcli1 dev-broadcast true
|
||||
|
||||
# Now mine that transaction so they see it.
|
||||
$CLI generate 1
|
||||
|
||||
check_peerstate lcli1 STATE_CLOSE_ONCHAIN_OUR_UNILATERAL
|
||||
|
||||
# Now "wait" for 1 day, which is what node2 asked for on commit.
|
||||
MOCKTIME=$(($MOCKTIME + 24 * 60 * 60 - 1))
|
||||
lcli1 dev-mocktime $MOCKTIME
|
||||
# Now move bitcoind 1 day, which is what node2 asked for on commit.
|
||||
# Get current time from last block (works if we run this twice).
|
||||
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.
|
||||
$CLI setmocktime $MOCKTIME
|
||||
# Move average so CSV moves.
|
||||
$CLI generate 6
|
||||
|
||||
# Now it should have spent the commit tx.
|
||||
check_tx_spend lcli1
|
||||
|
||||
# 100 blocks pass...
|
||||
# 100 blocks pass
|
||||
$CLI generate 100
|
||||
MOCKTIME=$(($MOCKTIME + 1))
|
||||
lcli1 dev-mocktime $MOCKTIME
|
||||
|
||||
# Considers it all done now.
|
||||
check_no_peers lcli1
|
||||
|
Loading…
Reference in New Issue
Block a user