From 97c7ba2f801cab13224bd05bc4e3c50e866b9e10 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 4 Sep 2018 14:52:47 +0930 Subject: [PATCH] gossipd: fix reordering of node_announcements in presence of a unannounced channel. If we receive a channel_announce but not a channel_update, we store the announce but don't put it in the broadcast map. When we delete a channel, we check if the node_announcement broadcast now preceeds all channel_announcements, and if so, we move it to the end of the map. However, with a channel_announcement at index '0', this test fails. This is at least one potential cause of the node map getting out of order. Signed-off-by: Rusty Russell --- gossipd/routing.c | 2 +- gossipd/routing.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gossipd/routing.c b/gossipd/routing.c index 619dd921a..a0ab36a80 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -199,7 +199,7 @@ static bool remove_channel_from_array(struct chan ***chans, const struct chan *c static bool node_announce_predates_channels(const struct node *node) { for (size_t i = 0; i < tal_count(node->chans); i++) { - if (!is_chan_public(node->chans[i])) + if (!is_chan_announced(node->chans[i])) continue; if (node->chans[i]->channel_announcement_index diff --git a/gossipd/routing.h b/gossipd/routing.h index 1631498bb..f8552611e 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -61,11 +61,19 @@ struct chan { u64 satoshis; }; +/* A local channel can exist which isn't announcable. */ static inline bool is_chan_public(const struct chan *chan) { return chan->channel_announce != NULL; } +/* A channel is only announced once we have a channel_update to send + * with it. */ +static inline bool is_chan_announced(const struct chan *chan) +{ + return chan->channel_announcement_index != 0; +} + static inline bool is_halfchan_defined(const struct half_chan *hc) { return hc->channel_update != NULL;