From f4a6986d72198a3ab4c889d0189a8c46c9232d46 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 8 Oct 2019 17:29:46 +1030 Subject: [PATCH] gossipd: remove unknown short_channel_ids as we ask for them. Otherwise we can get stuck asking for bogus ones over and over! Signed-off-by: Rusty Russell --- gossipd/seeker.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gossipd/seeker.c b/gossipd/seeker.c index b2c5b4e3e..df7b09b38 100644 --- a/gossipd/seeker.c +++ b/gossipd/seeker.c @@ -286,11 +286,11 @@ static void normal_gossip_start(struct seeker *seeker, struct peer *peer) disable_gossip_stream(seeker, peer); } -/* Turn unknown_scids map into a flat array. */ -static struct short_channel_id *unknown_scids_arr(const tal_t *ctx, - const struct seeker *seeker) +/* Turn unknown_scids map into a flat array, removes from map. */ +static struct short_channel_id *unknown_scids_remove(const tal_t *ctx, + struct seeker *seeker) { - const struct scid_map *map = &seeker->unknown_scids; + struct scid_map *map = &seeker->unknown_scids; struct short_channel_id *scids, *s; size_t i, max; struct scid_map_iter it; @@ -302,9 +302,11 @@ static struct short_channel_id *unknown_scids_arr(const tal_t *ctx, max = 8000; scids = tal_arr(ctx, struct short_channel_id, max); - i = 0; - for (s = scid_map_first(map, &it); i < max; s = scid_map_next(map, &it)) - scids[i++] = *s; + for (i = 0, s = scid_map_first(map, &it); i < max; i++) { + scids[i] = *s; + scid_map_del(map, s); + tal_free(s); + } assert(i == tal_count(scids)); return scids; } @@ -360,7 +362,7 @@ static bool seek_any_unknown_scids(struct seeker *seeker) set_state(seeker, ASKING_FOR_UNKNOWN_SCIDS); selected_peer(seeker, peer); - scids = unknown_scids_arr(tmpctx, seeker); + scids = unknown_scids_remove(tmpctx, seeker); if (!query_short_channel_ids(seeker->daemon, peer, scids, NULL, scid_query_done)) status_failed(STATUS_FAIL_INTERNAL_ERROR,