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

Function test_anchorspend_using_to_remote

tests/test_closing.py:4719–4793  ·  view source on GitHub ↗

Make sure we can use `to_remote` output of previous close to spend anchor

(node_factory, bitcoind, anchors)

Source from the content-addressed store, hash-verified

4717@pytest.mark.parametrize("anchors", [False, True])
4718@unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd')
4719def test_anchorspend_using_to_remote(node_factory, bitcoind, anchors):
4720 """Make sure we can use `to_remote` output of previous close to spend anchor"""
4721 # Try with old output from both anchor and non-anchor channel.
4722
4723 # We want l2 to process the WIRE_UPDATE_FULFILL_HTLC, so l4 drops
4724 # on WIRE_REVOKE_AND_ACK after that.
4725 l4_opts = {'disconnect': ['-WIRE_REVOKE_AND_ACK*2']}
4726 if anchors is False:
4727 l4_opts['dev-force-features'] = "-23"
4728
4729 l1, l2, l3, l4 = node_factory.get_nodes(4, opts=[{},
4730 {},
4731 {'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC']},
4732 l4_opts])
4733
4734 # Give l2 some funds, from a to-remote output. It will have to spend
4735 # this to use anchor.
4736 node_factory.join_nodes([l4, l2])
4737
4738 # l4 disconnects after receiving fulfill. It then unilaterally
4739 # closes, l2 gets to-remote with its output.
4740 l4.rpc.xpay(l2.rpc.invoice(100000000, 'test', 'test')['bolt11'])
4741 wait_for(lambda: only_one(l4.rpc.listpeerchannels()['channels'])['htlcs'] != [])
4742
4743 wait_for(lambda: only_one(l4.rpc.listpeers()['peers'])['connected'] is False)
4744 close = l4.rpc.close(l2.info['id'], 1)
4745 bitcoind.generate_block(1, wait_for_mempool=only_one(close['txids']))
4746 wait_for(lambda: len(l2.rpc.listfunds()['outputs']) == 1)
4747 # Don't need l4 any more
4748 l4.stop()
4749
4750 for n in (l1, l2, l3):
4751 wait_for(lambda: n.rpc.listchannels() == {'channels': []})
4752
4753 # Now l1->l2<-l3 but push funds to l2 so it can forward.
4754 node_factory.join_nodes([l1, l2])
4755 node_factory.join_nodes([l3, l2])
4756
4757 # Make sure everyone knows about everyone else!
4758 bitcoind.generate_block(5)
4759 for n in (l1, l2, l3):
4760 wait_for(lambda: len(n.rpc.listchannels()['channels']) == 4)
4761
4762 l3.rpc.xpay(l2.rpc.invoice(200000000, 'test2', 'test2')['bolt11'])
4763 wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['htlcs'] == [])
4764
4765 # Get HTLC stuck, so l2 has reason to push commitment tx.
4766 amt = 100_000_000
4767 sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky')
4768 route = l1.single_route(l3.info['id'], amt)
4769 l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret'])
4770 l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC')
4771
4772 # Give l2 a sense of urgency, by ensuring there's an HTLC in-channel
4773 # when it needs to go onchain.
4774 # Make sure HTLC expiry is what we expect!
4775 l2.daemon.wait_for_log('Adding HTLC 0 amount=100000000msat cltv=123 gave CHANNEL_ERR_ADD_OK')
4776

Callers

nothing calls this directly

Calls 15

wait_forFunction · 0.90
only_oneFunction · 0.90
sync_blockheightFunction · 0.90
get_nodesMethod · 0.80
join_nodesMethod · 0.80
listpeerchannelsMethod · 0.80
generate_blockMethod · 0.80
single_routeMethod · 0.80
sendpayMethod · 0.80
wait_for_logMethod · 0.80
wait_for_logsMethod · 0.80
xpayMethod · 0.45

Tested by

no test coverage detected