MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_zeroconf_withhold_htlc_failback

Function test_zeroconf_withhold_htlc_failback

tests/test_opening.py:3610–3673  ·  view source on GitHub ↗

Test that CLTV timeout on a withheld channel fails HTLCs back upstream without force-close.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

3608
3609
3610def test_zeroconf_withhold_htlc_failback(node_factory, bitcoind):
3611 """Test that CLTV timeout on a withheld channel fails HTLCs back upstream without force-close."""
3612 zeroconf_plugin = str(Path(__file__).parent / "plugins" / "zeroconf-selective.py")
3613 hold_plugin = str(Path(__file__).parent / "plugins" / "hold_htlcs.py")
3614
3615 l1, l2, l3 = node_factory.get_nodes(3, opts=[
3616 {},
3617 {},
3618 {'plugin': [zeroconf_plugin, hold_plugin],
3619 'zeroconf_allow': 'any',
3620 'hold-time': 10000},
3621 ])
3622
3623 # l1 -> l2: normal funded channel
3624 l1.fundwallet(10**7)
3625 l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
3626 l1.rpc.fundchannel(l2.info['id'], 1000000)
3627 bitcoind.generate_block(6, wait_for_mempool=1)
3628 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL')
3629 scid12 = only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['short_channel_id']
3630
3631 # l2 -> l3: withheld zeroconf channel
3632 l2.fundwallet(10**7)
3633 l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
3634 amount = 1000000
3635 funding_addr = l2.rpc.fundchannel_start(l3.info['id'], f"{amount}sat", mindepth=0)['funding_address']
3636 psbt = l2.rpc.fundpsbt(amount, "1000perkw", 1000, excess_as_change=True)['psbt']
3637 psbt = l2.rpc.addpsbtoutput(amount, psbt, destination=funding_addr)['psbt']
3638 assert l2.rpc.fundchannel_complete(l3.info['id'], psbt, withhold=True)['commitments_secured']
3639
3640 # Wait for withheld channel to be usable
3641 wait_for(lambda: 'remote' in only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['updates'])
3642 alias23 = only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['alias']['local']
3643
3644 # Create invoice on l3 and send payment from l1 via manual route
3645 inv = l3.rpc.invoice(10000, 'test_withhold_failback', 'desc')
3646 route = [{'amount_msat': 10001,
3647 'id': l2.info['id'],
3648 'delay': 12,
3649 'channel': scid12},
3650 {'amount_msat': 10000,
3651 'id': l3.info['id'],
3652 'delay': 6,
3653 'channel': alias23}]
3654 l1.rpc.sendpay(route, inv['payment_hash'], payment_secret=inv['payment_secret'])
3655
3656 # Wait for HTLC to be held at l3
3657 l3.daemon.wait_for_log("Holding onto an incoming htlc")
3658
3659 # Mine blocks to hit the CLTV deadline.
3660 bitcoind.generate_block(8)
3661
3662 # CLTV expiry triggers force-close on the withheld channel
3663 l2.daemon.wait_for_log(r'cltv .* hit deadline')
3664
3665 # Withheld channel is gone (no on-chain tx was broadcast)
3666 assert l2.rpc.listpeerchannels(l3.info['id'])['channels'] == []
3667

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
only_oneFunction · 0.90
get_nodesMethod · 0.80
fundwalletMethod · 0.80
generate_blockMethod · 0.80
listpeerchannelsMethod · 0.80
fundchannel_startMethod · 0.80
fundpsbtMethod · 0.80
addpsbtoutputMethod · 0.80
fundchannel_completeMethod · 0.80
sendpayMethod · 0.80
wait_for_logMethod · 0.80

Tested by

no test coverage detected