gossipd: fix rolling corruption.

If gossip_store is an incorrect version, we will recreate it: with an incorrect
version!  This means we never get persistent gossip, *and* the pay plugin will
fail to map the gossip_store.  Everyone will be sad.

Debugged-by: Matt Whitlock
Fixes: #4376
Fixes: #4288
Typing-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-03-25 20:16:49 +10:30
parent 1275af6fbb
commit b689d33e97

View File

@@ -335,6 +335,11 @@ struct gossip_store *gossip_store_new(struct routing_state *rstate,
if (ftruncate(gs->fd, 0) != 0)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Truncating store: %s", strerror(errno));
/* Subtle: we are at offset 1, move back to start! */
if (lseek(gs->fd, 0, SEEK_SET) != 0)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Seeking to start of store: %s",
strerror(errno));
}
/* Empty file, write version byte */
gs->version = GOSSIP_STORE_VERSION;