Skip to content

Commit

Permalink
refactor: replace min/max helpers with built-in min/max
Browse files Browse the repository at this point in the history
We can use the built-in `min` and `max` functions since Go 1.21.

Reference: https://go.dev/ref/spec#Min_and_max
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Jan 26, 2025
1 parent 1ed76af commit 866c9df
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 116 deletions.
4 changes: 1 addition & 3 deletions autopilot/simple_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ func NewSimpleGraph(g ChannelGraph) (*SimpleGraph, error) {
func maxVal(mapping map[int]uint32) uint32 {
maxValue := uint32(0)
for _, value := range mapping {
if maxValue < value {
maxValue = value
}
maxValue = max(maxValue, value)
}
return maxValue
}
Expand Down
26 changes: 0 additions & 26 deletions lntypes/comparison.go

This file was deleted.

25 changes: 0 additions & 25 deletions lntypes/comparison_test.go

This file was deleted.

13 changes: 5 additions & 8 deletions routing/unified_edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/btcsuite/btcd/btcutil"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
)
Expand Down Expand Up @@ -379,13 +378,11 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,

capMsat = edge.policy.MaxHTLC
}
maxCapMsat = lntypes.Max(capMsat, maxCapMsat)
maxCapMsat = max(capMsat, maxCapMsat)

// Track the maximum time lock of all channels that are
// candidate for non-strict forwarding at the routing node.
maxTimelock = lntypes.Max(
maxTimelock, edge.policy.TimeLockDelta,
)
maxTimelock = max(maxTimelock, edge.policy.TimeLockDelta)

outboundFee := int64(edge.policy.ComputeFee(amt))
fee := outboundFee + inboundFee
Expand Down Expand Up @@ -440,10 +437,10 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,

// minAmt returns the minimum amount that can be forwarded on this connection.
func (u *edgeUnifier) minAmt() lnwire.MilliSatoshi {
min := lnwire.MaxMilliSatoshi
minAmount := lnwire.MaxMilliSatoshi
for _, edge := range u.edges {
min = lntypes.Min(min, edge.policy.MinHTLC)
minAmount = min(minAmount, edge.policy.MinHTLC)
}

return min
return minAmount
}
18 changes: 0 additions & 18 deletions watchtower/wtdb/migration4/range_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
"than end height %d", start, end)
}

// min is a helper closure that will return the minimum of two uint64s.
min := func(a, b uint64) uint64 {
if a < b {
return a
}

return b
}

// max is a helper closure that will return the maximum of two uint64s.
max := func(a, b uint64) uint64 {
if a > b {
return a
}

return b
}

// Collect the ranges that fall before and after the new range along
// with the start and end values of the new range.
var before, after []rangeItem
Expand Down
18 changes: 0 additions & 18 deletions watchtower/wtdb/migration8/range_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
"than end height %d", start, end)
}

// min is a helper closure that will return the minimum of two uint64s.
min := func(a, b uint64) uint64 {
if a < b {
return a
}

return b
}

// max is a helper closure that will return the maximum of two uint64s.
max := func(a, b uint64) uint64 {
if a > b {
return a
}

return b
}

// Collect the ranges that fall before and after the new range along
// with the start and end values of the new range.
var before, after []rangeItem
Expand Down
18 changes: 0 additions & 18 deletions watchtower/wtdb/range_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
"than end height %d", start, end)
}

// min is a helper closure that will return the minimum of two uint64s.
min := func(a, b uint64) uint64 {
if a < b {
return a
}

return b
}

// max is a helper closure that will return the maximum of two uint64s.
max := func(a, b uint64) uint64 {
if a > b {
return a
}

return b
}

// Collect the ranges that fall before and after the new range along
// with the start and end values of the new range.
var before, after []rangeItem
Expand Down

0 comments on commit 866c9df

Please sign in to comment.