mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 23:04:35 +01:00
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user