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.
This commit is contained in:
Johan T. Halseth 2019-01-29 14:28:19 +01:00
parent 9a0f87fd8e
commit 47918bd6ce
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

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