From b689d33e97f80254058b8cee52abf682741efa13 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 25 Mar 2021 20:16:49 +1030 Subject: [PATCH] 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 --- gossipd/gossip_store.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index 1f7aec848..26a2a62c7 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -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;