From 47918bd6ce306111a1244a385b40689c1df35e73 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 29 Jan 2019 14:28:19 +0100 Subject: [PATCH] lnwallet/channel: add restoration sanity check To avoid more bugs slipping through where the logIndex is not set, we panic to catch this. This was earlier done for Adds and the htlcCounter, which did lead us to find the resulting retoration bug. --- lnwallet/channel.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index ed1b1a18..6349ca10 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1816,6 +1816,14 @@ func (lc *LightningChannel) restoreStateLogs( "using %v", payDesc.LogIndex) } + // At this point the restored update's logIndex must be equal + // to the update log, otherwise somthing is horribly wrong. + if payDesc.LogIndex != lc.localUpdateLog.logIndex { + panic(fmt.Sprintf("log index mismatch: "+ + "%v vs %v", payDesc.LogIndex, + lc.localUpdateLog.logIndex)) + } + switch payDesc.EntryType { case Add: // The HtlcIndex of the added HTLC _must_ be equal to