Skip to content

Commit

Permalink
remove duplicates from fee menu
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Jul 31, 2023
1 parent 349ef98 commit 059155a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions channel_opener_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ func (s *channelOpenerServer) createOpeningParamsMenu(
sort.Slice(menu, func(i, j int) bool {
return menu[i].MinMsat < menu[j].MinMsat
})

// Remove duplicate items from the menu, keeping the one with the longest validity.
var last *lspdrpc.OpeningFeeParams
menulen := len(menu)
for i := menulen - 1; i >= 0; i-- {
current := menu[i]
if last != nil {
if current.MinMsat == last.MinMsat && current.Proportional == last.Proportional {
if current.ValidUntil > last.ValidUntil {
// remove last
menu = append(menu[:i+1], menu[i+2:]...)
} else {
// remove current
menu = append(menu[:i], menu[i+1:]...)
}
}
}

last = current
}
return menu, nil
}

Expand Down

0 comments on commit 059155a

Please sign in to comment.