From 37dc458b4d95ee78ce0683cd1c76e90317baabae Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 30 May 2018 18:13:22 +0200 Subject: [PATCH] gossip: Have the broadcast_state track its message count This is far more precise than bolting on the stale tracking in the `gossip_store`. Signed-off-by: Christian Decker --- gossipd/broadcast.c | 3 +++ gossipd/broadcast.h | 1 + 2 files changed, 4 insertions(+) diff --git a/gossipd/broadcast.c b/gossipd/broadcast.c index 6bcb7afd1..d4a0c4b19 100644 --- a/gossipd/broadcast.c +++ b/gossipd/broadcast.c @@ -27,6 +27,7 @@ struct broadcast_state *new_broadcast_state(tal_t *ctx) uintmap_init(&bstate->broadcasts); /* Skip 0 because we initialize peers with 0 */ bstate->next_index = 1; + bstate->count = 0; return bstate; } @@ -43,6 +44,7 @@ static void destroy_queued_message(struct queued_message *msg, struct broadcast_state *bstate) { broadcast_del(bstate, msg->index, msg->payload); + bstate->count--; } static struct queued_message *new_queued_message(const tal_t *ctx, @@ -58,6 +60,7 @@ static struct queued_message *new_queued_message(const tal_t *ctx, msg->timestamp = timestamp; uintmap_add(&bstate->broadcasts, index, msg); tal_add_destructor2(msg, destroy_queued_message, bstate); + bstate->count++; return msg; } diff --git a/gossipd/broadcast.h b/gossipd/broadcast.h index 8be37fb40..d68011e83 100644 --- a/gossipd/broadcast.h +++ b/gossipd/broadcast.h @@ -12,6 +12,7 @@ struct broadcast_state { u64 next_index; UINTMAP(struct queued_message *) broadcasts; + size_t count; }; struct broadcast_state *new_broadcast_state(tal_t *ctx);