mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-30 07:58:15 +01:00
refactor: replace math.Min and math.Max with built-in min/max
Reference: https://github.com/lightningnetwork/lnd/pull/9451#pullrequestreview-2580942691 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
@@ -391,9 +390,7 @@ func (c *commitSweepResolver) Launch() error {
|
|||||||
// expires after.
|
// expires after.
|
||||||
unlockHeight := confHeight + c.commitResolution.MaturityDelay
|
unlockHeight := confHeight + c.commitResolution.MaturityDelay
|
||||||
if c.hasCLTV() {
|
if c.hasCLTV() {
|
||||||
unlockHeight = uint32(math.Max(
|
unlockHeight = max(unlockHeight, c.leaseExpiry)
|
||||||
float64(unlockHeight), float64(c.leaseExpiry),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update report now that we learned the confirmation height.
|
// Update report now that we learned the confirmation height.
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package contractcourt
|
package contractcourt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
@@ -42,9 +40,7 @@ func (h *htlcLeaseResolver) deriveWaitHeight(csvDelay uint32,
|
|||||||
|
|
||||||
waitHeight := uint32(commitSpend.SpendingHeight) + csvDelay - 1
|
waitHeight := uint32(commitSpend.SpendingHeight) + csvDelay - 1
|
||||||
if h.hasCLTV() {
|
if h.hasCLTV() {
|
||||||
waitHeight = uint32(math.Max(
|
waitHeight = max(waitHeight, h.leaseExpiry)
|
||||||
float64(waitHeight), float64(h.leaseExpiry),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return waitHeight
|
return waitHeight
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -9512,7 +9511,7 @@ func (lc *LightningChannel) MaxFeeRate(
|
|||||||
// rather than us decreasing in local balance. The max fee rate is
|
// rather than us decreasing in local balance. The max fee rate is
|
||||||
// always floored by the current fee rate of the channel.
|
// always floored by the current fee rate of the channel.
|
||||||
idealMaxFee := float64(baseBalance) * maxAllocation
|
idealMaxFee := float64(baseBalance) * maxAllocation
|
||||||
maxFee := math.Max(float64(currentFee), idealMaxFee)
|
maxFee := max(float64(currentFee), idealMaxFee)
|
||||||
maxFeeAllocation := maxFee / float64(baseBalance)
|
maxFeeAllocation := maxFee / float64(baseBalance)
|
||||||
maxFeeRate := chainfee.SatPerKWeight(maxFee / (float64(weight) / 1000))
|
maxFeeRate := chainfee.SatPerKWeight(maxFee / (float64(weight) / 1000))
|
||||||
|
|
||||||
@@ -9538,17 +9537,10 @@ func (lc *LightningChannel) IdealCommitFeeRate(netFeeRate, minRelayFeeRate,
|
|||||||
switch lc.channelState.ChanType.HasAnchors() &&
|
switch lc.channelState.ChanType.HasAnchors() &&
|
||||||
maxFeeRate > maxAnchorCommitFeeRate {
|
maxFeeRate > maxAnchorCommitFeeRate {
|
||||||
case true:
|
case true:
|
||||||
commitFeeRate = chainfee.SatPerKWeight(
|
commitFeeRate = min(netFeeRate, maxAnchorCommitFeeRate)
|
||||||
math.Min(
|
|
||||||
float64(netFeeRate),
|
|
||||||
float64(maxAnchorCommitFeeRate),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
case false:
|
case false:
|
||||||
commitFeeRate = chainfee.SatPerKWeight(
|
commitFeeRate = min(netFeeRate, maxFeeRate)
|
||||||
math.Min(float64(netFeeRate), float64(maxFeeRate)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if commitFeeRate >= minRelayFeeRate {
|
if commitFeeRate >= minRelayFeeRate {
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func randRetryDelay(initialRetryDelay, maxRetryDelay time.Duration,
|
|||||||
// attempt. If we double something n times, that's the same as
|
// 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
|
// multiplying the value with 2^n. We limit the power to 32 to avoid
|
||||||
// overflows.
|
// 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
|
actualDelay := initialDelay * factor
|
||||||
|
|
||||||
// Cap the delay at the maximum configured value.
|
// Cap the delay at the maximum configured value.
|
||||||
|
|||||||
Reference in New Issue
Block a user