mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
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>
This commit is contained in:
parent
294c76e749
commit
a38c619486
@ -43,12 +43,13 @@ static struct queued_message *new_queued_message(const tal_t *ctx,
|
||||
return msg;
|
||||
}
|
||||
|
||||
void insert_broadcast(struct broadcast_state *bstate,
|
||||
u64 insert_broadcast(struct broadcast_state *bstate,
|
||||
const u8 *payload, u32 timestamp)
|
||||
{
|
||||
/* Free payload, free index. */
|
||||
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,
|
||||
|
@ -17,7 +17,7 @@ struct broadcast_state {
|
||||
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Return the broadcast with index >= *last_index, timestamp >= min and <= max
|
||||
|
@ -1494,7 +1494,7 @@ static bool create_next_scid_reply(struct peer *peer)
|
||||
const struct node *n;
|
||||
|
||||
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;
|
||||
|
||||
queue_peer_msg(peer, n->node_announcement);
|
||||
|
@ -150,7 +150,7 @@ static struct node *new_node(struct routing_state *rstate,
|
||||
n->chans = tal_arr(n, struct chan *, 0);
|
||||
n->alias = NULL;
|
||||
n->node_announcement = NULL;
|
||||
n->node_announcement_public = false;
|
||||
n->node_announcement_index = 0;
|
||||
n->last_timestamp = -1;
|
||||
n->addresses = tal_arr(n, struct wireaddr, 0);
|
||||
node_map_add(rstate->nodes, n);
|
||||
@ -238,6 +238,7 @@ struct chan *new_chan(struct routing_state *rstate,
|
||||
chan->nodes[!n1idx] = n2;
|
||||
chan->txout_script = NULL;
|
||||
chan->channel_announce = NULL;
|
||||
chan->channel_announcement_index = 0;
|
||||
chan->satoshis = 0;
|
||||
|
||||
n = tal_count(n2->chans);
|
||||
@ -617,7 +618,9 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
||||
struct chan *chan,
|
||||
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);
|
||||
|
||||
/* If we've been waiting for this, now we can announce node */
|
||||
@ -625,8 +628,8 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
|
||||
struct node *node = chan->nodes[i];
|
||||
if (!node->node_announcement)
|
||||
continue;
|
||||
if (!node->node_announcement_public) {
|
||||
node->node_announcement_public = true;
|
||||
if (!node->node_announcement_index) {
|
||||
node->node_announcement_index =
|
||||
insert_broadcast(rstate->broadcasts,
|
||||
node->node_announcement,
|
||||
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.
|
||||
*/
|
||||
/* We might be waiting for channel_announce to be released. */
|
||||
node->node_announcement_public = node_has_broadcastable_channels(node);
|
||||
if (node->node_announcement_public)
|
||||
insert_broadcast(rstate->broadcasts, node->node_announcement,
|
||||
if (node_has_broadcastable_channels(node)) {
|
||||
node->node_announcement_index =
|
||||
insert_broadcast(rstate->broadcasts,
|
||||
node->node_announcement,
|
||||
timestamp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,8 @@ struct chan {
|
||||
|
||||
/* NULL if not announced yet (ie. not public). */
|
||||
const u8 *channel_announce;
|
||||
/* Index in broadcast map, if public (otherwise 0) */
|
||||
u64 channel_announcement_index;
|
||||
|
||||
u64 satoshis;
|
||||
};
|
||||
@ -101,7 +103,8 @@ struct node {
|
||||
|
||||
/* Cached `node_announcement` we might forward to new peers (or NULL). */
|
||||
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);
|
||||
|
@ -93,7 +93,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 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)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
|
@ -57,7 +57,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 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)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
|
@ -55,7 +55,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 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)
|
||||
{ fprintf(stderr, "insert_broadcast called!\n"); abort(); }
|
||||
/* Generated stub for onion_type_name */
|
||||
|
Loading…
Reference in New Issue
Block a user