Test that we drop onchain if the peer doesn't time out HTLC
(node_factory, bitcoind, executor)
| 436 | |
| 437 | |
| 438 | def test_htlc_out_timeout(node_factory, bitcoind, executor): |
| 439 | """Test that we drop onchain if the peer doesn't time out HTLC""" |
| 440 | |
| 441 | # HTLC 1->2, 1 fails after it's irrevocably committed, can't reconnect |
| 442 | disconnects = ['-WIRE_REVOKE_AND_ACK'] |
| 443 | # Feerates identical so we don't get gratuitous commit to update them |
| 444 | l1 = node_factory.get_node(disconnect=disconnects, |
| 445 | options={'dev-no-reconnect': None}, |
| 446 | feerates=(7500, 7500, 7500, 7500)) |
| 447 | l2 = node_factory.get_node() |
| 448 | |
| 449 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 450 | chanid, _ = l1.fundchannel(l2, 10**6) |
| 451 | |
| 452 | amt = 200000000 |
| 453 | inv = l2.rpc.invoice(amt, 'test_htlc_out_timeout', 'desc')['bolt11'] |
| 454 | assert only_one(l2.rpc.listinvoices('test_htlc_out_timeout')['invoices'])['status'] == 'unpaid' |
| 455 | |
| 456 | executor.submit(l1.rpc.xpay, inv) |
| 457 | |
| 458 | # l1 will disconnect, and not reconnect. |
| 459 | l1.daemon.wait_for_log('dev_disconnect: -WIRE_REVOKE_AND_ACK') |
| 460 | |
| 461 | bitcoind.generate_block(5 + 1) |
| 462 | time.sleep(3) |
| 463 | assert not l1.daemon.is_in_log('hit deadline') |
| 464 | bitcoind.generate_block(1) |
| 465 | |
| 466 | l1.daemon.wait_for_log('Offered HTLC 0 SENT_ADD_ACK_REVOCATION cltv .* hit deadline') |
| 467 | l1.daemon.wait_for_log('sendrawtx exit 0') |
| 468 | l1.bitcoin.generate_block(1) |
| 469 | l1.daemon.wait_for_log(' to ONCHAIN') |
| 470 | l2.daemon.wait_for_log(' to ONCHAIN') |
| 471 | |
| 472 | # L1 will timeout HTLC immediately |
| 473 | ((_, _, blocks1), (_, txid, blocks2)) = \ |
| 474 | l1.wait_for_onchaind_txs(('OUR_DELAYED_RETURN_TO_WALLET', |
| 475 | 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US'), |
| 476 | ('OUR_HTLC_TIMEOUT_TX', |
| 477 | 'OUR_UNILATERAL/OUR_HTLC')) |
| 478 | assert blocks1 == 4 |
| 479 | # We hit deadline (we give 1 block grace), then mined another. |
| 480 | assert blocks2 == -2 |
| 481 | |
| 482 | # If we try to reuse the same output as we used for the anchor spend, then |
| 483 | # bitcoind can reject it. In that case we'll try again after we get change |
| 484 | # from anchor spend. |
| 485 | if txid not in bitcoind.rpc.getrawmempool(): |
| 486 | bitcoind.generate_block(1) |
| 487 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 488 | else: |
| 489 | bitcoind.generate_block(1) |
| 490 | |
| 491 | rawtx, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET', |
| 492 | 'OUR_HTLC_TIMEOUT_TX/DELAYED_OUTPUT_TO_US') |
| 493 | assert blocks == 4 |
| 494 | bitcoind.generate_block(4) |
| 495 |
nothing calls this directly
no test coverage detected