mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-29 02:00:54 +02:00
lnwallet: remove continue statements from evaluateHTLCView loops
This further reduces loop complexity in evaluateHTLCView by using explicit filter steps rather than loop continue statements.
This commit is contained in:
@ -2933,18 +2933,16 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
for _, party := range parties {
|
for _, party := range parties {
|
||||||
// First we run through non-add entries in both logs,
|
// First we run through non-add entries in both logs,
|
||||||
// populating the skip sets.
|
// populating the skip sets.
|
||||||
for _, entry := range view.Updates.GetForParty(party) {
|
resolutions := fn.Filter(func(pd *paymentDescriptor) bool {
|
||||||
switch entry.EntryType {
|
switch pd.EntryType {
|
||||||
// Skip adds for now. They will be processed below.
|
case Settle, Fail, MalformedFail:
|
||||||
case Add:
|
return true
|
||||||
continue
|
default:
|
||||||
|
return false
|
||||||
// Skip fee updates because we've already dealt with
|
|
||||||
// them above.
|
|
||||||
case FeeUpdate:
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
}, view.Updates.GetForParty(party))
|
||||||
|
|
||||||
|
for _, entry := range resolutions {
|
||||||
addEntry, err := lc.fetchParent(
|
addEntry, err := lc.fetchParent(
|
||||||
entry, whoseCommitChain, party.CounterParty(),
|
entry, whoseCommitChain, party.CounterParty(),
|
||||||
)
|
)
|
||||||
@ -2971,13 +2969,12 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
// settled HTLCs, and debiting the chain state balance due to any newly
|
// settled HTLCs, and debiting the chain state balance due to any newly
|
||||||
// added HTLCs.
|
// added HTLCs.
|
||||||
for _, party := range parties {
|
for _, party := range parties {
|
||||||
for _, entry := range view.Updates.GetForParty(party) {
|
liveAdds := fn.Filter(func(pd *paymentDescriptor) bool {
|
||||||
isAdd := entry.EntryType == Add
|
return pd.EntryType == Add &&
|
||||||
skipSet := skip.GetForParty(party)
|
!skip.GetForParty(party).Contains(pd.HtlcIndex)
|
||||||
if skipSet.Contains(entry.HtlcIndex) || !isAdd {
|
}, view.Updates.GetForParty(party))
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for _, entry := range liveAdds {
|
||||||
// Skip the entries that have already had their add
|
// Skip the entries that have already had their add
|
||||||
// commit height set for this commit chain.
|
// commit height set for this commit chain.
|
||||||
addHeight := entry.addCommitHeights.GetForParty(
|
addHeight := entry.addCommitHeights.GetForParty(
|
||||||
@ -2988,12 +2985,9 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance,
|
|||||||
entry, ourBalance, theirBalance, party,
|
entry, ourBalance, theirBalance, party,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
prevUpdates := newView.Updates.GetForParty(party)
|
|
||||||
newView.Updates.SetForParty(
|
|
||||||
party, append(prevUpdates, entry),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newView.Updates.SetForParty(party, liveAdds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a function that is capable of identifying whether or not the
|
// Create a function that is capable of identifying whether or not the
|
||||||
|
Reference in New Issue
Block a user