An HTLC that hits its deadline while the channel is quiescent (STFU) must still force-close and get timed out onchain.
(node_factory, bitcoind)
| 5008 | |
| 5009 | |
| 5010 | def test_htlc_timeout_during_stfu(node_factory, bitcoind): |
| 5011 | # Originally authored by claude-fable-5 v2.1.228 (Claude Code) |
| 5012 | """An HTLC that hits its deadline while the channel is quiescent (STFU) |
| 5013 | must still force-close and get timed out onchain.""" |
| 5014 | plugin = os.path.join(os.getcwd(), 'tests/plugins/hold_htlcs.py') |
| 5015 | |
| 5016 | # Pin feerates so no update_fee sneaks in and blocks quiescence. |
| 5017 | # l2 holds any incoming HTLC (hook sleeps), so it stays committed |
| 5018 | # but unresolved while we mine past its expiry. |
| 5019 | l1, l2 = node_factory.line_graph(2, opts=[{'dev-no-reconnect': None, |
| 5020 | 'feerates': (7500, 7500, 7500, 7500)}, |
| 5021 | {'dev-no-reconnect': None, |
| 5022 | 'feerates': (7500, 7500, 7500, 7500), |
| 5023 | 'plugin': plugin, |
| 5024 | 'hold-time': 10000, |
| 5025 | 'hold-result': 'continue'}]) |
| 5026 | |
| 5027 | amt = 200000000 |
| 5028 | inv = l2.rpc.invoice(amt, 'stfu_timeout', 'desc') |
| 5029 | |
| 5030 | # Explicit route: fixed delay, no shadow-route randomness. |
| 5031 | route = [{'amount_msat': amt, |
| 5032 | 'id': l2.info['id'], |
| 5033 | 'delay': 10, |
| 5034 | 'channel': first_scid(l1, l2)}] |
| 5035 | l1.rpc.sendpay(route, inv['payment_hash'], |
| 5036 | payment_secret=inv['payment_secret']) |
| 5037 | |
| 5038 | # htlc_accepted hook fires only once the HTLC is irrevocably |
| 5039 | # committed on both sides, so this means it's fully locked in. |
| 5040 | l2.daemon.wait_for_log('Holding onto an incoming htlc') |
| 5041 | |
| 5042 | # Now go quiescent. A committed-but-unresolved HTLC is not a |
| 5043 | # "pending update", so STFU completes. |
| 5044 | l1.rpc.call('dev-quiesce', [l2.info['id']]) |
| 5045 | l1.daemon.wait_for_log('STFU complete: we are quiescent') |
| 5046 | l2.daemon.wait_for_log('STFU complete: we are quiescent') |
| 5047 | |
| 5048 | # lightningd fails the channel at height == expiry + 1 (htlc_out_deadline). |
| 5049 | htlc = only_one(l1.rpc.listhtlcs()['htlcs']) |
| 5050 | deadline = htlc['expiry'] + 1 |
| 5051 | |
| 5052 | # One block short of the deadline: still quiet. |
| 5053 | bitcoind.generate_block(deadline - bitcoind.rpc.getblockcount() - 1) |
| 5054 | sync_blockheight(bitcoind, [l1, l2]) |
| 5055 | time.sleep(3) |
| 5056 | assert not l1.daemon.is_in_log('hit deadline') |
| 5057 | assert only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL' |
| 5058 | |
| 5059 | # The deadline block: l1 drops to chain despite being in STFU. |
| 5060 | bitcoind.generate_block(1) |
| 5061 | l1.daemon.wait_for_log('Offered HTLC 0 SENT_ADD_ACK_REVOCATION cltv {} hit deadline' |
| 5062 | .format(htlc['expiry'])) |
| 5063 | l1.daemon.wait_for_log('sendrawtx exit 0') |
| 5064 | |
| 5065 | # Mine the commitment (anchors may add a CPFP tx alongside it). |
| 5066 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 5067 | l1.daemon.wait_for_log(' to ONCHAIN') |
nothing calls this directly
no test coverage detected