From 33af030c65d80ed157fd3a375846309754eb42ab Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 9 Feb 2024 16:18:21 +1030 Subject: [PATCH] lightningd: don't force state if gossipd gives us an unexpected channel_update. This was triggered by the recover plugin tests (not yet merged!) and causes a crash because we don't have signatures yet. It can only happen if we lost our database, but at least don't crash! Signed-off-by: Rusty Russell --- lightningd/channel_gossip.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lightningd/channel_gossip.c b/lightningd/channel_gossip.c index a7f123d1f415..95e4a81e09a4 100644 --- a/lightningd/channel_gossip.c +++ b/lightningd/channel_gossip.c @@ -28,6 +28,23 @@ enum channel_gossip_state { CGOSSIP_ANNOUNCED, }; +static const char *channel_gossip_state_str(enum channel_gossip_state s) +{ + switch (s) { + case CGOSSIP_PRIVATE: + return "CGOSSIP_PRIVATE"; + case CGOSSIP_NOT_USABLE: + return "CGOSSIP_NOT_USABLE"; + case CGOSSIP_NOT_DEEP_ENOUGH: + return "CGOSSIP_NOT_DEEP_ENOUGH"; + case CGOSSIP_NEED_PEER_SIGS: + return "CGOSSIP_NEED_PEER_SIGS"; + case CGOSSIP_ANNOUNCED: + return "CGOSSIP_ANNOUNCED"; + } + return "***INVALID***"; +} + struct remote_announce_sigs { struct short_channel_id scid; secp256k1_ecdsa_signature node_sig; @@ -774,7 +791,7 @@ void channel_gossip_update_from_gossipd(struct channel *channel, return; } - /* If we didn't think it was announced already, it is now! */ + /* We might still want signatures from peer (we lost state?) */ switch (channel->channel_gossip->state) { case CGOSSIP_PRIVATE: log_broken(channel->log, @@ -784,8 +801,12 @@ void channel_gossip_update_from_gossipd(struct channel *channel, case CGOSSIP_NOT_USABLE: case CGOSSIP_NOT_DEEP_ENOUGH: case CGOSSIP_NEED_PEER_SIGS: - set_gossip_state(channel, CGOSSIP_ANNOUNCED); - break; + if (taken(channel_update)) + tal_free(channel_update); + log_broken(channel->log, + "gossipd gave us channel_update for channel in gossip_state %s", + channel_gossip_state_str(channel->channel_gossip->state)); + return; case CGOSSIP_ANNOUNCED: break; }