diff --git a/channeld/channel.c b/channeld/channel.c index 094958737..daf498a92 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -1940,6 +1940,10 @@ static void handle_funding_locked(struct peer *peer, const u8 *msg) static void handle_funding_announce_depth(struct peer *peer) { + /* This can happen if we got told already at init time */ + if (peer->announce_depth_reached) + return; + peer->announce_depth_reached = true; send_announcement_signatures(peer); @@ -2449,7 +2453,8 @@ static void init_channel(struct peer *peer) &peer->shutdown_sent[REMOTE], &peer->final_scriptpubkey, &peer->channel_flags, - &funding_signed)) + &funding_signed, + &peer->announce_depth_reached)) master_badmsg(WIRE_CHANNEL_INIT, msg); status_trace("init %s: remote_per_commit = %s, old_remote_per_commit = %s" @@ -2516,6 +2521,10 @@ static void init_channel(struct peer *peer) if (funding_signed) enqueue_peer_msg(peer, take(funding_signed)); + /* It's possible that we died previously before doing these. */ + send_temporary_announcement(peer); + send_announcement_signatures(peer); + billboard_update(peer); tal_free(msg); } diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 75d5af20c..d7ff88496 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -58,6 +58,7 @@ channel_init,,final_scriptpubkey,final_scriptpubkey_len*u8 channel_init,,flags,u8 channel_init,,init_peer_pkt_len,u16 channel_init,,init_peer_pkt,init_peer_pkt_len*u8 +channel_init,,reached_announce_depth,bool # Tx is deep enough, go! channel_funding_locked,1002 diff --git a/gossipd/routing.c b/gossipd/routing.c index e87eaaed4..3d2ef944e 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1516,8 +1516,9 @@ void handle_local_add_channel(struct routing_state *rstate, u8 *msg) return; } + /* Can happen on channeld restart. */ if (get_channel(rstate, &scid)) { - status_broken("Attempted to local_add_channel a known channel"); + status_trace("Attempted to local_add_channel a known channel"); return; } diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 2c0f71b55..6bc694e7c 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -186,6 +186,7 @@ bool peer_start_channeld(struct channel *channel, u64 num_revocations; struct lightningd *ld = channel->peer->ld; const struct config *cfg = &ld->config; + bool reached_announce_depth; msg = towire_hsm_client_hsmfd(tmpctx, &channel->peer->id, HSM_CAP_SIGN_GOSSIP | HSM_CAP_ECDH); if (!wire_sync_write(ld->hsm_fd, take(msg))) @@ -223,10 +224,16 @@ bool peer_start_channeld(struct channel *channel, if (channel->scid) { funding_channel_id = *channel->scid; - log_debug(channel->log, "Already have funding locked in"); + reached_announce_depth + = (short_channel_id_blocknum(&funding_channel_id) + + ANNOUNCE_MIN_DEPTH <= get_block_height(ld->topology)); + log_debug(channel->log, "Already have funding locked in%s", + reached_announce_depth + ? " (and ready to announce)" : ""); } else { log_debug(channel->log, "Waiting for funding confirmations"); memset(&funding_channel_id, 0, sizeof(funding_channel_id)); + reached_announce_depth = false; } num_revocations = revocations_received(&channel->their_shachain.chain); @@ -281,7 +288,8 @@ bool peer_start_channeld(struct channel *channel, p2wpkh_for_keyidx(tmpctx, ld, channel->final_key_idx), channel->channel_flags, - funding_signed); + funding_signed, + reached_announce_depth); /* We don't expect a response: we are triggered by funding_depth_cb. */ subd_send_msg(channel->owner, take(initmsg));