lnwallet: unify remote and local update log fetch
This commit is contained in:
parent
2c08a8b9a8
commit
e114f58b5e
@ -2460,6 +2460,46 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
|
|||||||
skipUs := make(map[uint64]struct{})
|
skipUs := make(map[uint64]struct{})
|
||||||
skipThem := 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 {
|
||||||
|
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
|
// First we run through non-add entries in both logs, populating the
|
||||||
// skip sets and mutating the current chain state (crediting balances,
|
// skip sets and mutating the current chain state (crediting balances,
|
||||||
// etc) to reflect the settle/timeout entry encountered.
|
// etc) to reflect the settle/timeout entry encountered.
|
||||||
@ -2486,22 +2526,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
|
|||||||
lc.channelState.TotalMSatReceived += entry.Amount
|
lc.channelState.TotalMSatReceived += entry.Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
addEntry := lc.remoteUpdateLog.lookupHtlc(entry.ParentIndex)
|
addEntry := fetchParentEntry(entry, true)
|
||||||
|
|
||||||
// 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{}{}
|
skipThem[addEntry.HtlcIndex] = struct{}{}
|
||||||
processRemoveEntry(entry, ourBalance, theirBalance,
|
processRemoveEntry(entry, ourBalance, theirBalance,
|
||||||
@ -2531,22 +2556,7 @@ func (lc *LightningChannel) evaluateHTLCView(view *htlcView, ourBalance,
|
|||||||
lc.channelState.TotalMSatSent += entry.Amount
|
lc.channelState.TotalMSatSent += entry.Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
addEntry := lc.localUpdateLog.lookupHtlc(entry.ParentIndex)
|
addEntry := fetchParentEntry(entry, false)
|
||||||
|
|
||||||
// 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{}{}
|
skipUs[addEntry.HtlcIndex] = struct{}{}
|
||||||
processRemoveEntry(entry, ourBalance, theirBalance,
|
processRemoveEntry(entry, ourBalance, theirBalance,
|
||||||
|
Loading…
Reference in New Issue
Block a user