Skip to content

Commit

Permalink
refactor: replace math.Min and math.Max with built-in min/max
Browse files Browse the repository at this point in the history
Reference: #9451 (review)
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed Jan 31, 2025
1 parent 3376b95 commit 8a38aa5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
5 changes: 1 addition & 4 deletions contractcourt/commit_sweep_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/binary"
"fmt"
"io"
"math"
"sync"

"github.com/btcsuite/btcd/btcutil"
Expand Down Expand Up @@ -391,9 +390,7 @@ func (c *commitSweepResolver) Launch() error {
// expires after.
unlockHeight := confHeight + c.commitResolution.MaturityDelay
if c.hasCLTV() {
unlockHeight = uint32(math.Max(
float64(unlockHeight), float64(c.leaseExpiry),
))
unlockHeight = max(unlockHeight, c.leaseExpiry)
}

// Update report now that we learned the confirmation height.
Expand Down
6 changes: 1 addition & 5 deletions contractcourt/htlc_lease_resolver.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package contractcourt

import (
"math"

"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
Expand Down Expand Up @@ -42,9 +40,7 @@ func (h *htlcLeaseResolver) deriveWaitHeight(csvDelay uint32,

waitHeight := uint32(commitSpend.SpendingHeight) + csvDelay - 1
if h.hasCLTV() {
waitHeight = uint32(math.Max(
float64(waitHeight), float64(h.leaseExpiry),
))
waitHeight = max(waitHeight, h.leaseExpiry)
}

return waitHeight
Expand Down
14 changes: 3 additions & 11 deletions lnwallet/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/sha256"
"errors"
"fmt"
"math"
"slices"
"sync"

Expand Down Expand Up @@ -9512,7 +9511,7 @@ func (lc *LightningChannel) MaxFeeRate(
// rather than us decreasing in local balance. The max fee rate is
// always floored by the current fee rate of the channel.
idealMaxFee := float64(baseBalance) * maxAllocation
maxFee := math.Max(float64(currentFee), idealMaxFee)
maxFee := max(float64(currentFee), idealMaxFee)
maxFeeAllocation := maxFee / float64(baseBalance)
maxFeeRate := chainfee.SatPerKWeight(maxFee / (float64(weight) / 1000))

Expand All @@ -9538,17 +9537,10 @@ func (lc *LightningChannel) IdealCommitFeeRate(netFeeRate, minRelayFeeRate,
switch lc.channelState.ChanType.HasAnchors() &&
maxFeeRate > maxAnchorCommitFeeRate {
case true:
commitFeeRate = chainfee.SatPerKWeight(
math.Min(
float64(netFeeRate),
float64(maxAnchorCommitFeeRate),
),
)
commitFeeRate = min(netFeeRate, maxAnchorCommitFeeRate)

case false:
commitFeeRate = chainfee.SatPerKWeight(
math.Min(float64(netFeeRate), float64(maxFeeRate)),
)
commitFeeRate = min(netFeeRate, maxFeeRate)
}

if commitFeeRate >= minRelayFeeRate {
Expand Down
2 changes: 1 addition & 1 deletion sqldb/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func randRetryDelay(initialRetryDelay, maxRetryDelay time.Duration,
// attempt. If we double something n times, that's the same as
// multiplying the value with 2^n. We limit the power to 32 to avoid
// overflows.
factor := time.Duration(math.Pow(2, math.Min(float64(attempt), 32)))
factor := time.Duration(math.Pow(2, min(float64(attempt), 32)))
actualDelay := initialDelay * factor

// Cap the delay at the maximum configured value.
Expand Down

0 comments on commit 8a38aa5

Please sign in to comment.