gossmap: make API more robust against future changes.

Many changes to gossmap (including the pending ones!) don't actually
concern readers, as long as they obey certain rules:

1. Ignore unknown messages.
2. Treat all 16 upper bits of length as flags, ignore unknown ones.

So now we split the version byte into MAJOR and MINOR, and you can
ignore MINOR changes.

We don't expose the internal version (for creating the map)
programmatically: you should really hardcode what major version you
understand!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-09-14 13:20:31 +09:30
parent 3817a690c9
commit 6338758018
9 changed files with 51 additions and 22 deletions

View File

@@ -11,7 +11,18 @@ struct gossip_rcvd_filter;
/**
* gossip_store -- On-disk storage related information
*/
#define GOSSIP_STORE_VERSION 10
/* First byte of file is the version.
*
* Top three bits mean incompatible change.
* As of this writing, major == 0, minor == 10.
*/
#define GOSSIP_STORE_MAJOR_VERSION_MASK 0xE0
#define GOSSIP_STORE_MINOR_VERSION_MASK 0x1F
/* Extract version from first byte */
#define GOSSIP_STORE_MAJOR_VERSION(verbyte) (((u8)(verbyte)) >> 5)
#define GOSSIP_STORE_MINOR_VERSION(verbyte) ((verbyte) & GOSSIP_STORE_MINOR_VERSION_MASK)
/**
* Bit of length we use to mark a deleted record.
@@ -26,12 +37,16 @@ struct gossip_rcvd_filter;
/**
* Bit of length used to define a rate-limited record (do not rebroadcast)
*/
#define GOSSIP_STORE_LEN_RATELIMIT_BIT 0x20000000U
#define GOSSIP_STORE_LEN_RATELIMIT_BIT 0x20000000U
/**
* Full flags mask
*/
#define GOSSIP_STORE_FLAGS_MASK 0xFFFF0000U
/* Mask for extracting just the length part of len field */
#define GOSSIP_STORE_LEN_MASK \
(~(GOSSIP_STORE_LEN_PUSH_BIT | GOSSIP_STORE_LEN_DELETED_BIT | \
GOSSIP_STORE_LEN_RATELIMIT_BIT))
(~(GOSSIP_STORE_FLAGS_MASK))
/**
* gossip_hdr -- On-disk format header.

View File

@@ -672,7 +672,8 @@ static bool load_gossip_store(struct gossmap *map, size_t *num_rejected)
if (map->mmap == MAP_FAILED)
map->mmap = NULL;
if (map_u8(map, 0) != GOSSIP_STORE_VERSION) {
/* We only support major version 0 */
if (GOSSIP_STORE_MAJOR_VERSION(map_u8(map, 0)) != 0) {
close(map->fd);
if (map->mmap)
munmap(map->mmap, map->map_size);

View File

@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
int store_fd;
struct gossmap *gossmap;
const double riskfactor = 1.0;
char gossip_version = GOSSIP_STORE_VERSION;
char gossip_version = 10;
char *gossipfilename;
common_setup(argv[0]);

View File

@@ -176,7 +176,7 @@ int main(int argc, char *argv[])
int store_fd;
struct gossmap *gossmap;
const double riskfactor = 1.0;
char gossip_version = GOSSIP_STORE_VERSION;
char gossip_version = 10;
char *gossipfilename;
chainparams = chainparams_for_network("regtest");