From 9324bf7b1d1ccecb3e4c873f61580148722620aa Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 4 May 2018 13:42:57 +0200 Subject: [PATCH] lnwallet/channel: return error in case of htlc index mismatch This commit make us return an error in case a restored HTLC from a pending remote commit has an index that is different from our local update log index. It is appended with the assumption that these indexes are the same, and if they are not we cannot really continue. --- lnwallet/channel.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 6ab16c9a..f249e555 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -1765,6 +1765,16 @@ func (lc *LightningChannel) restoreStateLogs( } if payDesc.EntryType == Add { + // The HtlcIndex of the added HTLC _must_ be equal to + // the log's htlcCounter at this point. If it is not we + // panic to catch this. + // TODO(halseth): remove when cause of htlc entry bug + // is found. + if payDesc.HtlcIndex != lc.localUpdateLog.htlcCounter { + panic(fmt.Sprintf("htlc index mismatch: "+ + "%v vs %v", payDesc.HtlcIndex, + lc.localUpdateLog.htlcCounter)) + } lc.localUpdateLog.appendHtlc(payDesc) } else { lc.localUpdateLog.appendUpdate(payDesc)