Browse Source

gossip: Use replace_broadcast when enqueuing a channel_announcement

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
26b5588656
  1. 23
      gossipd/routing.c
  2. 2
      gossipd/routing.h
  3. 7
      gossipd/test/run-bench-find_route.c
  4. 7
      gossipd/test/run-find_route-specific.c
  5. 7
      gossipd/test/run-find_route.c

23
gossipd/routing.c

@ -50,6 +50,16 @@ struct pending_cannouncement {
const u8 *updates[2];
};
/**
* routing_channel keeps track of the indices in the broadcast queue
* for the corresponding messages. This way we always know exactly
* which broadcast to replace, and don't have to search for it */
enum gossip_msg_indexes {
MSG_INDEX_CUPDATE_0,
MSG_INDEX_CUPDATE_1,
MSG_INDEX_CANNOUNCE
};
static struct node_map *empty_node_map(const tal_t *ctx)
{
struct node_map *map = tal(ctx, struct node_map);
@ -564,6 +574,7 @@ routing_channel_new(const tal_t *ctx, struct short_channel_id *scid)
chan->nodes[0] = chan->nodes[1] = NULL;
chan->txout_script = NULL;
chan->state = TXOUT_FETCHING;
memset(&chan->msg_indexes, 0, sizeof(chan->msg_indexes));
return chan;
}
@ -677,6 +688,11 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
u8 *tag;
const u8 *s;
struct pending_cannouncement *pending;
struct routing_channel *chan;
u64 uscid = short_channel_id_to_uint(scid);
chan = uintmap_get(&rstate->channels, uscid);
assert(chan);
pending = find_pending_cannouncement(rstate, scid);
assert(pending);
@ -732,9 +748,10 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
&pending->short_channel_id, pending->announce);
if (forward) {
if (queue_broadcast(rstate->broadcasts,
WIRE_CHANNEL_ANNOUNCEMENT,
tag, pending->announce))
if (replace_broadcast(rstate->broadcasts,
&chan->msg_indexes[MSG_INDEX_CANNOUNCE],
WIRE_CHANNEL_ANNOUNCEMENT,
(u8*)tag, pending->announce))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Announcement %s was replaced?",
tal_hex(trc, pending->announce));

2
gossipd/routing.h

@ -94,6 +94,8 @@ struct routing_channel {
struct node_connection *connections[2];
struct node *nodes[2];
u64 msg_indexes[3];
};
struct routing_state {

7
gossipd/test/run-bench-find_route.c

@ -75,6 +75,13 @@ bool queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_fail code UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }

7
gossipd/test/run-find_route-specific.c

@ -46,6 +46,13 @@ bool queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_fail code UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }

7
gossipd/test/run-find_route.c

@ -39,6 +39,13 @@ bool queue_broadcast(struct broadcast_state *bstate UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "queue_broadcast called!\n"); abort(); }
/* Generated stub for replace_broadcast */
bool replace_broadcast(struct broadcast_state *bstate UNNEEDED,
u64 *index UNNEEDED,
const int type UNNEEDED,
const u8 *tag UNNEEDED,
const u8 *payload UNNEEDED)
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_fail code UNNEEDED, const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "status_failed called!\n"); abort(); }

Loading…
Cancel
Save