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 <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-05-30 18:13:22 +02:00
parent eab2a62894
commit 37dc458b4d
2 changed files with 4 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);