diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 74e46ad26..f44bd41b5 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -388,7 +388,6 @@ static void send_node_announcement(struct daemon *daemon) u32 timestamp = time_now().ts.tv_sec; secp256k1_ecdsa_signature sig; u8 *msg, *nannounce, *err; - s64 last_timestamp; struct node *self = get_node(daemon->rstate, &daemon->id); /* BOLT #7: @@ -397,14 +396,8 @@ static void send_node_announcement(struct daemon *daemon) * - MUST set `timestamp` to be greater than that of any previous * `node_announcement` it has previously created. */ - if (self) - last_timestamp = self->last_timestamp; - else - /* last_timestamp is carefully a s64, so this works */ - last_timestamp = -1; - - if (timestamp <= last_timestamp) - timestamp = last_timestamp + 1; + if (self && self->node_announcement && timestamp <= self->last_timestamp) + timestamp = self->last_timestamp + 1; /* Get an unsigned one. */ nannounce = create_node_announcement(tmpctx, daemon, NULL, timestamp); @@ -438,7 +431,7 @@ static bool node_announcement_redundant(struct daemon *daemon) if (!n) return false; - if (n->last_timestamp == -1) + if (!n->node_announcement) return false; if (tal_count(n->addresses) != tal_count(daemon->announcable)) @@ -2062,10 +2055,12 @@ static void append_node(const struct gossip_getnodes_entry ***entries, e = tal(*entries, struct gossip_getnodes_entry); e->nodeid = n->id; - e->last_timestamp = n->last_timestamp; /* Timestamp on wire is an unsigned 32 bit: we use a 64-bit signed, so * -1 means "we never received a channel_update". */ - if (e->last_timestamp >= 0) { + if (!n->node_announcement) + e->last_timestamp = -1; + else { + e->last_timestamp = n->last_timestamp; e->globalfeatures = n->globalfeatures; e->addresses = n->addresses; BUILD_ASSERT(ARRAY_SIZE(e->alias) == ARRAY_SIZE(n->alias)); diff --git a/gossipd/routing.c b/gossipd/routing.c index 2d6cc5b45..79c8f374c 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -231,7 +231,6 @@ static struct node *new_node(struct routing_state *rstate, n->globalfeatures = NULL; n->node_announcement = NULL; n->node_announcement_index = 0; - n->last_timestamp = -1; n->addresses = tal_arr(n, struct wireaddr, 0); node_map_add(rstate->nodes, n); tal_add_destructor2(n, destroy_node, rstate); @@ -1193,7 +1192,7 @@ static void set_connection_values(struct chan *chan, u32 delay, u8 message_flags, u8 channel_flags, - u64 timestamp, + u32 timestamp, struct amount_msat htlc_minimum, struct amount_msat htlc_maximum) { @@ -1658,7 +1657,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann) return NULL; } - if (node->last_timestamp >= timestamp) { + if (node->node_announcement && node->last_timestamp >= timestamp) { SUPERVERBOSE("Ignoring node announcement, it's outdated."); return NULL; } @@ -1853,6 +1852,8 @@ void route_prune(struct routing_state *rstate) if (!is_chan_public(chan)) continue; + /* Rare case where we examine timestamp even without update; + * it's used to prune channels where update never arrives */ if (chan->half[0].last_timestamp < highwater && chan->half[1].last_timestamp < highwater) { status_trace( diff --git a/gossipd/routing.h b/gossipd/routing.h index 5c146d74a..9d1a57986 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -25,8 +25,7 @@ struct half_chan { /* Delay for HTLC in blocks.*/ u32 delay; - /* -1 if channel_update is NULL */ - s64 last_timestamp; + u32 last_timestamp; /* Minimum and maximum number of msatoshi in an HTLC */ struct amount_msat htlc_minimum, htlc_maximum; @@ -114,8 +113,7 @@ HTABLE_DEFINE_TYPE(struct chan, chan_map_scid, hash_scid, chan_eq_scid, chan_map struct node { struct node_id id; - /* -1 means never; other fields undefined */ - s64 last_timestamp; + u32 last_timestamp; /* IP/Hostname and port of this node (may be NULL) */ struct wireaddr *addresses;