Skip to content

Commit 0899cee

Browse files
committed
refactor: replace min/max helpers with built-in min/max
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>
1 parent bac699d commit 0899cee

File tree

7 files changed

+6
-116
lines changed

7 files changed

+6
-116
lines changed

autopilot/simple_graph.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ func NewSimpleGraph(g ChannelGraph) (*SimpleGraph, error) {
8585
func maxVal(mapping map[int]uint32) uint32 {
8686
maxValue := uint32(0)
8787
for _, value := range mapping {
88-
if maxValue < value {
89-
maxValue = value
90-
}
88+
maxValue = max(maxValue, value)
9189
}
9290
return maxValue
9391
}

lntypes/comparison.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

lntypes/comparison_test.go

Lines changed: 0 additions & 25 deletions
This file was deleted.

routing/unified_edges.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/btcsuite/btcd/btcutil"
77
graphdb "github.com/lightningnetwork/lnd/graph/db"
88
"github.com/lightningnetwork/lnd/graph/db/models"
9-
"github.com/lightningnetwork/lnd/lntypes"
109
"github.com/lightningnetwork/lnd/lnwire"
1110
"github.com/lightningnetwork/lnd/routing/route"
1211
)
@@ -379,13 +378,11 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
379378

380379
capMsat = edge.policy.MaxHTLC
381380
}
382-
maxCapMsat = lntypes.Max(capMsat, maxCapMsat)
381+
maxCapMsat = max(capMsat, maxCapMsat)
383382

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

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

441438
// minAmt returns the minimum amount that can be forwarded on this connection.
442439
func (u *edgeUnifier) minAmt() lnwire.MilliSatoshi {
443-
min := lnwire.MaxMilliSatoshi
440+
minAmount := lnwire.MaxMilliSatoshi
444441
for _, edge := range u.edges {
445-
min = lntypes.Min(min, edge.policy.MinHTLC)
442+
minAmount = min(minAmount, edge.policy.MinHTLC)
446443
}
447444

448-
return min
445+
return minAmount
449446
}

watchtower/wtdb/migration4/range_index.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
7474
"than end height %d", start, end)
7575
}
7676

77-
// min is a helper closure that will return the minimum of two uint64s.
78-
min := func(a, b uint64) uint64 {
79-
if a < b {
80-
return a
81-
}
82-
83-
return b
84-
}
85-
86-
// max is a helper closure that will return the maximum of two uint64s.
87-
max := func(a, b uint64) uint64 {
88-
if a > b {
89-
return a
90-
}
91-
92-
return b
93-
}
94-
9577
// Collect the ranges that fall before and after the new range along
9678
// with the start and end values of the new range.
9779
var before, after []rangeItem

watchtower/wtdb/migration8/range_index.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
7474
"than end height %d", start, end)
7575
}
7676

77-
// min is a helper closure that will return the minimum of two uint64s.
78-
min := func(a, b uint64) uint64 {
79-
if a < b {
80-
return a
81-
}
82-
83-
return b
84-
}
85-
86-
// max is a helper closure that will return the maximum of two uint64s.
87-
max := func(a, b uint64) uint64 {
88-
if a > b {
89-
return a
90-
}
91-
92-
return b
93-
}
94-
9577
// Collect the ranges that fall before and after the new range along
9678
// with the start and end values of the new range.
9779
var before, after []rangeItem

watchtower/wtdb/range_index.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,6 @@ func (a *RangeIndex) addRange(start, end uint64) error {
7474
"than end height %d", start, end)
7575
}
7676

77-
// min is a helper closure that will return the minimum of two uint64s.
78-
min := func(a, b uint64) uint64 {
79-
if a < b {
80-
return a
81-
}
82-
83-
return b
84-
}
85-
86-
// max is a helper closure that will return the maximum of two uint64s.
87-
max := func(a, b uint64) uint64 {
88-
if a > b {
89-
return a
90-
}
91-
92-
return b
93-
}
94-
9577
// Collect the ranges that fall before and after the new range along
9678
// with the start and end values of the new range.
9779
var before, after []rangeItem

0 commit comments

Comments
 (0)