From aa1c2cdf81f066120d8c60a284dc2d3c146edd42 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Fri, 4 May 2018 13:25:10 +0200 Subject: [PATCH] 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. --- lnwallet/channel.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lnwallet/channel.go b/lnwallet/channel.go index a50a2956..5bb8add6 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -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)