Browse Source

gossipd: keep index of node and channel announcements.

This lets detect if a node announce preceeds a channel announce once we
delete the node announcement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
a38c619486
  1. 5
      gossipd/broadcast.c
  2. 4
      gossipd/broadcast.h
  3. 2
      gossipd/gossip.c
  4. 27
      gossipd/routing.c
  5. 5
      gossipd/routing.h
  6. 4
      gossipd/test/run-bench-find_route.c
  7. 4
      gossipd/test/run-find_route-specific.c
  8. 4
      gossipd/test/run-find_route.c

5
gossipd/broadcast.c

@ -43,12 +43,13 @@ static struct queued_message *new_queued_message(const tal_t *ctx,
return msg; return msg;
} }
void insert_broadcast(struct broadcast_state *bstate, u64 insert_broadcast(struct broadcast_state *bstate,
const u8 *payload, u32 timestamp) const u8 *payload, u32 timestamp)
{ {
/* Free payload, free index. */ /* Free payload, free index. */
new_queued_message(payload, bstate, payload, timestamp, new_queued_message(payload, bstate, payload, timestamp,
bstate->next_index++); bstate->next_index);
return bstate->next_index++;
} }
const u8 *next_broadcast(struct broadcast_state *bstate, const u8 *next_broadcast(struct broadcast_state *bstate,

4
gossipd/broadcast.h

@ -17,8 +17,8 @@ struct broadcast_state {
struct broadcast_state *new_broadcast_state(tal_t *ctx); struct broadcast_state *new_broadcast_state(tal_t *ctx);
/* Append a queued message for broadcast. Freeing the msg will remove it. */ /* Append a queued message for broadcast. Freeing the msg will remove it. */
void insert_broadcast(struct broadcast_state *bstate, const u8 *msg, u64 insert_broadcast(struct broadcast_state *bstate, const u8 *msg,
u32 timestamp); u32 timestamp);
/* Return the broadcast with index >= *last_index, timestamp >= min and <= max /* Return the broadcast with index >= *last_index, timestamp >= min and <= max
* and update *last_index. * and update *last_index.

2
gossipd/gossip.c

@ -1494,7 +1494,7 @@ static bool create_next_scid_reply(struct peer *peer)
const struct node *n; const struct node *n;
n = get_node(rstate, &peer->scid_query_nodes[i]); n = get_node(rstate, &peer->scid_query_nodes[i]);
if (!n || !n->node_announcement || !n->node_announcement_public) if (!n || !n->node_announcement || !n->node_announcement_index)
continue; continue;
queue_peer_msg(peer, n->node_announcement); queue_peer_msg(peer, n->node_announcement);

27
gossipd/routing.c

@ -150,7 +150,7 @@ static struct node *new_node(struct routing_state *rstate,
n->chans = tal_arr(n, struct chan *, 0); n->chans = tal_arr(n, struct chan *, 0);
n->alias = NULL; n->alias = NULL;
n->node_announcement = NULL; n->node_announcement = NULL;
n->node_announcement_public = false; n->node_announcement_index = 0;
n->last_timestamp = -1; n->last_timestamp = -1;
n->addresses = tal_arr(n, struct wireaddr, 0); n->addresses = tal_arr(n, struct wireaddr, 0);
node_map_add(rstate->nodes, n); node_map_add(rstate->nodes, n);
@ -238,6 +238,7 @@ struct chan *new_chan(struct routing_state *rstate,
chan->nodes[!n1idx] = n2; chan->nodes[!n1idx] = n2;
chan->txout_script = NULL; chan->txout_script = NULL;
chan->channel_announce = NULL; chan->channel_announce = NULL;
chan->channel_announcement_index = 0;
chan->satoshis = 0; chan->satoshis = 0;
n = tal_count(n2->chans); n = tal_count(n2->chans);
@ -617,7 +618,9 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
struct chan *chan, struct chan *chan,
u32 timestamp) u32 timestamp)
{ {
insert_broadcast(rstate->broadcasts, chan->channel_announce, timestamp); chan->channel_announcement_index
= insert_broadcast(rstate->broadcasts, chan->channel_announce,
timestamp);
rstate->local_channel_announced |= is_local_channel(rstate, chan); rstate->local_channel_announced |= is_local_channel(rstate, chan);
/* If we've been waiting for this, now we can announce node */ /* If we've been waiting for this, now we can announce node */
@ -625,11 +628,11 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
struct node *node = chan->nodes[i]; struct node *node = chan->nodes[i];
if (!node->node_announcement) if (!node->node_announcement)
continue; continue;
if (!node->node_announcement_public) { if (!node->node_announcement_index) {
node->node_announcement_public = true; node->node_announcement_index =
insert_broadcast(rstate->broadcasts, insert_broadcast(rstate->broadcasts,
node->node_announcement, node->node_announcement,
node->last_timestamp); node->last_timestamp);
} }
} }
} }
@ -1244,10 +1247,12 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
* order. It's not vital, but would be nice to fix. * order. It's not vital, but would be nice to fix.
*/ */
/* We might be waiting for channel_announce to be released. */ /* We might be waiting for channel_announce to be released. */
node->node_announcement_public = node_has_broadcastable_channels(node); if (node_has_broadcastable_channels(node)) {
if (node->node_announcement_public) node->node_announcement_index =
insert_broadcast(rstate->broadcasts, node->node_announcement, insert_broadcast(rstate->broadcasts,
timestamp); node->node_announcement,
timestamp);
}
return true; return true;
} }

