Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestNewBreachRetributionSkipsDustHtlcs incorrect state transtion #3998

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,46 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
skipUs := make(map[uint64]struct{})
skipThem := make(map[uint64]struct{})

// fetchParentEntry is a helper method that will fetch the parent of
// entry from the corresponding update log.
fetchParentEntry := func(entry *PaymentDescriptor,
remoteLog bool) *PaymentDescriptor {

var (
updateLog *updateLog
logName string
)

if remoteLog {
joostjager marked this conversation as resolved.
Show resolved Hide resolved
updateLog = lc.remoteUpdateLog
logName = "remote"
} else {
updateLog = lc.localUpdateLog
logName = "local"
}

addEntry := updateLog.lookupHtlc(entry.ParentIndex)

switch {
// 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.
case addEntry == nil:
panic(fmt.Sprintf("unable to find parent entry %d "+
"in %v update log: %v\nUpdatelog: %v",
entry.ParentIndex, logName,
newLogClosure(func() string {
return spew.Sdump(entry)
}), newLogClosure(func() string {
return spew.Sdump(updateLog)
}),
))
}

return addEntry
}

// First we run through non-add entries in both logs, populating the
// skip sets and mutating the current chain state (crediting balances,
// etc) to reflect the settle/timeout entry encountered.
Expand All @@ -2486,22 +2526,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
lc.channelState.TotalMSatReceived += entry.Amount
}

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)
}),
))
}
addEntry := fetchParentEntry(entry, true)

skipThem[addEntry.HtlcIndex] = struct{}{}
processRemoveEntry(entry, ourBalance, theirBalance,
Expand Down Expand Up @@ -2531,22 +2556,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
lc.channelState.TotalMSatSent += entry.Amount
}

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)
}),
))
}
addEntry := fetchParentEntry(entry, false)

skipUs[addEntry.HtlcIndex] = struct{}{}
processRemoveEntry(entry, ourBalance, theirBalance,
Expand Down