gossipd: erase old entries from the store, don't just append.

We use the high bit of the length field: this way we can still check
that the checksums are valid on deleted fields.

Once this is done, serially reading the gossip_store file will result
in a complete, ordered, minimal gossip broadcast.  Also, the horrible
corner case where we might try to delete things from the store during
load time is completely gone: we only load non-deleted things.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-06-04 03:39:25 +09:30
parent 696dc6b597
commit df00f20e4a
14 changed files with 126 additions and 93 deletions

View File

@@ -45,17 +45,21 @@ int main(int argc, char *argv[])
while (read(fd, &belen, sizeof(belen)) == sizeof(belen) &&
read(fd, &becsum, sizeof(becsum)) == sizeof(becsum)) {
struct amount_sat sat;
struct short_channel_id scid;
u32 msglen = be32_to_cpu(belen);
u8 *msg = tal_arr(NULL, u8, msglen), *inner;
u8 *msg, *inner;
bool deleted = (msglen & GOSSIP_STORE_LEN_DELETED_BIT);
msglen &= ~GOSSIP_STORE_LEN_DELETED_BIT;
msg = tal_arr(NULL, u8, msglen);
if (read(fd, msg, msglen) != msglen)
errx(1, "%zu: Truncated file?", off);
if (be32_to_cpu(becsum) != crc32c(0, msg, msglen))
warnx("Checksum verification failed");
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
if (deleted) {
printf("%zu: DELETED\n", off);
} else if (fromwire_gossip_store_channel_amount(msg, &sat)) {
printf("%zu: channel_amount: %s\n", off,
type_to_string(tmpctx, struct amount_sat, &sat));
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
@@ -70,11 +74,6 @@ int main(int argc, char *argv[])
} else if (fromwire_peektype(msg) == WIRE_GOSSIPD_LOCAL_ADD_CHANNEL) {
printf("%zu: local_add_channel: %s\n",
off, tal_hex(msg, msg));
} else if (fromwire_gossip_store_channel_delete(msg, &scid)) {
printf("%zu: channel_delete: %s\n",
off,
type_to_string(msg, struct short_channel_id,
&scid));
} else if (fromwire_gossip_store_private_update(msg, msg,
&inner)) {
printf("%zu: private channel_update: %s\n",