lnwallet/channel: add more info in case of crash

This commit adds a call to panic in case the HTLC we are looking for is
not found in the update log. It _should_ always be there, but we have
seen crashes resulting from it not being found. Since it will crash with
a nil pointer dereference below, we instead call panic giving us a bit
more information to work with.
This commit is contained in:
Johan T. Halseth 2018-05-04 13:25:10 +02:00
parent 1d676b77e1
commit aa1c2cdf81
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -2407,6 +2407,21 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
addEntry := lc.remoteUpdateLog.lookupHtlc(entry.ParentIndex)
// We check if the parent entry is not found at this point. We
// have seen this happening a few times and panic with some
// addtitional info to figure out why.
// TODO(halseth): remove when bug is fixed.
if addEntry == nil {
panic(fmt.Sprintf("unable to find parent entry %d "+
"in remote update log: %v\nUpdatelog: %v",
entry.ParentIndex, newLogClosure(func() string {
return spew.Sdump(entry)
}), newLogClosure(func() string {
return spew.Sdump(lc.remoteUpdateLog)
}),
))
}
skipThem[addEntry.HtlcIndex] = struct{}{}
processRemoveEntry(entry, ourBalance, theirBalance,
nextHeight, remoteChain, true, mutateState)
@ -2427,6 +2442,21 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
addEntry := lc.localUpdateLog.lookupHtlc(entry.ParentIndex)
// We check if the parent entry is not found at this point. We
// have seen this happening a few times and panic with some
// addtitional info to figure out why.
// TODO(halseth): remove when bug is fixed.
if addEntry == nil {
panic(fmt.Sprintf("unable to find parent entry %d "+
"in local update log: %v\nUpdatelog: %v",
entry.ParentIndex, newLogClosure(func() string {
return spew.Sdump(entry)
}), newLogClosure(func() string {
return spew.Sdump(lc.localUpdateLog)
}),
))
}
skipUs[addEntry.HtlcIndex] = struct{}{}
processRemoveEntry(entry, ourBalance, theirBalance,
nextHeight, remoteChain, false, mutateState)