diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 81af0e8a2e13..6a1cb1aa5473 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -565,12 +565,16 @@ void resend_opening_transactions(struct lightningd *ld) peer = peer_node_id_map_next(ld->peers, &it)) { list_for_each(&peer->channels, channel, list) { struct wally_tx *wtx; - if (channel_state_uncommitted(channel->state)) + /* Only states where the funding/splice tx might + * still be unconfirmed. channel->depth can't be + * used here: it's reset to 0 on DB load and only + * repopulated once topology starts. */ + if (channel->state != CHANNELD_AWAITING_LOCKIN + && channel->state != DUALOPEND_AWAITING_LOCKIN + && channel->state != CHANNELD_AWAITING_SPLICE) continue; if (!channel->funding_psbt || channel->withheld) continue; - if (channel->depth != 0) - continue; wtx = psbt_final_tx(tmpctx, channel->funding_psbt); if (!wtx) continue; diff --git a/tests/test_opening.py b/tests/test_opening.py index 918e37bbda44..a272e711e85e 100644 --- a/tests/test_opening.py +++ b/tests/test_opening.py @@ -3018,3 +3018,19 @@ def test_zeroconf_withhold_htlc_failback(node_factory, bitcoind): # l1's channel to l2 is still normal — no force-close assert only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['state'] == 'CHANNELD_NORMAL' + + +@pytest.mark.openchannel('v1') +@pytest.mark.openchannel('v2') +def test_no_retransmit_confirmed_funding(node_factory): + """An channel must not trigger funding tx re-transmission on restart.""" + l1, _ = node_factory.line_graph(2, wait_for_announce=True) + + # Channel is in CHANNELD_NORMAL and funding tx is confirmed. + assert only_one(l1.rpc.listpeerchannels()['channels'])['state'] == 'CHANNELD_NORMAL' + + l1.restart() + + # Should not have attempted (and failed) to re-broadcast the funding tx. + assert not l1.daemon.is_in_log('Failed to re-transmit funding tx') + assert not l1.daemon.is_in_log('Successfully rexmitted funding tx')