Test that we use anchor on peer's commit to CPFP tx
(node_factory, bitcoind, executor, chainparams)
| 4535 | |
| 4536 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd anchors not supportd') |
| 4537 | def test_peer_anchor_push(node_factory, bitcoind, executor, chainparams): |
| 4538 | """Test that we use anchor on peer's commit to CPFP tx""" |
| 4539 | l1, l2, l3 = node_factory.line_graph(3, opts=[{}, |
| 4540 | {'min-emergency-msat': 546000, |
| 4541 | 'dev-warn-on-overgrind': None, |
| 4542 | 'broken_log': 'overgrind: short signature length'}, |
| 4543 | {'disconnect': ['-WIRE_UPDATE_FULFILL_HTLC'], |
| 4544 | 'dev-warn-on-overgrind': None, |
| 4545 | 'broken_log': 'overgrind: short signature length'}], |
| 4546 | wait_for_announce=True) |
| 4547 | |
| 4548 | # We splinter l2's funds so it's forced to use more than one UTXO to push. |
| 4549 | fundsats = int(Millisatoshi(only_one(l2.rpc.listfunds()['outputs'])['amount_msat']).to_satoshi()) |
| 4550 | OUTPUT_SAT = 10000 |
| 4551 | NUM_OUTPUTS = 10 |
| 4552 | psbt = l2.rpc.fundpsbt("all", "1000perkw", 1000)['psbt'] |
| 4553 | # Pay 5k sats in fees. |
| 4554 | psbt = l2.rpc.addpsbtoutput(fundsats - OUTPUT_SAT * NUM_OUTPUTS - 5000, psbt, destination=l3.rpc.newaddr()['p2tr'])['psbt'] |
| 4555 | for _ in range(NUM_OUTPUTS): |
| 4556 | psbt = l2.rpc.addpsbtoutput(OUTPUT_SAT, psbt)['psbt'] |
| 4557 | l2.rpc.sendpsbt(l2.rpc.signpsbt(psbt)['signed_psbt']) |
| 4558 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 4559 | sync_blockheight(bitcoind, [l1, l2]) |
| 4560 | |
| 4561 | # Make sure all amounts are below OUTPUT_SAT sats! |
| 4562 | assert [x for x in l2.rpc.listfunds()['outputs'] if x['amount_msat'] > Millisatoshi(str(OUTPUT_SAT) + "sat")] == [] |
| 4563 | |
| 4564 | # Get HTLC stuck, so l2 has reason to push commitment tx. |
| 4565 | amt = 100_000_000 |
| 4566 | sticky_inv = l3.rpc.invoice(amt, 'sticky', 'sticky') |
| 4567 | route = l1.single_route(l3.info['id'], amt) |
| 4568 | l1.rpc.sendpay(route, sticky_inv['payment_hash'], payment_secret=sticky_inv['payment_secret']) |
| 4569 | l3.daemon.wait_for_log('dev_disconnect: -WIRE_UPDATE_FULFILL_HTLC') |
| 4570 | |
| 4571 | # Make sure HTLC expiry is what we expect! |
| 4572 | l2.daemon.wait_for_log('Adding HTLC 0 amount=100000000msat cltv=119 gave CHANNEL_ERR_ADD_OK') |
| 4573 | |
| 4574 | # l3 drops to chain, but make sure it doesn't CPFP its own anchor. |
| 4575 | wait_for(lambda: only_one(l3.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] != []) |
| 4576 | closetx = l3.rpc.dev_sign_last_tx(l2.info['id'])['tx'] |
| 4577 | l3.stop() |
| 4578 | # We don't care about l1 any more, either |
| 4579 | l1.stop() |
| 4580 | |
| 4581 | # We put l3's tx in the mempool, but won't mine it. |
| 4582 | bitcoind.rpc.sendrawtransaction(closetx) |
| 4583 | |
| 4584 | # We aim for feerate ~3750, so this won't mine l3's unilateral close. |
| 4585 | # HTLC's going to time out at block 120 (we give one block grace) |
| 4586 | for block in range(110, 120): |
| 4587 | bitcoind.generate_block(1, needfeerate=5000) |
| 4588 | assert bitcoind.rpc.getblockcount() == block |
| 4589 | sync_blockheight(bitcoind, [l2]) |
| 4590 | assert only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL' |
| 4591 | |
| 4592 | # Drops to chain |
| 4593 | bitcoind.generate_block(1, needfeerate=5000) |
| 4594 | wait_for(lambda: only_one(l2.rpc.listpeerchannels(l3.info['id'])['channels'])['state'] == 'AWAITING_UNILATERAL') |
nothing calls this directly
no test coverage detected