Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EstimateGasLimit config name to EstimateLimit #14297

Merged
merged 5 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/loud-windows-call.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"chainlink": minor
---

Added gas limit estimation feature to EVM gas estimators #added
Added gas limit estimation feature to EVM gas estimators. Introduced a new config `EVM.GasEstimator.EstimateLimit` to toggle this feature. #added
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func (g *TestGasEstimatorConfig) LimitJobType() evmconfig.LimitJobType {
func (g *TestGasEstimatorConfig) PriceMaxKey(addr common.Address) *assets.Wei {
return assets.GWei(1)
}
func (g *TestGasEstimatorConfig) EstimateGasLimit() bool { return false }
func (g *TestGasEstimatorConfig) EstimateLimit() bool { return false }

func (e *TestEvmConfig) GasEstimator() evmconfig.GasEstimator {
return &TestGasEstimatorConfig{bumpThreshold: e.BumpThreshold}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/chain_scoped_gas_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (g *gasEstimatorConfig) LimitJobType() LimitJobType {
return &limitJobTypeConfig{c: g.c.LimitJobType}
}

func (g *gasEstimatorConfig) EstimateGasLimit() bool {
return *g.c.EstimateGasLimit
func (g *gasEstimatorConfig) EstimateLimit() bool {
return *g.c.EstimateLimit
}

type limitJobTypeConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type GasEstimator interface {
PriceMin() *assets.Wei
Mode() string
PriceMaxKey(gethcommon.Address) *assets.Wei
EstimateGasLimit() bool
EstimateLimit() bool
}

type LimitJobType interface {
Expand Down
1 change: 1 addition & 0 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func TestChainScopedConfig_GasEstimator(t *testing.T) {
assert.Equal(t, assets.GWei(100), ge.FeeCapDefault())
assert.Equal(t, assets.NewWeiI(1), ge.TipCapDefault())
assert.Equal(t, assets.NewWeiI(1), ge.TipCapMin())
assert.Equal(t, false, ge.EstimateLimit())
}

func TestChainScopedConfig_BSCDefaults(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions core/chains/evm/config/mocks/gas_estimator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,12 @@ type GasEstimator struct {
PriceMax *assets.Wei
PriceMin *assets.Wei

LimitDefault *uint64
LimitMax *uint64
LimitMultiplier *decimal.Decimal
LimitTransfer *uint64
LimitJobType GasLimitJobType `toml:",omitempty"`
EstimateGasLimit *bool
LimitDefault *uint64
LimitMax *uint64
LimitMultiplier *decimal.Decimal
LimitTransfer *uint64
LimitJobType GasLimitJobType `toml:",omitempty"`
EstimateLimit *bool

BumpMin *assets.Wei
BumpPercent *uint16
Expand Down Expand Up @@ -647,8 +647,8 @@ func (e *GasEstimator) setFrom(f *GasEstimator) {
if v := f.LimitTransfer; v != nil {
e.LimitTransfer = v
}
if v := f.EstimateGasLimit; v != nil {
e.EstimateGasLimit = v
if v := f.EstimateLimit; v != nil {
e.EstimateLimit = v
}
if v := f.PriceDefault; v != nil {
e.PriceDefault = v
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/toml/defaults/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ EIP1559DynamicFees = false
FeeCapDefault = '100 gwei'
TipCapDefault = '1'
TipCapMin = '1'
EstimateGasLimit = false
EstimateLimit = false

[GasEstimator.BlockHistory]
BatchSize = 25
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/gas/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type MockGasEstimatorConfig struct {
FeeCapDefaultF *assets.Wei
LimitMaxF uint64
ModeF string
EstimateGasLimitF bool
EstimateLimitF bool
}

func NewMockGasConfig() *MockGasEstimatorConfig {
Expand Down Expand Up @@ -216,6 +216,6 @@ func (m *MockGasEstimatorConfig) Mode() string {
return m.ModeF
}

func (m *MockGasEstimatorConfig) EstimateGasLimit() bool {
return m.EstimateGasLimitF
func (m *MockGasEstimatorConfig) EstimateLimit() bool {
return m.EstimateLimitF
}
10 changes: 5 additions & 5 deletions core/chains/evm/gas/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
)

// EstimateGasBuffer is a multiplier applied to estimated gas when the EstimateGasLimit feature is enabled
// EstimateGasBuffer is a multiplier applied to estimated gas when the EstimateLimit feature is enabled
const EstimateGasBuffer = float32(1.15)

// EvmFeeEstimator provides a unified interface that wraps EvmEstimator and can determine if legacy or dynamic fee estimation should be used
Expand Down Expand Up @@ -74,7 +74,7 @@ func NewEstimator(lggr logger.Logger, ethClient feeEstimatorClient, cfg Config,
"tipCapMin", geCfg.TipCapMin(),
"priceMax", geCfg.PriceMax(),
"priceMin", geCfg.PriceMin(),
"estimateGasLimit", geCfg.EstimateGasLimit(),
"estimateLimit", geCfg.EstimateLimit(),
)
df := geCfg.EIP1559DynamicFees()

Expand Down Expand Up @@ -352,8 +352,8 @@ func (e *evmFeeEstimator) estimateFeeLimit(ctx context.Context, feeLimit uint64,
if err != nil {
return estimatedFeeLimit, err
}
// Use provided fee limit by default if EstimateGasLimit is disabled
if !e.geCfg.EstimateGasLimit() {
// Use provided fee limit by default if EstimateLimit is disabled
if !e.geCfg.EstimateLimit() {
return providedGasLimit, nil
}
// Create call msg for gas limit estimation
Expand Down Expand Up @@ -417,7 +417,7 @@ type GasEstimatorConfig interface {
PriceMin() *assets.Wei
PriceMax() *assets.Wei
Mode() string
EstimateGasLimit() bool
EstimateLimit() bool
}

type BlockHistoryConfig interface {
Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
lggr := logger.Test(t)
// expect legacy fee data
dynamicFees := false
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(estimatedGasLimit, nil).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand All @@ -288,7 +288,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
lggr := logger.Test(t)
// expect legacy fee data
dynamicFees := false
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(estimatedGasLimit, nil).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand All @@ -306,7 +306,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
estimatedGasLimit := uint64(15) // same as provided limit
lggr := logger.Test(t)
dynamicFees := false // expect legacy fee data
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(estimatedGasLimit, nil).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand All @@ -331,7 +331,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
lggr := logger.Test(t)
// expect legacy fee data
dynamicFees := false
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(uint64(0), errors.New("something broke")).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand Down Expand Up @@ -362,7 +362,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
lggr := logger.Test(t)
// expect legacy fee data
dynamicFees := false
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(estimatedGasLimit, nil).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
lggr := logger.Test(t)
// expect legacy fee data
dynamicFees := false
geCfg.EstimateGasLimitF = true
geCfg.EstimateLimitF = true
ethClient := testutils.NewEthClientMockWithDefaultChain(t)
ethClient.On("EstimateGas", mock.Anything, mock.Anything).Return(uint64(0), errors.New("something broke")).Twice()
estimator := gas.NewEvmFeeEstimator(lggr, getRootEst, dynamicFees, geCfg, ethClient)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_GasEstimationError(t *testing.T)

db := pgtest.NewSqlxDB(t)
cfg := configtest.NewTestGeneralConfig(t)
cfg.EVMConfigs()[0].GasEstimator.EstimateGasLimit = ptr(true) // Enabled gas limit estimation
cfg.EVMConfigs()[0].GasEstimator.EstimateLimit = ptr(true) // Enabled gas limit estimation
limitMultiplier := float32(1.25)
cfg.EVMConfigs()[0].GasEstimator.LimitMultiplier = ptr(decimal.NewFromFloat32(limitMultiplier)) // Set LimitMultiplier for the buffer
txStore := cltest.NewTestTxStore(t, db)
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (g *TestGasEstimatorConfig) LimitTransfer() uint64 { return 42 }
func (g *TestGasEstimatorConfig) PriceMax() *assets.Wei { return assets.NewWeiI(42) }
func (g *TestGasEstimatorConfig) PriceMin() *assets.Wei { return assets.NewWeiI(42) }
func (g *TestGasEstimatorConfig) Mode() string { return "FixedPrice" }
func (g *TestGasEstimatorConfig) EstimateGasLimit() bool { return false }
func (g *TestGasEstimatorConfig) EstimateLimit() bool { return false }
func (g *TestGasEstimatorConfig) LimitJobType() evmconfig.LimitJobType {
return &TestLimitJobTypeConfig{}
}
Expand Down
4 changes: 2 additions & 2 deletions core/config/docs/chains-evm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ LimitMax = 500_000 # Default
LimitMultiplier = '1.0' # Default
# LimitTransfer is the gas limit used for an ordinary ETH transfer.
LimitTransfer = 21_000 # Default
# EstimateGasLimit enables estimating gas limits for transactions. This feature respects the gas limit provided during transaction creation as an upper bound.
EstimateGasLimit = false # Default
# EstimateLimit enables estimating gas limits for transactions. This feature respects the gas limit provided during transaction creation as an upper bound.
EstimateLimit = false # Default
# BumpMin is the minimum fixed amount of wei by which gas is bumped on each transaction attempt.
BumpMin = '5 gwei' # Default
# BumpPercent is the percentage by which to bump gas on a transaction that has exceeded `BumpThreshold`. The larger of `BumpPercent` and `BumpMin` is taken for gas bumps.
Expand Down
4 changes: 2 additions & 2 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func TestConfig_Marshal(t *testing.T) {
LimitMax: ptr[uint64](17),
LimitMultiplier: mustDecimal("1.234"),
LimitTransfer: ptr[uint64](100),
EstimateGasLimit: ptr(false),
EstimateLimit: ptr(false),
TipCapDefault: assets.NewWeiI(2),
TipCapMin: assets.NewWeiI(1),
PriceDefault: assets.NewWeiI(math.MaxInt64),
Expand Down Expand Up @@ -1041,7 +1041,7 @@ LimitDefault = 12
LimitMax = 17
LimitMultiplier = '1.234'
LimitTransfer = 100
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '100 wei'
BumpPercent = 10
BumpThreshold = 6
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ LimitDefault = 12
LimitMax = 17
LimitMultiplier = '1.234'
LimitTransfer = 100
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '100 wei'
BumpPercent = 10
BumpThreshold = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '5 gwei'
BumpPercent = 20
BumpThreshold = 3
Expand Down Expand Up @@ -418,7 +418,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '5 gwei'
BumpPercent = 20
BumpThreshold = 3
Expand Down Expand Up @@ -516,7 +516,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '20 gwei'
BumpPercent = 20
BumpThreshold = 5
Expand Down
2 changes: 1 addition & 1 deletion core/web/resolver/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ LimitDefault = 12
LimitMax = 17
LimitMultiplier = '1.234'
LimitTransfer = 100
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '100 wei'
BumpPercent = 10
BumpThreshold = 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '5 gwei'
BumpPercent = 20
BumpThreshold = 3
Expand Down Expand Up @@ -418,7 +418,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '5 gwei'
BumpPercent = 20
BumpThreshold = 3
Expand Down Expand Up @@ -516,7 +516,7 @@ LimitDefault = 500000
LimitMax = 500000
LimitMultiplier = '1'
LimitTransfer = 21000
EstimateGasLimit = false
EstimateLimit = false
BumpMin = '20 gwei'
BumpPercent = 20
BumpThreshold = 5
Expand Down
Loading
Loading