From 628b65fb4082ff4dc8568fa0f88b7956cc21b392 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 4 Jun 2019 03:55:25 +0930 Subject: [PATCH] gossip_store: don't leave dangling channel_announce if we truncate. (Or, if we crashed before we got to write out the channel_update). It's a corner case, but one reported by @darosior and reproduced on my test node (both with bad gossip_store due to previous iterations of this patchset!). Signed-off-by: Rusty Russell --- gossipd/gossip_store.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gossipd/gossip_store.c b/gossipd/gossip_store.c index eb809c062..9f14577c1 100644 --- a/gossipd/gossip_store.c +++ b/gossipd/gossip_store.c @@ -624,10 +624,18 @@ truncate_nomsg: status_failed(STATUS_FAIL_INTERNAL_ERROR, "Truncating store: %s", strerror(errno)); out: + gs->writable = true; + /* If we ever truncated, we might have a dangling channel_announce */ + if (chan_ann) { + struct broadcastable bcast; + bcast.index = chan_ann_off; + status_unusual("Deleting un-updated channel_announcement @%" + PRIu64, chan_ann_off); + gossip_store_delete(gs, &bcast, WIRE_CHANNEL_ANNOUNCEMENT); + } status_trace("total store load time: %"PRIu64" msec", time_to_msec(time_between(time_now(), start))); status_trace("gossip_store: Read %zu/%zu/%zu/%zu cannounce/cupdate/nannounce/cdelete from store (%zu deleted) in %"PRIu64" bytes", stats[0], stats[1], stats[2], stats[3], gs->deleted, gs->len); - gs->writable = true; }