Skip to content

Commit 6ce8eb1

Browse files
committed
regtests: add test "lnwatcher_waits_until_fees_go_down"
reproduces #9980
1 parent 75be9c6 commit 6ce8eb1

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

tests/regtest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def test_breach_with_unspent_htlc(self):
8282
def test_breach_with_spent_htlc(self):
8383
self.run_shell(['breach_with_spent_htlc'])
8484

85+
def test_lnwatcher_waits_until_fees_go_down(self):
86+
self.run_shell(['lnwatcher_waits_until_fees_go_down'])
87+
8588

8689
class TestLightningSwapserver(TestLightning):
8790
agents = {

tests/regtest/regtest.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ function wait_until_spent()
9090
printf "\n"
9191
}
9292

93+
function assert_utxo_exists()
94+
{
95+
utxo=$($bitcoin_cli gettxout $1 $2)
96+
if [[ -z "$utxo" ]]; then
97+
echo "utxo $1:$2 does not exist"
98+
exit 1
99+
fi
100+
}
101+
93102
if [[ $# -eq 0 ]]; then
94103
echo "syntax: init|start|open|status|pay|close|stop"
95104
exit 1
@@ -308,6 +317,89 @@ if [[ $1 == "swapserver_refund" ]]; then
308317
fi
309318

310319

320+
if [[ $1 == "lnwatcher_waits_until_fees_go_down" ]]; then
321+
# Alice sends two HTLCs to Bob (one for small invoice, one for large invoice), which Bob will hold.
322+
# Alice requests Bob to force-close the channel, while the HTLCs are pending. Bob force-closes.
323+
# Fee levels rise, to the point where the small HTLC is not economical to claim.
324+
# Alice sweeps the large HTLC (via onchain timeout), but not the small one.
325+
# Then, fee levels go back down, and Alice sweeps the small HTLC.
326+
# This test checks Alice does not abandon channel outputs that are temporarily ~dust due to
327+
# mempool spikes, and keeps watching the channel in hope of fees going down.
328+
$alice setconfig test_force_disable_mpp true
329+
$alice setconfig test_force_mpp false
330+
wait_for_balance alice 1
331+
$alice test_inject_fee_etas "{2:1000}"
332+
$bob test_inject_fee_etas "{2:1000}"
333+
echo "alice opens channel"
334+
bob_node=$($bob nodeid)
335+
channel=$($alice open_channel $bob_node 0.15 --password='')
336+
chan_funding_txid=$(echo "$channel" | cut -d ":" -f 1)
337+
chan_funding_outidx=$(echo "$channel" | cut -d ":" -f 2)
338+
new_blocks 3
339+
wait_until_channel_open alice
340+
# Alice sends an HTLC to Bob, which Bob will hold indefinitely. Alice's lnpay will time out.
341+
invoice1=$($bob add_hold_invoice deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee1 \
342+
--amount 0.0004 --min_final_cltv_expiry_delta 300 | jq -r ".invoice")
343+
invoice2=$($bob add_hold_invoice deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee2 \
344+
--amount 0.04 --min_final_cltv_expiry_delta 300 | jq -r ".invoice")
345+
set +e
346+
$alice lnpay $invoice1 --timeout 3
347+
$alice lnpay $invoice2 --timeout 3
348+
set -e
349+
# After a while, Alice gets impatient and gets Bob to close the channel.
350+
new_blocks 20
351+
$alice request_force_close $channel
352+
wait_until_spent $chan_funding_txid $chan_funding_outidx
353+
$bob stop # bob closes and then disappears. FIXME this is a hack to prevent Bob claiming the fake-hold-invoice-htlc onchain
354+
new_blocks 1
355+
wait_until_channel_closed alice
356+
ctx_id=$($alice list_channels | jq -r ".[0].closing_txid")
357+
if [ $TEST_ANCHOR_CHANNELS = True ] ; then
358+
htlc_output_index1=2
359+
htlc_output_index2=3
360+
to_alice_index=4 # Bob's to_remote
361+
wait_until_spent $ctx_id $to_alice_index
362+
else
363+
htlc_output_index1=0
364+
htlc_output_index2=1
365+
to_alice_index=2
366+
fi
367+
new_blocks 1
368+
assert_utxo_exists $ctx_id $htlc_output_index1
369+
assert_utxo_exists $ctx_id $htlc_output_index2
370+
# fee levels rise. now small htlc is ~dust
371+
$alice test_inject_fee_etas "{2:300000}"
372+
new_blocks 300 # this goes past the CLTV of the HTLC-output in ctx
373+
wait_until_spent $ctx_id $htlc_output_index2
374+
assert_utxo_exists $ctx_id $htlc_output_index1
375+
new_blocks 24 # note: >20 blocks depth is considered "DEEP" by lnwatcher
376+
sleep 1 # give time for Alice to make mistakes, such as abandoning the channel. which it should NOT do.
377+
new_blocks 1
378+
# Alice goes offline and comes back later, 1
379+
$alice stop
380+
$alice daemon -d
381+
$alice test_inject_fee_etas "{2:300000}"
382+
$alice load_wallet
383+
$alice wait_for_sync
384+
new_blocks 1
385+
sleep 1 # give time for Alice to make mistakes
386+
# Alice goes offline and comes back later, 2
387+
$alice stop
388+
$alice daemon -d
389+
$alice test_inject_fee_etas "{2:300000}"
390+
$alice load_wallet
391+
$alice wait_for_sync
392+
new_blocks 1
393+
sleep 1 # give time for Alice to make mistakes
394+
# fee levels go down. time to claim the small htlc
395+
$alice test_inject_fee_etas "{2:1000}"
396+
new_blocks 1
397+
wait_until_spent $ctx_id $htlc_output_index1
398+
new_blocks 1
399+
wait_for_balance alice 0.9995
400+
fi
401+
402+
311403
if [[ $1 == "extract_preimage" ]]; then
312404
# Alice sends htlc1 to Bob. Bob sends htlc2 to Alice.
313405
# Neither one of them settles, they hold the htlcs, and Bob force-closes.

0 commit comments

Comments
 (0)