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 cc61dcb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions channel_opener_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,32 @@ func (s *channelOpenerServer) createOpeningParamsMenu(
}

sort.Slice(menu, func(i, j int) bool {
if menu[i].MinMsat == menu[j].MinMsat {
return menu[i].Proportional < menu[j].Proportional
}

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 cc61dcb

Please sign in to comment.