@@ -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+
93102if [[ $# -eq 0 ]]; then
94103 echo " syntax: init|start|open|status|pay|close|stop"
95104 exit 1
@@ -308,6 +317,71 @@ if [[ $1 == "swapserver_refund" ]]; then
308317fi
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 1
376+ # fee levels go down. time to claim the small htlc
377+ $alice test_inject_fee_etas " {2:1000}"
378+ new_blocks 1
379+ wait_until_spent $ctx_id $htlc_output_index1
380+ new_blocks 1
381+ wait_for_balance alice 0.9995
382+ fi
383+
384+
311385if [[ $1 == " extract_preimage" ]]; then
312386 # Alice sends htlc1 to Bob. Bob sends htlc2 to Alice.
313387 # Neither one of them settles, they hold the htlcs, and Bob force-closes.
0 commit comments