Skip to content

Commit 803e4f8

Browse files
committed
gossipd: announce nodes after channel announcement.
In general, we need to only publish node announcements after publishing channel announcements, though we can accept node announcements as soon as we see channel announcements. So we keep a flag for those node_announcement which haven't been broadcast yet. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent c2cc382 commit 803e4f8

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

gossipd/routing.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static struct node *new_node(struct routing_state *rstate,
150150
n->chans = tal_arr(n, struct chan *, 0);
151151
n->alias = NULL;
152152
n->node_announcement = NULL;
153+
n->node_announcement_public = false;
153154
n->last_timestamp = -1;
154155
n->addresses = tal_arr(n, struct wireaddr, 0);
155156
node_map_add(rstate->nodes, n);
@@ -617,6 +618,18 @@ static void add_channel_announce_to_broadcast(struct routing_state *rstate,
617618
{
618619
insert_broadcast(rstate->broadcasts, chan->channel_announce);
619620
rstate->local_channel_announced |= is_local_channel(rstate, chan);
621+
622+
/* If we've been waiting for this, now we can announce node */
623+
for (size_t i = 0; i < ARRAY_SIZE(chan->nodes); i++) {
624+
struct node *node = chan->nodes[i];
625+
if (!node->node_announcement)
626+
continue;
627+
if (!node->node_announcement_public) {
628+
node->node_announcement_public = true;
629+
insert_broadcast(rstate->broadcasts,
630+
node->node_announcement);
631+
}
632+
}
620633
}
621634

622635
bool routing_add_channel_announcement(struct routing_state *rstate,
@@ -1140,6 +1153,14 @@ static struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser)
11401153
return wireaddrs;
11411154
}
11421155

1156+
static bool node_has_public_channels(struct node *node)
1157+
{
1158+
for (size_t i = 0; i < tal_count(node->chans); i++)
1159+
if (is_chan_public(node->chans[i]))
1160+
return true;
1161+
return false;
1162+
}
1163+
11431164
bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg TAKES)
11441165
{
11451166
struct node *node;
@@ -1175,16 +1196,16 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
11751196

11761197
tal_free(node->node_announcement);
11771198
node->node_announcement = tal_dup_arr(node, u8, msg, tal_len(msg), 0);
1178-
insert_broadcast(rstate->broadcasts, node->node_announcement);
1179-
return true;
1180-
}
11811199

1182-
static bool node_has_public_channels(struct node *node)
1183-
{
1184-
for (size_t i = 0; i < tal_count(node->chans); i++)
1185-
if (is_chan_public(node->chans[i]))
1186-
return true;
1187-
return false;
1200+
/* FIXME:
1201+
* When a channel is closed, the node announce may now be out of
1202+
* order. It's not vital, but would be nice to fix.
1203+
*/
1204+
/* We might be waiting for channel_announce to be released. */
1205+
node->node_announcement_public = node_has_public_channels(node);
1206+
if (node->node_announcement_public)
1207+
insert_broadcast(rstate->broadcasts, node->node_announcement);
1208+
return true;
11881209
}
11891210

11901211
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)

gossipd/routing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct node {
101101

102102
/* Cached `node_announcement` we might forward to new peers (or NULL). */
103103
const u8 *node_announcement;
104+
bool node_announcement_public;
104105
};
105106

106107
const secp256k1_pubkey *node_map_keyof_node(const struct node *n);

0 commit comments

Comments
 (0)