From 6a446a94c6fef61423e5daf2ae9872b2b3143fb4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 22 Mar 2023 07:48:57 +1030 Subject: [PATCH] connectd: implement timestamp-as-trinary. This implements the proposal to simply use timestamp as "all", "none" or "stream". There's also a rough spec draft which I will post soon. This *also* removes the last place where we would sometimes sweep the entire gossip_store looking for their given timestamps. We could also get rid of the actual timestamp filtering logic in gossip_store_next if we want to, as it's now basically unused. Changelog-Changed: Protocol: Simplify gossip_timestamp_filter handling to "all", "none" or "recent" instead of exact timestamp. Signed-off-by: Rusty Russell --- connectd/multiplex.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 8d9e780b6..dcf65124d 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -681,18 +681,27 @@ static void handle_gossip_timestamp_filter_in(struct peer *peer, const u8 *msg) if (peer->gs.timestamp_max < peer->gs.timestamp_min) peer->gs.timestamp_max = UINT32_MAX; - /* Optimization: they don't want anything. LND and us (at least), - * both set first_timestamp to 0xFFFFFFFF to indicate that. */ - if (peer->gs.timestamp_min == UINT32_MAX) + /* BOLT-gossip-filter-simplify #7: + * The receiver: + *... + * - if `first_timestamp` is 0: + * - SHOULD send all known gossip messages. + * - otherwise, if `first_timestamp` is 0xFFFFFFFF: + * - SHOULD NOT send any gossip messages (except its own). + * - otherwise: + * - SHOULD send gossip messages it receives from now own. + */ + /* For us, this means we only sweep the gossip store for messages + * if the first_timestamp is 0 */ + if (first_timestamp == 0) + peer->gs.off = 1; + else if (first_timestamp == 0xFFFFFFFF) peer->gs.off = peer->daemon->gossip_store_end; else { - /* Second optimation: it's common to ask for "recent" gossip, - * so we don't have to start at beginning of store. */ + /* We are actually a bit nicer than the spec, and we include + * "recent" gossip here. */ update_recent_timestamp(peer->daemon); - if (peer->gs.timestamp_min >= peer->daemon->gossip_recent_time) - peer->gs.off = peer->daemon->gossip_store_recent_off; - else - peer->gs.off = 1; + peer->gs.off = peer->daemon->gossip_store_recent_off; } /* BOLT #7: