Skip to content

Commit

Permalink
Extracted Gas Limit Multiplier from gas estimators to WrappedEvmEstim…
Browse files Browse the repository at this point in the history
…ator (#12534)

* Applied LimitMultiplier to chainSpecificGasLimit in all gas estimators

* Added changeset

* altered tests to use a limit multiplier of 1.5 rather than 1

* improve some nits and refactor foundry tests (#12522)

* improve some nits and refactor foundry tests

* add changesets

* fix

* fix tests

* write registerUpkeep() foundry tests for auto v2.3 (#12535)

move addFunds() tests to foundry for auto v2.3

add tests for onTokenTransfer()

---------

Co-authored-by: Ryan Hall <RyanRHall@users.noreply.github.com>

* Added error checks

* updated existing tests

* Extracted fee limit multiplier out of indivudal gas estimators, into WrappedEvmEstimator

* Cleaned up unused LimitMultipliers

* Removed unused limit multipliers in tests and cleaned up

* removed chainSpecificGasLimit from BumpDynamicFee, GetDynamicFee

* Fixed failing tests

---------

Co-authored-by: FelixFan1992 <fankejin@gmail.com>
Co-authored-by: Ryan Hall <RyanRHall@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 28, 2024
1 parent a1bb52d commit bd532b5
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 204 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-suits-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Extracted Gas Limit Multiplier from gas estimators to WrappedEvmEstimator.
4 changes: 2 additions & 2 deletions core/chains/evm/gas/arbitrum_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestArbitrumEstimator(t *testing.T) {
rpcClient := mocks.NewRPCClient(t)
ethClient := mocks.NewETHClient(t)
o := gas.NewArbitrumEstimator(logger.Test(t), &arbConfig{}, rpcClient, ethClient)
_, _, err := o.GetDynamicFee(testutils.Context(t), gasLimit, maxGasPrice)
_, err := o.GetDynamicFee(testutils.Context(t), maxGasPrice)
assert.EqualError(t, err, "dynamic fees are not implemented for this estimator")
})

Expand All @@ -180,7 +180,7 @@ func TestArbitrumEstimator(t *testing.T) {
FeeCap: assets.NewWeiI(42),
TipCap: assets.NewWeiI(5),
}
_, _, err := o.BumpDynamicFee(testutils.Context(t), fee, gasLimit, maxGasPrice, nil)
_, err := o.BumpDynamicFee(testutils.Context(t), fee, maxGasPrice, nil)
assert.EqualError(t, err, "dynamic fees are not implemented for this estimator")
})

Expand Down
27 changes: 13 additions & 14 deletions core/chains/evm/gas/block_history_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ type chainConfig interface {
type estimatorGasEstimatorConfig interface {
EIP1559DynamicFees() bool
BumpThreshold() uint64
LimitMultiplier() float32
PriceDefault() *assets.Wei
TipCapDefault() *assets.Wei
TipCapMin() *assets.Wei
Expand Down Expand Up @@ -264,7 +263,7 @@ func (b *BlockHistoryEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLim
gasPrice = b.eConfig.PriceDefault()
}
gasPrice = capGasPrice(gasPrice, maxGasPriceWei, b.eConfig.PriceMax())
chainSpecificGasLimit, err = commonfee.ApplyMultiplier(gasLimit, b.eConfig.LimitMultiplier())
chainSpecificGasLimit = gasLimit
return
}

Expand Down Expand Up @@ -298,7 +297,11 @@ func (b *BlockHistoryEstimator) BumpLegacyGas(_ context.Context, originalGasPric
return nil, 0, err
}
}
return BumpLegacyGasPriceOnly(b.eConfig, b.logger, b.getGasPrice(), originalGasPrice, gasLimit, maxGasPriceWei)
bumpedGasPrice, err = BumpLegacyGasPriceOnly(b.eConfig, b.logger, b.getGasPrice(), originalGasPrice, maxGasPriceWei)
if err != nil {
return nil, 0, err
}
return bumpedGasPrice, gasLimit, err
}

// checkConnectivity detects if the transaction is not being included due to
Expand Down Expand Up @@ -388,18 +391,14 @@ func (b *BlockHistoryEstimator) checkConnectivity(attempts []EvmPriorAttempt) er
return nil
}

func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, gasLimit uint64, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint64, err error) {
func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error) {
if !b.eConfig.EIP1559DynamicFees() {
return fee, 0, pkgerrors.New("Can't get dynamic fee, EIP1559 is disabled")
return fee, pkgerrors.New("Can't get dynamic fee, EIP1559 is disabled")
}

var feeCap *assets.Wei
var tipCap *assets.Wei
ok := b.IfStarted(func() {
chainSpecificGasLimit, err = commonfee.ApplyMultiplier(gasLimit, b.eConfig.LimitMultiplier())
if err != nil {
return
}
b.priceMu.RLock()
defer b.priceMu.RUnlock()
tipCap = b.tipCap
Expand Down Expand Up @@ -431,10 +430,10 @@ func (b *BlockHistoryEstimator) GetDynamicFee(_ context.Context, gasLimit uint64
}
})
if !ok {
return fee, 0, pkgerrors.New("BlockHistoryEstimator is not started; cannot estimate gas")
return fee, pkgerrors.New("BlockHistoryEstimator is not started; cannot estimate gas")
}
if err != nil {
return fee, 0, err
return fee, err
}
fee.FeeCap = feeCap
fee.TipCap = tipCap
Expand All @@ -461,18 +460,18 @@ func calcFeeCap(latestAvailableBaseFeePerGas *assets.Wei, bufferBlocks int, tipC
return feeCap
}

func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, originalGasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) {
func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error) {
if b.bhConfig.CheckInclusionBlocks() > 0 {
if err = b.checkConnectivity(attempts); err != nil {
if pkgerrors.Is(err, commonfee.ErrConnectivity) {
b.logger.Criticalw(BumpingHaltedLabel, "err", err)
b.SvcErrBuffer.Append(err)
promBlockHistoryEstimatorConnectivityFailureCount.WithLabelValues(b.chainID.String(), "eip1559").Inc()
}
return bumped, 0, err
return bumped, err
}
}
return BumpDynamicFeeOnly(b.eConfig, b.bhConfig.EIP1559FeeCapBufferBlocks(), b.logger, b.getTipCap(), b.getCurrentBaseFee(), originalFee, originalGasLimit, maxGasPriceWei)
return BumpDynamicFeeOnly(b.eConfig, b.bhConfig.EIP1559FeeCapBufferBlocks(), b.logger, b.getTipCap(), b.getCurrentBaseFee(), originalFee, maxGasPriceWei)
}

func (b *BlockHistoryEstimator) runLoop() {
Expand Down
Loading

0 comments on commit bd532b5

Please sign in to comment.