Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 514869d

Browse files
authored
feat(utils): replace mathutils (#595)
1 parent 0f15192 commit 514869d

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ require (
1919
github.com/stretchr/testify v1.8.4
2020
github.com/swaggo/swag v1.16.2
2121
github.com/urfave/cli/v2 v2.25.7
22+
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611
2223
golang.org/x/sync v0.5.0
23-
modernc.org/mathutil v1.6.0
2424
)
2525

2626
require (
@@ -167,7 +167,6 @@ require (
167167
github.com/quic-go/quic-go v0.39.3 // indirect
168168
github.com/quic-go/webtransport-go v0.6.0 // indirect
169169
github.com/raulk/go-watchdog v1.3.0 // indirect
170-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
171170
github.com/rivo/uniseg v0.4.4 // indirect
172171
github.com/rogpeppe/go-internal v1.9.0 // indirect
173172
github.com/rs/cors v1.7.0 // indirect
@@ -197,7 +196,6 @@ require (
197196
go.uber.org/multierr v1.11.0 // indirect
198197
go.uber.org/zap v1.26.0 // indirect
199198
golang.org/x/crypto v0.17.0 // indirect
200-
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
201199
golang.org/x/mod v0.14.0 // indirect
202200
golang.org/x/net v0.19.0 // indirect
203201
golang.org/x/oauth2 v0.7.0 // indirect

go.sum

-4
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,6 @@ github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtB
891891
github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU=
892892
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
893893
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
894-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
895-
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
896894
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
897895
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
898896
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
@@ -1654,8 +1652,6 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920 h1:CbnUZsM497iRC5QMVkHwyl8s2tB3g
16541652
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
16551653
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
16561654
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
1657-
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
1658-
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
16591655
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
16601656
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
16611657
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

internal/sender/common.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"github.com/ethereum/go-ethereum/core/types"
1010
"github.com/ethereum/go-ethereum/log"
1111
"github.com/holiman/uint256"
12-
"modernc.org/mathutil"
12+
13+
"github.com/taikoxyz/taiko-client/internal/utils"
1314
)
1415

1516
// adjustGas adjusts the gas fee cap and gas tip cap of the given transaction with the configured
@@ -20,27 +21,27 @@ func (s *Sender) adjustGas(txData types.TxData) {
2021
case *types.DynamicFeeTx:
2122
gasFeeCap := baseTx.GasFeeCap.Int64()
2223
gasFeeCap = gasFeeCap / 100 * int64(rate)
23-
gasFeeCap = mathutil.MinInt64(gasFeeCap, int64(s.MaxGasFee))
24+
gasFeeCap = utils.Min(gasFeeCap, int64(s.MaxGasFee))
2425
baseTx.GasFeeCap = big.NewInt(gasFeeCap)
2526

2627
gasTipCap := baseTx.GasTipCap.Int64()
2728
gasTipCap = gasTipCap / 100 * int64(rate)
28-
gasTipCap = mathutil.MinInt64(gasFeeCap, mathutil.MinInt64(gasTipCap, int64(s.MaxGasFee)))
29+
gasTipCap = utils.Min(gasFeeCap, utils.Min(gasTipCap, int64(s.MaxGasFee)))
2930
baseTx.GasTipCap = big.NewInt(gasTipCap)
3031
case *types.BlobTx:
3132
gasFeeCap := baseTx.GasFeeCap.Uint64()
3233
gasFeeCap = gasFeeCap / 100 * rate
33-
gasFeeCap = mathutil.MinUint64(gasFeeCap, s.MaxGasFee)
34+
gasFeeCap = utils.Min(gasFeeCap, s.MaxGasFee)
3435
baseTx.GasFeeCap = uint256.NewInt(gasFeeCap)
3536

3637
gasTipCap := baseTx.GasTipCap.Uint64()
3738
gasTipCap = gasTipCap / 100 * rate
38-
gasTipCap = mathutil.MinUint64(gasFeeCap, mathutil.MinUint64(gasTipCap, s.MaxGasFee))
39+
gasTipCap = utils.Min(gasFeeCap, utils.Min(gasTipCap, s.MaxGasFee))
3940
baseTx.GasTipCap = uint256.NewInt(gasTipCap)
4041

4142
blobFeeCap := baseTx.BlobFeeCap.Uint64()
4243
blobFeeCap = blobFeeCap / 100 * rate
43-
blobFeeCap = mathutil.MinUint64(blobFeeCap, s.MaxBlobFee)
44+
blobFeeCap = utils.Min(blobFeeCap, s.MaxBlobFee)
4445
baseTx.BlobFeeCap = uint256.NewInt(blobFeeCap)
4546
default:
4647
log.Warn("Unsupported transaction type when adjust gas fee", "from", s.Opts.From)

internal/utils/utils.go

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ethereum/go-ethereum/log"
1212
"github.com/joho/godotenv"
1313
"github.com/modern-go/reflect2"
14+
"golang.org/x/exp/constraints"
1415
)
1516

1617
func LoadEnv() {
@@ -52,3 +53,19 @@ func RandUint32(max *big.Int) uint32 {
5253
func IsNil(i interface{}) bool {
5354
return reflect2.IsNil(i)
5455
}
56+
57+
// Min return the minimum value of two integers.
58+
func Min[T constraints.Integer](a, b T) T {
59+
if a < b {
60+
return a
61+
}
62+
return b
63+
}
64+
65+
// Max return the maximum value of two integers.
66+
func Max[T constraints.Integer](a, b T) T {
67+
if a > b {
68+
return a
69+
}
70+
return b
71+
}

0 commit comments

Comments
 (0)