Test that we use anchor on peer's commit to CPFP tx
(node_factory, bitcoind, executor, chainparams)
| 3997 | |
| 3998 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd') |
| 3999 | def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams): |
| 4000 | """Test that we use anchor on peer's commit to CPFP tx""" |
| 4001 | l1, l2, l3 = node_factory.line_graph(3, opts=[{}, |
| 4002 | {'min-emergency-msat': 546000, |
| 4003 | 'dev-warn-on-overgrind': None, |
| 4004 | 'broken_log': 'overgrind: short signature length'}, |
| 4005 | {'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC'], |
| 4006 | 'dev-warn-on-overgrind': None, |
| 4007 | 'broken_log': 'overgrind: short signature length'}], |
| 4008 | wait_for_announce=True) |
| 4009 | |
| 4010 | # We splinter l2's funds so it's forced to use more than one UTXO to push. |
| 4011 | fundsats = int(Millisatoshi(only_one(l2.rpc.listfunds()['outputs'])['amount_msat']).to_satoshi()) |
| 4012 | OUTPUT_SAT = 10000 |
| 4013 | NUM_OUTPUTS = 10 |
| 4014 | psbt = l2.rpc.fundpsbt("all", "1000perkw", 1000)['psbt'] |
| 4015 | # Pay 5k sats in fees. |
| 4016 | psbt = l2.rpc.addpsbtoutput(fundsats - OUTPUT_SAT * NUM_OUTPUTS - 5000, psbt, destination=l3.rpc.newaddr()['p2tr'])['psbt'] |
| 4017 | for _ in range(NUM_OUTPUTS): |
| 4018 | psbt = l2.rpc.addpsbtoutput(OUTPUT_SAT, psbt)['psbt'] |
| 4019 | l2.rpc.sendpsbt(l2.rpc.signpsbt(psbt)['signed_psbt']) |
| 4020 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 4021 | sync_blockheight(bitcoind, [l1, l2]) |
| 4022 | |
| 4023 | # Make sure all amounts are below OUTPUT_SAT sats! |
| 4024 | assert [x for x in l2.rpc.listfunds()['outputs'] if x['amount_msat'] > Millisatoshi(str(OUTPUT_SAT) + "sat")] == [] |
| 4025 | |
| 4026 | # Get HTLC stuck, so l2 has reason to push commitment tx. |
| 4027 | amt = 100_000_000 |
| 4028 | sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky') |
| 4029 | route = l1.single_route(l3.info['id'], amt) |
| 4030 | l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret']) |
| 4031 | l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC') |
| 4032 | |
| 4033 | # Make sure HTLC expiry is what we expect! |
| 4034 | l2.daemon.wait_for_log('Adding HTLC 0 amount=100000000msat cltv=119 gave CHANNEL_ERR_ADD_OK') |
| 4035 | |
| 4036 | # l3 drops to chain, but make sure it doesn't CPFP its own anchor. |
| 4037 | wait_for(lambda: only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] != []) |
| 4038 | closetx = l3.rpc.dev_sign_last_tx(l2.info['id'])['tx'] |
| 4039 | l3.stop() |
| 4040 | # We don't care about l1 any more, either |
| 4041 | l1.stop() |
| 4042 | |
| 4043 | # We put l3's tx in the mempool, but won't mine it. |
| 4044 | bitcoind.rpc.sendrawtransaction(closetx) |
| 4045 | |
| 4046 | # We aim for feerate ~3750, so this won't mine l3's unilateral close. |
| 4047 | # HTLC's going to time out at block 120 (we give one block grace) |
| 4048 | for block in range(110, 120): |
| 4049 | bitcoind.generate_block(1, needfeerate=5000) |
| 4050 | assert bitcoind.rpc.getblockcount() == block |
| 4051 | sync_blockheight(bitcoind, [l2]) |
| 4052 | assert only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL' |
| 4053 | |
| 4054 | # Drops to chain |
| 4055 | bitcoind.generate_block(1, needfeerate=5000) |
| 4056 | wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL') |
nothing calls this directly
no test coverage detected