Browse Source

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>
ppa-0.6.1
Christian Decker 7 years ago
parent
commit
83caf1fdab
  1. 6
      gossipd/broadcast.c
  2. 5
      gossipd/broadcast.h
  3. 4
      gossipd/routing.c
  4. 2
      gossipd/test/run-bench-find_route.c
  5. 2
      gossipd/test/run-find_route-specific.c
  6. 2
      gossipd/test/run-find_route.c

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

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

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

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

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

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

Loading…
Cancel
Save