gossipd: don't broadcast node_announcement if we have no public channels.

This could always happen if we armed the timer when we did have public
channels, and by the time we did our node_announcement we no longer
did, but it gets triggered in our tests when we remove (our own!)
zombied node_announcement in the next patch.
This commit is contained in:
Rusty Russell 2023-02-15 15:02:34 +10:30 committed by Alex Myers
parent 9e93826eea
commit 167209d595
5 changed files with 15 additions and 8 deletions

View File

@ -263,6 +263,10 @@ static bool update_own_node_announcement(struct daemon *daemon,
/* Discard existing timer. */ /* Discard existing timer. */
daemon->node_announce_timer = tal_free(daemon->node_announce_timer); daemon->node_announce_timer = tal_free(daemon->node_announce_timer);
/* If we don't have any channels now, don't send node_announcement */
if (!self || !node_has_broadcastable_channels(self))
goto reset_timer;
/* If we ever use set-based propagation, ensuring the toggle the lower /* If we ever use set-based propagation, ensuring the toggle the lower
* bit in consecutive timestamps makes it more robust. */ * bit in consecutive timestamps makes it more robust. */
if (self && self->bcast.index if (self && self->bcast.index
@ -327,6 +331,7 @@ static bool update_own_node_announcement(struct daemon *daemon,
send: send:
sign_and_send_nannounce(daemon, nannounce, timestamp); sign_and_send_nannounce(daemon, nannounce, timestamp);
reset_timer:
/* Generate another one in 24 hours. */ /* Generate another one in 24 hours. */
setup_force_nannounce_regen_timer(daemon); setup_force_nannounce_regen_timer(daemon);
@ -341,13 +346,6 @@ static void update_own_node_announcement_after_startup(struct daemon *daemon)
/* This creates and transmits a *new* node announcement */ /* This creates and transmits a *new* node announcement */
static void force_self_nannounce_regen(struct daemon *daemon) static void force_self_nannounce_regen(struct daemon *daemon)
{ {
struct node *self = get_node(daemon->rstate, &daemon->id);
/* Clear timer pointer now. */
daemon->node_announce_regen_timer = NULL;
/* No channels left? We'll restart timer once we have one. */
if (!self || !self->bcast.index)
return;
update_own_node_announcement(daemon, false, true); update_own_node_announcement(daemon, false, true);
} }

View File

@ -416,7 +416,7 @@ static bool is_node_zombie(struct node* node)
/* We can *send* a channel_announce for a channel attached to this node: /* We can *send* a channel_announce for a channel attached to this node:
* we only send once we have a channel_update. */ * we only send once we have a channel_update. */
static bool node_has_broadcastable_channels(struct node *node) bool node_has_broadcastable_channels(const struct node *node)
{ {
struct chan_map_iter i; struct chan_map_iter i;
struct chan *c; struct chan *c;

View File

@ -434,6 +434,9 @@ bool would_ratelimit_cupdate(struct routing_state *rstate,
const struct half_chan *hc, const struct half_chan *hc,
u32 timestamp); u32 timestamp);
/* Does this node have public, non-zombie channels? */
bool node_has_broadcastable_channels(const struct node *node);
/* Returns an error string if there are unfinalized entries after load */ /* Returns an error string if there are unfinalized entries after load */
const char *unfinalized_entries(const tal_t *ctx, struct routing_state *rstate); const char *unfinalized_entries(const tal_t *ctx, struct routing_state *rstate);

View File

@ -68,6 +68,9 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
struct timerel expire UNNEEDED, struct timerel expire UNNEEDED,
void (*cb)(void *) UNNEEDED, void *arg UNNEEDED) void (*cb)(void *) UNNEEDED, void *arg UNNEEDED)
{ fprintf(stderr, "new_reltimer_ called!\n"); abort(); } { fprintf(stderr, "new_reltimer_ called!\n"); abort(); }
/* Generated stub for node_has_broadcastable_channels */
bool node_has_broadcastable_channels(const struct node *node UNNEEDED)
{ fprintf(stderr, "node_has_broadcastable_channels called!\n"); abort(); }
/* Generated stub for queue_peer_msg */ /* Generated stub for queue_peer_msg */
void queue_peer_msg(struct peer *peer UNNEEDED, const u8 *msg TAKES UNNEEDED) void queue_peer_msg(struct peer *peer UNNEEDED, const u8 *msg TAKES UNNEEDED)
{ fprintf(stderr, "queue_peer_msg called!\n"); abort(); } { fprintf(stderr, "queue_peer_msg called!\n"); abort(); }

View File

@ -94,6 +94,9 @@ struct oneshot *new_reltimer_(struct timers *timers UNNEEDED,
struct timerel expire UNNEEDED, struct timerel expire UNNEEDED,
void (*cb)(void *) UNNEEDED, void *arg UNNEEDED) void (*cb)(void *) UNNEEDED, void *arg UNNEEDED)
{ fprintf(stderr, "new_reltimer_ called!\n"); abort(); } { fprintf(stderr, "new_reltimer_ called!\n"); abort(); }
/* Generated stub for node_has_broadcastable_channels */
bool node_has_broadcastable_channels(const struct node *node UNNEEDED)
{ fprintf(stderr, "node_has_broadcastable_channels called!\n"); abort(); }
/* Generated stub for peer_supplied_good_gossip */ /* Generated stub for peer_supplied_good_gossip */
void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED) void peer_supplied_good_gossip(struct peer *peer UNNEEDED, size_t amount UNNEEDED)
{ fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); } { fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); }