5
gossipd/routing.h

@ -52,6 +52,8 @@ struct chan {
/* NULL if not announced yet (ie. not public). */ /* NULL if not announced yet (ie. not public). */
const u8 *channel_announce; const u8 *channel_announce;
/* Index in broadcast map, if public (otherwise 0) */
u64 channel_announcement_index;
u64 satoshis; u64 satoshis;
}; };
@ -101,7 +103,8 @@ struct node {
/* Cached `node_announcement` we might forward to new peers (or NULL). */ /* Cached `node_announcement` we might forward to new peers (or NULL). */
const u8 *node_announcement; const u8 *node_announcement;
bool node_announcement_public; /* If public, this is non-zero. */
u64 node_announcement_index;
}; };
const secp256k1_pubkey *node_map_keyof_node(const struct node *n); const secp256k1_pubkey *node_map_keyof_node(const struct node *n);

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

@ -93,8 +93,8 @@ 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) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
/* Generated stub for insert_broadcast */ /* Generated stub for insert_broadcast */
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED, u64 insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
u32 timestamp UNNEEDED) u32 timestamp UNNEEDED)
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); } { fprintf(stderr, "insert_broadcast called!\n"); abort(); }
/* Generated stub for onion_type_name */ /* Generated stub for onion_type_name */
const char *onion_type_name(int e UNNEEDED) const char *onion_type_name(int e UNNEEDED)

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

@ -57,8 +57,8 @@ 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) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
/* Generated stub for insert_broadcast */ /* Generated stub for insert_broadcast */
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED, u64 insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
u32 timestamp UNNEEDED) u32 timestamp UNNEEDED)
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); } { fprintf(stderr, "insert_broadcast called!\n"); abort(); }
/* Generated stub for onion_type_name */ /* Generated stub for onion_type_name */
const char *onion_type_name(int e UNNEEDED) const char *onion_type_name(int e UNNEEDED)

4
gossipd/test/run-find_route.c

@ -55,8 +55,8 @@ 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) bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
/* Generated stub for insert_broadcast */ /* Generated stub for insert_broadcast */
void insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED, u64 insert_broadcast(struct broadcast_state *bstate UNNEEDED, const u8 *msg UNNEEDED,
u32 timestamp UNNEEDED) u32 timestamp UNNEEDED)
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); } { fprintf(stderr, "insert_broadcast called!\n"); abort(); }
/* Generated stub for onion_type_name */ /* Generated stub for onion_type_name */
const char *onion_type_name(int e UNNEEDED) const char *onion_type_name(int e UNNEEDED)

Loading…
Cancel
Save