From bbc36a7bec0e285b71eb67d9cca3bf068b0bbd54 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 16 Oct 2018 14:14:53 +1030 Subject: [PATCH] gossipd: update node announcement even if we change within a second. Usually Travis triggers corner cases because it's so slow, but this time the moons aligned, and it managed to fail test_node_reannounce because it generated the updated node_announcement with the same timestamp as the old one. This is because we only updated "last_announce_timestamp" when we generated the announcement, not when we got it off the wire or loaded it from the gossip store. The fix is to ask the routing code what the latest timestamp is; we could still generate a clashing timestamp if (1) the gossip store is lost, and (2) we restart within one second. Hard to care. Signed-off-by: Rusty Russell --- gossipd/gossipd.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 386c45413..98bfe8031 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -90,9 +90,6 @@ struct daemon { /* What we can actually announce. */ struct wireaddr *announcable; - - /* To make sure our node_announcement timestamps increase */ - u32 last_announce_timestamp; }; struct peer { @@ -313,11 +310,17 @@ 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); + + if (self) + last_timestamp = self->last_timestamp; + else + last_timestamp = -1; /* Timestamps must move forward, or announce will be ignored! */ - if (timestamp <= daemon->last_announce_timestamp) - timestamp = daemon->last_announce_timestamp + 1; - daemon->last_announce_timestamp = timestamp; + if (timestamp <= last_timestamp) + timestamp = last_timestamp + 1; nannounce = create_node_announcement(tmpctx, daemon, NULL, timestamp); @@ -2149,7 +2152,6 @@ int main(int argc, char *argv[]) daemon = tal(NULL, struct daemon); list_head_init(&daemon->peers); timers_init(&daemon->timers, time_mono()); - daemon->last_announce_timestamp = 0; /* stdin == control */ daemon_conn_init(daemon, &daemon->master, STDIN_FILENO, recv_req,