Interrupt a payment between two peers, then fail and recover funds using the HTLC sig.
(node_factory, bitcoind, executor, chainparams)
| 386 | |
| 387 | |
| 388 | def test_htlc_sig_persistence(node_factory, bitcoind, executor, chainparams): |
| 389 | """Interrupt a payment between two peers, then fail and recover funds using the HTLC sig. |
| 390 | """ |
| 391 | # Feerates identical so we don't get gratuitous commit to update them |
| 392 | l1 = node_factory.get_node(options={'dev-no-reconnect': None}, |
| 393 | feerates=(7500, 7500, 7500, 7500)) |
| 394 | l2 = node_factory.get_node(disconnect=['+WIRE_COMMITMENT_SIGNED']) |
| 395 | |
| 396 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 397 | l1.fundchannel(l2, 10**6) |
| 398 | f = executor.submit(l1.pay, l2, 31337000) |
| 399 | l1.daemon.wait_for_log(r'HTLC out 0 RCVD_ADD_ACK_COMMIT->SENT_ADD_ACK_REVOCATION') |
| 400 | l1.stop() |
| 401 | |
| 402 | # `pay` call is lost |
| 403 | with pytest.raises(RpcError): |
| 404 | f.result() |
| 405 | |
| 406 | # We should have the HTLC sig |
| 407 | assert(len(l1.db_query("SELECT * FROM htlc_sigs;")) == 1) |
| 408 | |
| 409 | # This should reload the htlc_sig |
| 410 | l2.rpc.dev_fail(l1.info['id']) |
| 411 | # Make sure it broadcasts to chain. |
| 412 | l2.wait_for_channel_onchain(l1.info['id']) |
| 413 | l2.stop() |
| 414 | bitcoind.generate_block(1) |
| 415 | l1.start() |
| 416 | |
| 417 | assert l1.daemon.is_in_log(r'Loaded 1 HTLC signatures from DB') |
| 418 | |
| 419 | # Could happen in either order! |
| 420 | l1.daemon.wait_for_log(r'Peer permanent failure in CHANNELD_NORMAL: Funding transaction spent') |
| 421 | |
| 422 | _, txid, blocks = l1.wait_for_onchaind_tx('OUR_HTLC_TIMEOUT_TO_US', |
| 423 | 'THEIR_UNILATERAL/OUR_HTLC') |
| 424 | assert blocks == 5 |
| 425 | |
| 426 | bitcoind.generate_block(5) |
| 427 | bitcoind.generate_block(1, wait_for_mempool=txid) |
| 428 | outtype = 'p2tr' if not chainparams['elements'] else 'p2wpkh' |
| 429 | l1.daemon.wait_for_logs([ |
| 430 | rf'Owning output . (\d+)sat \({outtype}\) txid {txid} CONFIRMED', |
| 431 | ]) |
| 432 | |
| 433 | # We should now have 1) the unilateral to us, and b) the HTLC respend to us |
| 434 | # and maybe (c) change. |
| 435 | assert 2 <= len(l1.rpc.listfunds()['outputs']) <= 3 |
| 436 | |
| 437 | |
| 438 | def test_htlc_out_timeout(node_factory, bitcoind, executor): |
nothing calls this directly
no test coverage detected