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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-03-22 07:48:57 +10:30 committed by ShahanaFarooqui
parent 00f75d6ee1
commit 6a446a94c6
1 changed files with 18 additions and 9 deletions

View File

@ -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) if (peer->gs.timestamp_max < peer->gs.timestamp_min)
peer->gs.timestamp_max = UINT32_MAX; peer->gs.timestamp_max = UINT32_MAX;
/* Optimization: they don't want anything. LND and us (at least), /* BOLT-gossip-filter-simplify #7:
* both set first_timestamp to 0xFFFFFFFF to indicate that. */ * The receiver:
if (peer->gs.timestamp_min == UINT32_MAX) *...
* - 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; peer->gs.off = peer->daemon->gossip_store_end;
else { else {
/* Second optimation: it's common to ask for "recent" gossip, /* We are actually a bit nicer than the spec, and we include
* so we don't have to start at beginning of store. */ * "recent" gossip here. */
update_recent_timestamp(peer->daemon); update_recent_timestamp(peer->daemon);
if (peer->gs.timestamp_min >= peer->daemon->gossip_recent_time) peer->gs.off = peer->daemon->gossip_store_recent_off;
peer->gs.off = peer->daemon->gossip_store_recent_off;
else
peer->gs.off = 1;
} }
/* BOLT #7: /* BOLT #7: