diff --git a/gossipd/broadcast.c b/gossipd/broadcast.c index 8fc02eefb..4721858f0 100644 --- a/gossipd/broadcast.c +++ b/gossipd/broadcast.c @@ -21,13 +21,14 @@ static struct queued_message *new_queued_message(tal_t *ctx, return msg; } -void queue_broadcast(struct broadcast_state *bstate, +bool queue_broadcast(struct broadcast_state *bstate, const int type, const u8 *tag, const u8 *payload) { struct queued_message *msg; u64 index; + bool evicted = false; /* Remove any tag&type collisions */ for (msg = uintmap_first(&bstate->broadcasts, &index); @@ -36,6 +37,8 @@ void queue_broadcast(struct broadcast_state *bstate, if (msg->type == type && memcmp(msg->tag, tag, tal_count(tag)) == 0) { uintmap_del(&bstate->broadcasts, index); tal_free(msg); + evicted = true; + break; } } @@ -43,6 +46,7 @@ void queue_broadcast(struct broadcast_state *bstate, msg = new_queued_message(bstate, type, tag, payload); uintmap_add(&bstate->broadcasts, bstate->next_index, msg); bstate->next_index += 1; + return evicted; } struct queued_message *next_broadcast_message(struct broadcast_state *bstate, u64 last_index) diff --git a/gossipd/broadcast.h b/gossipd/broadcast.h index baa561d4f..cb8747d61 100644 --- a/gossipd/broadcast.h +++ b/gossipd/broadcast.h @@ -29,8 +29,9 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx); /* Queue a new message to be broadcast and replace any outdated * broadcast. Replacement is done by comparing the `type` and the * `tag`, if both match the old message is dropped from the queue. The - * new message is added to the top of the broadcast queue. */ -void queue_broadcast(struct broadcast_state *bstate, + * new message is added to the top of the broadcast queue. Returns + * true if a previous entry with the same tag has been evicted. */ +bool queue_broadcast(struct broadcast_state *bstate, const int type, const u8 *tag, const u8 *payload); diff --git a/gossipd/routing.c b/gossipd/routing.c index d23c40d90..b61a61c59 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -580,8 +580,8 @@ bool handle_channel_announcement( u8 *tag = tal_arr(tmpctx, u8, 0); towire_short_channel_id(&tag, &short_channel_id); - queue_broadcast(rstate->broadcasts, WIRE_CHANNEL_ANNOUNCEMENT, - tag, serialized); + assert(!queue_broadcast(rstate->broadcasts, WIRE_CHANNEL_ANNOUNCEMENT, + tag, serialized)); tal_free(tmpctx); return local; diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 006048d2d..81d3c5a90 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -64,7 +64,7 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } /* Generated stub for queue_broadcast */ -void queue_broadcast(struct broadcast_state *bstate UNNEEDED, +bool queue_broadcast(struct broadcast_state *bstate UNNEEDED, const int type UNNEEDED, const u8 *tag UNNEEDED, const u8 *payload UNNEEDED) diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 42fa9a4f3..49f70f1f3 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -35,7 +35,7 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } /* Generated stub for queue_broadcast */ -void queue_broadcast(struct broadcast_state *bstate UNNEEDED, +bool queue_broadcast(struct broadcast_state *bstate UNNEEDED, const int type UNNEEDED, const u8 *tag UNNEEDED, const u8 *payload UNNEEDED) diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index dc244763a..97b740370 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -28,7 +28,7 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } /* Generated stub for queue_broadcast */ -void queue_broadcast(struct broadcast_state *bstate UNNEEDED, +bool queue_broadcast(struct broadcast_state *bstate UNNEEDED, const int type UNNEEDED, const u8 *tag UNNEEDED, const u8 *payload UNNEEDED)