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.
This commit is contained in:
Johan T. Halseth 2018-05-04 13:42:57 +02:00
parent 7e1f2a7dc3
commit 9324bf7b1d
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -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)