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

Function test_permfail

tests/test_closing.py:3551–3636  ·  view source on GitHub ↗
(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

3549
3550
3551def test_permfail(node_factory, bitcoind):
3552 l1, l2 = node_factory.line_graph(2)
3553
3554 # The funding change should be confirmed and our only output
3555 assert [o['status'] for o in l1.rpc.listfunds()['outputs']] == ['confirmed']
3556 l1.pay(l2, 200000000)
3557
3558 # Make sure l2 has received sig with 0 htlcs!
3559 l2.daemon.wait_for_log('Received commit_sig with 1 htlc sigs')
3560 l2.daemon.wait_for_log('Received commit_sig with 0 htlc sigs')
3561
3562 # Make sure l1 has final revocation.
3563 l1.daemon.wait_for_log('Sending commit_sig with 1 htlc sigs')
3564 l1.daemon.wait_for_log('Sending commit_sig with 0 htlc sigs')
3565 l1.daemon.wait_for_log('peer_in WIRE_REVOKE_AND_ACK')
3566
3567 # We fail l2, so l1 will reconnect to it.
3568 l2.rpc.dev_fail(l1.info['id'])
3569 l2.daemon.wait_for_log('Failing due to dev-fail command')
3570 l2.wait_for_channel_onchain(l1.info['id'])
3571
3572 assert l1.bitcoin.rpc.getmempoolinfo()['size'] == 1
3573
3574 # Now grab the close transaction
3575 closetxid = only_one(l1.bitcoin.rpc.getrawmempool(False))
3576
3577 # l2 will send out tx (l1 considers it a transient error)
3578 bitcoind.generate_block(1)
3579
3580 l1.daemon.wait_for_log('Their unilateral tx, old commit point')
3581 l1.daemon.wait_for_log(' to ONCHAIN')
3582 l2.daemon.wait_for_log(' to ONCHAIN')
3583 _, txid, blocks = l2.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
3584 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
3585 assert blocks == 4
3586
3587 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['status']
3588 == ['ONCHAIN:Tracking their unilateral close',
3589 'ONCHAIN:All outputs resolved: waiting 99 more blocks before forgetting channel'])
3590
3591 def check_billboard():
3592 billboard = only_one(l2.rpc.listpeerchannels(l1.info['id'])['channels'])['status']
3593 return (
3594 len(billboard) == 2
3595 and billboard[0] == 'ONCHAIN:Tracking our own unilateral close'
3596 and re.fullmatch(r'ONCHAIN:.* outputs unresolved: in 4 blocks will spend DELAYED_OUTPUT_TO_US \(.*:.*\) using OUR_DELAYED_RETURN_TO_WALLET', billboard[1])
3597 )
3598 wait_for(check_billboard)
3599
3600 # Now, mine 4 blocks so it sends out the spending tx.
3601 bitcoind.generate_block(4)
3602
3603 # onchaind notes to-local payment immediately.
3604 assert (closetxid, "confirmed") in set([(o['txid'], o['status']) for o in l1.rpc.listfunds()['outputs']])
3605
3606 # Restart, should still be confirmed (fails: unwinding blocks erases
3607 # the confirmation, and we don't re-make it).
3608 l1.restart()

Callers

nothing calls this directly

Calls 15

only_oneFunction · 0.90
wait_forFunction · 0.90
scriptpubkey_addrFunction · 0.90
line_graphMethod · 0.80
wait_for_logMethod · 0.80
dev_failMethod · 0.80
generate_blockMethod · 0.80
wait_for_onchaind_txMethod · 0.80
listpeerchannelsMethod · 0.80
restartMethod · 0.80
listfundsMethod · 0.45

Tested by

no test coverage detected