routing: Add tracking of eviction for broadcasts

We should never be evicting channel_announcements because a) they were
deeply buried and should not change the short_channel_id/tag, b) they
are static.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2017-12-21 09:05:31 +01:00
parent 1b28220b64
commit 83caf1fdab
6 changed files with 13 additions and 8 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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