From a071a754b3e81010193f9bf0693acf227c38a690 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 22 Sep 2019 11:51:34 +0930 Subject: [PATCH] gossipd: place limit on pending announcements. Now we queue them, we should place a limit. It's not the worst thing in the world if we discard them (we'll catch up eventually), but we should try not to in case we're just a bit behind. Our behaviour here is also O(n^2) so we don't want a massive queue anyway. Signed-off-by: Rusty Russell --- gossipd/routing.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gossipd/routing.c b/gossipd/routing.c index 37fd92cf8..64ae8a3d0 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1746,6 +1746,20 @@ u8 *handle_channel_announcement(struct routing_state *rstate, goto malformed; } + /* Don't add an infinite number of pending announcements. If we're + * catching up with the bitcoin chain, though, they can definitely + * pile up. */ + if (pending_cannouncement_map_count(&rstate->pending_cannouncements) + > 100000) { + static bool warned = false; + if (!warned) { + status_unusual("Flooded by channel_announcements:" + " ignoring some"); + warned = true; + } + goto ignored; + } + status_debug("Received channel_announcement for channel %s", type_to_string(tmpctx, struct short_channel_id, &pending->short_channel_id));