diff --git a/.changeset/wicked-suits-watch.md b/.changeset/wicked-suits-watch.md new file mode 100644 index 00000000000..b4caf929a7a --- /dev/null +++ b/.changeset/wicked-suits-watch.md @@ -0,0 +1,5 @@ +--- +"chainlink": minor +--- + +Extracted Gas Limit Multiplier from gas estimators to WrappedEvmEstimator. \ No newline at end of file diff --git a/core/chains/evm/gas/arbitrum_estimator_test.go b/core/chains/evm/gas/arbitrum_estimator_test.go index afac9e03276..3c46b466e87 100644 --- a/core/chains/evm/gas/arbitrum_estimator_test.go +++ b/core/chains/evm/gas/arbitrum_estimator_test.go @@ -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") }) @@ -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") }) diff --git a/core/chains/evm/gas/block_history_estimator.go b/core/chains/evm/gas/block_history_estimator.go index fcd0d627063..cfe618219c8 100644 --- a/core/chains/evm/gas/block_history_estimator.go +++ b/core/chains/evm/gas/block_history_estimator.go @@ -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 @@ -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 } @@ -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 @@ -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 @@ -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 @@ -461,7 +460,7 @@ 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) { @@ -469,10 +468,10 @@ func (b *BlockHistoryEstimator) BumpDynamicFee(_ context.Context, originalFee Dy 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() { diff --git a/core/chains/evm/gas/block_history_estimator_test.go b/core/chains/evm/gas/block_history_estimator_test.go index f5ab06fc913..5260a22bff3 100644 --- a/core/chains/evm/gas/block_history_estimator_test.go +++ b/core/chains/evm/gas/block_history_estimator_test.go @@ -67,7 +67,6 @@ func TestBlockHistoryEstimator_Start(t *testing.T) { minGasPrice := assets.NewWeiI(1) maxGasPrice := assets.NewWeiI(100) - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMinF = minGasPrice geCfg.PriceMaxF = maxGasPrice @@ -112,7 +111,6 @@ func TestBlockHistoryEstimator_Start(t *testing.T) { t.Run("starts and loads partial history if fetch context times out", func(t *testing.T) { geCfg2 := &gas.MockGasEstimatorConfig{} geCfg2.EIP1559DynamicFeesF = true - geCfg2.LimitMultiplierF = float32(1) geCfg2.PriceMinF = minGasPrice bhCfg2 := newBlockHistoryConfig() @@ -188,7 +186,7 @@ func TestBlockHistoryEstimator_Start(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") - _, _, err = bhe.GetDynamicFee(testutils.Context(t), 100, maxGasPrice) + _, err = bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") }) @@ -211,7 +209,7 @@ func TestBlockHistoryEstimator_Start(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") - _, _, err = bhe.GetDynamicFee(testutils.Context(t), 100, maxGasPrice) + _, err = bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") }) @@ -252,7 +250,7 @@ func TestBlockHistoryEstimator_Start(t *testing.T) { require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") - _, _, err = bhe.GetDynamicFee(testutils.Context(t), 100, maxGasPrice) + _, err = bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.Error(t, err) require.Contains(t, err.Error(), "has not finished the first gas estimation yet, likely because a failure on start") }) @@ -1785,7 +1783,6 @@ func TestBlockHistoryEstimator_GetLegacyGas(t *testing.T) { maxGasPrice := assets.NewWeiI(1000000) geCfg := &gas.MockGasEstimatorConfig{} geCfg.EIP1559DynamicFeesF = false - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMaxF = maxGasPrice geCfg.PriceMinF = assets.NewWeiI(0) @@ -1828,7 +1825,6 @@ func TestBlockHistoryEstimator_GetLegacyGas(t *testing.T) { cfg = gas.NewMockConfig() - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMaxF = assets.NewWeiI(700) geCfg.PriceMinF = assets.NewWeiI(0) @@ -1867,7 +1863,6 @@ func TestBlockHistoryEstimator_UseDefaultPriceAsFallback(t *testing.T) { geCfg := &gas.MockGasEstimatorConfig{} geCfg.EIP1559DynamicFeesF = false - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMaxF = assets.NewWeiI(1000000) geCfg.PriceDefaultF = assets.NewWeiI(100) @@ -1917,7 +1912,6 @@ func TestBlockHistoryEstimator_UseDefaultPriceAsFallback(t *testing.T) { bhCfg.EIP1559FeeCapBufferBlocksF = uint16(4) geCfg := &gas.MockGasEstimatorConfig{} geCfg.EIP1559DynamicFeesF = true - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMaxF = assets.NewWeiI(1000000) geCfg.PriceDefaultF = assets.NewWeiI(100) geCfg.TipCapDefaultF = assets.NewWeiI(50) @@ -1952,11 +1946,10 @@ func TestBlockHistoryEstimator_UseDefaultPriceAsFallback(t *testing.T) { err := bhe.Start(testutils.Context(t)) require.NoError(t, err) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(200)) + fee, err := bhe.GetDynamicFee(testutils.Context(t), assets.NewWeiI(200)) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(114), TipCap: geCfg.TipCapDefault()}, fee) - assert.Equal(t, 100000, int(limit)) }) } @@ -1970,7 +1963,6 @@ func TestBlockHistoryEstimator_GetDynamicFee(t *testing.T) { bhCfg.TransactionPercentileF = uint16(35) geCfg := &gas.MockGasEstimatorConfig{} geCfg.EIP1559DynamicFeesF = true - geCfg.LimitMultiplierF = float32(1) geCfg.PriceMaxF = maxGasPrice geCfg.TipCapMinF = assets.NewWeiI(0) geCfg.PriceMinF = assets.NewWeiI(0) @@ -1999,7 +1991,7 @@ func TestBlockHistoryEstimator_GetDynamicFee(t *testing.T) { t.Run("if estimator is missing base fee and gas bumping is enabled", func(t *testing.T) { geCfg.BumpThresholdF = uint64(1) - _, _, err := bhe.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + _, err := bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.Error(t, err) assert.Contains(t, err.Error(), "BlockHistoryEstimator: no value for latest block base fee; cannot estimate EIP-1559 base fee. Are you trying to run with EIP1559 enabled on a non-EIP1559 chain?") }) @@ -2007,10 +1999,9 @@ func TestBlockHistoryEstimator_GetDynamicFee(t *testing.T) { t.Run("if estimator is missing base fee and gas bumping is disabled", func(t *testing.T) { geCfg.BumpThresholdF = uint64(0) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + fee, err := bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: maxGasPrice, TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) h := cltest.Head(1) @@ -2020,41 +2011,37 @@ func TestBlockHistoryEstimator_GetDynamicFee(t *testing.T) { t.Run("if gas bumping is enabled", func(t *testing.T) { geCfg.BumpThresholdF = uint64(1) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + fee, err := bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(186203), TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) t.Run("if gas bumping is disabled", func(t *testing.T) { geCfg.BumpThresholdF = uint64(0) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + fee, err := bhe.GetDynamicFee(testutils.Context(t), maxGasPrice) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: maxGasPrice, TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) t.Run("if gas bumping is enabled and local max gas price set", func(t *testing.T) { geCfg.BumpThresholdF = uint64(1) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(180000)) + fee, err := bhe.GetDynamicFee(testutils.Context(t), assets.NewWeiI(180000)) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(180000), TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) t.Run("if bump threshold is 0 and local max gas price set", func(t *testing.T) { geCfg.BumpThresholdF = uint64(0) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(100)) + fee, err := bhe.GetDynamicFee(testutils.Context(t), assets.NewWeiI(100)) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) h = cltest.Head(1) @@ -2064,11 +2051,10 @@ func TestBlockHistoryEstimator_GetDynamicFee(t *testing.T) { t.Run("if gas bumping is enabled and global max gas price lower than local max gas price", func(t *testing.T) { geCfg.BumpThresholdF = uint64(1) - fee, limit, err := bhe.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(1200000)) + fee, err := bhe.GetDynamicFee(testutils.Context(t), assets.NewWeiI(1200000)) require.NoError(t, err) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(1000000), TipCap: assets.NewWeiI(6000)}, fee) - assert.Equal(t, 100000, int(limit)) }) } @@ -2379,7 +2365,6 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { geCfg.BumpPercentF = 10 geCfg.BumpMinF = assets.NewWeiI(150) geCfg.PriceMaxF = maxGasPrice - geCfg.LimitMultiplierF = float32(1.1) bhe := newBlockHistoryEstimator(t, nil, cfg, geCfg, bhCfg) @@ -2409,7 +2394,6 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { geCfg.BumpPercentF = 10 geCfg.BumpMinF = assets.NewWeiI(150) geCfg.PriceMaxF = maxGasPrice - geCfg.LimitMultiplierF = float32(1.1) bhe := newBlockHistoryEstimator(t, nil, cfg, geCfg, bhCfg) @@ -2417,10 +2401,10 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { gasPrice, gasLimit, err := bhe.BumpLegacyGas(testutils.Context(t), assets.NewWeiI(42), 100000, maxGasPrice, nil) require.NoError(t, err) - expectedGasPrice, expectedGasLimit, err := gas.BumpLegacyGasPriceOnly(geCfg, logger.TestSugared(t), nil, assets.NewWeiI(42), 100000, maxGasPrice) + expectedGasPrice, err := gas.BumpLegacyGasPriceOnly(geCfg, logger.TestSugared(t), nil, assets.NewWeiI(42), maxGasPrice) require.NoError(t, err) - assert.Equal(t, expectedGasLimit, gasLimit) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, expectedGasPrice, gasPrice) }) @@ -2431,10 +2415,10 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { massive := assets.NewWeiI(100000000000000) gas.SetGasPrice(bhe, massive) - expectedGasPrice, expectedGasLimit, err := gas.BumpLegacyGasPriceOnly(geCfg, logger.TestSugared(t), massive, assets.NewWeiI(42), 100000, maxGasPrice) + expectedGasPrice, err := gas.BumpLegacyGasPriceOnly(geCfg, logger.TestSugared(t), massive, assets.NewWeiI(42), maxGasPrice) require.NoError(t, err) - assert.Equal(t, expectedGasLimit, gasLimit) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, expectedGasPrice, gasPrice) }) @@ -2444,7 +2428,7 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { gasPrice, gasLimit, err := bhe.BumpLegacyGas(testutils.Context(t), assets.NewWeiI(42), 100000, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(192), gasPrice) }) @@ -2454,7 +2438,7 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { gasPrice, gasLimit, err := bhe.BumpLegacyGas(testutils.Context(t), assets.NewWeiI(42), 100000, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(193), gasPrice) }) @@ -2491,7 +2475,6 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { geCfg.BumpPercentF = 10 geCfg.BumpMinF = assets.NewWeiI(150) geCfg.PriceMaxF = maxGasPrice - geCfg.LimitMultiplierF = float32(1.1) bhe := newBlockHistoryEstimator(t, nil, cfg, geCfg, bhCfg) @@ -2509,7 +2492,7 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { attempts := []gas.EvmPriorAttempt{ {TxType: 0x2, TxHash: NewEvmHash(), DynamicFee: gas.DynamicFee{TipCap: originalFee.TipCap, FeeCap: originalFee.FeeCap}, BroadcastBeforeBlockNum: testutils.Ptr(int64(0))}} - _, _, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, attempts) + _, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, attempts) require.Error(t, err) assert.True(t, pkgerrors.Is(err, commonfee.ErrConnectivity)) assert.Contains(t, err.Error(), fmt.Sprintf("transaction %s has tip cap of 25 wei, which is above percentile=10%% (percentile tip cap: 1 wei) for blocks 1 thru 1 (checking 1 blocks)", attempts[0].TxHash)) @@ -2524,47 +2507,42 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { geCfg.BumpPercentF = 10 geCfg.BumpMinF = assets.NewWeiI(150) geCfg.PriceMaxF = maxGasPrice - geCfg.LimitMultiplierF = float32(1.1) geCfg.TipCapDefaultF = assets.NewWeiI(52) bhe := newBlockHistoryEstimator(t, nil, cfg, geCfg, bhCfg) t.Run("when current tip cap is nil", func(t *testing.T) { originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(250), TipCap: assets.NewWeiI(202)}, fee) }) t.Run("ignores current tip cap that is smaller than original fee with bump applied", func(t *testing.T) { gas.SetTipCap(bhe, assets.NewWeiI(201)) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(250), TipCap: assets.NewWeiI(202)}, fee) }) t.Run("uses current tip cap that is larger than original fee with bump applied", func(t *testing.T) { gas.SetTipCap(bhe, assets.NewWeiI(203)) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(250), TipCap: assets.NewWeiI(203)}, fee) }) t.Run("ignores absurdly large current tip cap", func(t *testing.T) { gas.SetTipCap(bhe, assets.NewWeiI(1000000000000000)) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, gas.DynamicFee{FeeCap: assets.NewWeiI(250), TipCap: assets.NewWeiI(202)}, fee) }) @@ -2572,10 +2550,9 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { gas.SetTipCap(bhe, assets.NewWeiI(203)) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(990000)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.Error(t, err) - assert.Equal(t, 0, int(gasLimit)) assert.Equal(t, gas.DynamicFee{}, fee) assert.Contains(t, err.Error(), "bumped tip cap of 1.089 mwei would exceed configured max gas price of 1 mwei (original fee: tip cap 990 kwei, fee cap 100 wei)") }) @@ -2584,10 +2561,9 @@ func TestBlockHistoryEstimator_Bumps(t *testing.T) { gas.SetTipCap(bhe, assets.NewWeiI(203)) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(990000), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := bhe.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.Error(t, err) - assert.Equal(t, 0, int(gasLimit)) assert.Equal(t, gas.DynamicFee{}, fee) assert.Contains(t, err.Error(), "bumped fee cap of 1.089 mwei would exceed configured max gas price of 1 mwei (original fee: tip cap 25 wei, fee cap 990 kwei)") }) diff --git a/core/chains/evm/gas/fixed_price_estimator.go b/core/chains/evm/gas/fixed_price_estimator.go index 53b7e93a871..fc65413d375 100644 --- a/core/chains/evm/gas/fixed_price_estimator.go +++ b/core/chains/evm/gas/fixed_price_estimator.go @@ -30,7 +30,6 @@ type bumpConfig interface { type fixedPriceEstimatorConfig interface { BumpThreshold() uint64 FeeCapDefault() *assets.Wei - LimitMultiplier() float32 PriceDefault() *assets.Wei TipCapDefault() *assets.Wei PriceMax() *assets.Wei @@ -60,10 +59,7 @@ func (f *fixedPriceEstimator) Start(context.Context) error { func (f *fixedPriceEstimator) GetLegacyGas(_ context.Context, _ []byte, gasLimit uint64, maxGasPriceWei *assets.Wei, _ ...feetypes.Opt) (*assets.Wei, uint64, error) { gasPrice := commonfee.CalculateFee(f.config.PriceDefault().ToInt(), maxGasPriceWei.ToInt(), f.config.PriceMax().ToInt()) - chainSpecificGasLimit, err := commonfee.ApplyMultiplier(gasLimit, f.config.LimitMultiplier()) - if err != nil { - return nil, 0, err - } + chainSpecificGasLimit := gasLimit return assets.NewWei(gasPrice), chainSpecificGasLimit, nil } @@ -88,22 +84,15 @@ func (f *fixedPriceEstimator) BumpLegacyGas( return nil, 0, err } - chainSpecificGasLimit, err := commonfee.ApplyMultiplier(originalGasLimit, f.config.LimitMultiplier()) - if err != nil { - return nil, 0, err - } + chainSpecificGasLimit := originalGasLimit return assets.NewWei(gasPrice), chainSpecificGasLimit, err } -func (f *fixedPriceEstimator) GetDynamicFee(_ context.Context, originalGasLimit uint64, maxGasPriceWei *assets.Wei) (d DynamicFee, chainSpecificGasLimit uint64, err error) { +func (f *fixedPriceEstimator) GetDynamicFee(_ context.Context, maxGasPriceWei *assets.Wei) (d DynamicFee, err error) { gasTipCap := f.config.TipCapDefault() if gasTipCap == nil { - return d, 0, pkgerrors.New("cannot calculate dynamic fee: EthGasTipCapDefault was not set") - } - chainSpecificGasLimit, err = commonfee.ApplyMultiplier(originalGasLimit, f.config.LimitMultiplier()) - if err != nil { - return d, 0, err + return d, pkgerrors.New("cannot calculate dynamic fee: EthGasTipCapDefault was not set") } var feeCap *assets.Wei @@ -118,16 +107,15 @@ func (f *fixedPriceEstimator) GetDynamicFee(_ context.Context, originalGasLimit return DynamicFee{ FeeCap: feeCap, TipCap: gasTipCap, - }, chainSpecificGasLimit, nil + }, nil } func (f *fixedPriceEstimator) BumpDynamicFee( _ context.Context, originalFee DynamicFee, - originalGasLimit uint64, maxGasPriceWei *assets.Wei, _ []EvmPriorAttempt, -) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) { +) (bumped DynamicFee, err error) { return BumpDynamicFeeOnly( f.config, @@ -136,7 +124,6 @@ func (f *fixedPriceEstimator) BumpDynamicFee( f.config.TipCapDefault(), nil, originalFee, - originalGasLimit, maxGasPriceWei, ) } diff --git a/core/chains/evm/gas/fixed_price_estimator_test.go b/core/chains/evm/gas/fixed_price_estimator_test.go index 968275ace48..c31bd41aeee 100644 --- a/core/chains/evm/gas/fixed_price_estimator_test.go +++ b/core/chains/evm/gas/fixed_price_estimator_test.go @@ -24,50 +24,46 @@ func Test_FixedPriceEstimator(t *testing.T) { t.Parallel() maxGasPrice := assets.NewWeiI(1000000) - t.Run("GetLegacyGas returns EvmGasPriceDefault from config, with multiplier applied", func(t *testing.T) { + t.Run("GetLegacyGas returns EvmGasPriceDefault from config", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t)) config.PriceDefaultF = assets.NewWeiI(42) - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = maxGasPrice gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, maxGasPrice) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(42), gasPrice) }) t.Run("GetLegacyGas returns user specified maximum gas price", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} config.PriceDefaultF = assets.NewWeiI(42) - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = assets.NewWeiI(35) f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t)) gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, assets.NewWeiI(30)) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(30), gasPrice) }) t.Run("GetLegacyGas returns global maximum gas price", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} config.PriceDefaultF = assets.NewWeiI(42) - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = assets.NewWeiI(20) f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, logger.Test(t)) gasPrice, gasLimit, err := f.GetLegacyGas(testutils.Context(t), nil, 100000, assets.NewWeiI(30)) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(20), gasPrice) }) t.Run("BumpLegacyGas calls BumpLegacyGasPriceOnly", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} config.PriceDefaultF = assets.NewWeiI(42) - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = maxGasPrice config.BumpPercentF = uint16(10) config.BumpMinF = assets.NewWeiI(150) @@ -78,16 +74,15 @@ func Test_FixedPriceEstimator(t *testing.T) { gasPrice, gasLimit, err := f.BumpLegacyGas(testutils.Context(t), assets.NewWeiI(42), 100000, maxGasPrice, nil) require.NoError(t, err) - expectedGasPrice, expectedGasLimit, err := gas.BumpLegacyGasPriceOnly(config, lggr, nil, assets.NewWeiI(42), 100000, maxGasPrice) + expectedGasPrice, err := gas.BumpLegacyGasPriceOnly(config, lggr, nil, assets.NewWeiI(42), maxGasPrice) require.NoError(t, err) - assert.Equal(t, expectedGasLimit, gasLimit) + assert.Equal(t, 100000, int(gasLimit)) assert.Equal(t, expectedGasPrice, gasPrice) }) - t.Run("GetDynamicFee returns defaults from config, with multiplier applied", func(t *testing.T) { + t.Run("GetDynamicFee returns defaults from config", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = maxGasPrice config.TipCapDefaultF = assets.NewWeiI(52) config.FeeCapDefaultF = assets.NewWeiI(100) @@ -96,9 +91,8 @@ func Test_FixedPriceEstimator(t *testing.T) { lggr := logger.Test(t) f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, lggr) - fee, gasLimit, err := f.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + fee, err := f.GetDynamicFee(testutils.Context(t), maxGasPrice) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(52), fee.TipCap) assert.Equal(t, assets.NewWeiI(100), fee.FeeCap) @@ -106,17 +100,15 @@ func Test_FixedPriceEstimator(t *testing.T) { // Gas bumping disabled config.BumpThresholdF = uint64(0) - fee, gasLimit, err = f.GetDynamicFee(testutils.Context(t), 100000, maxGasPrice) + fee, err = f.GetDynamicFee(testutils.Context(t), maxGasPrice) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(52), fee.TipCap) assert.Equal(t, maxGasPrice, fee.FeeCap) // override max gas price - fee, gasLimit, err = f.GetDynamicFee(testutils.Context(t), 100000, assets.NewWeiI(10)) + fee, err = f.GetDynamicFee(testutils.Context(t), assets.NewWeiI(10)) require.NoError(t, err) - assert.Equal(t, 110000, int(gasLimit)) assert.Equal(t, assets.NewWeiI(52), fee.TipCap) assert.Equal(t, assets.NewWeiI(10), fee.FeeCap) @@ -124,7 +116,6 @@ func Test_FixedPriceEstimator(t *testing.T) { t.Run("BumpDynamicFee calls BumpDynamicFeeOnly", func(t *testing.T) { config := &gas.MockGasEstimatorConfig{} - config.LimitMultiplierF = float32(1.1) config.PriceMaxF = maxGasPrice config.TipCapDefaultF = assets.NewWeiI(52) config.BumpMinF = assets.NewWeiI(150) @@ -134,13 +125,12 @@ func Test_FixedPriceEstimator(t *testing.T) { f := gas.NewFixedPriceEstimator(config, &blockHistoryConfig{}, lggr) originalFee := gas.DynamicFee{FeeCap: assets.NewWeiI(100), TipCap: assets.NewWeiI(25)} - fee, gasLimit, err := f.BumpDynamicFee(testutils.Context(t), originalFee, 100000, maxGasPrice, nil) + fee, err := f.BumpDynamicFee(testutils.Context(t), originalFee, maxGasPrice, nil) require.NoError(t, err) - expectedFee, expectedGasLimit, err := gas.BumpDynamicFeeOnly(config, 0, lggr, nil, nil, originalFee, 100000, maxGasPrice) + expectedFee, err := gas.BumpDynamicFeeOnly(config, 0, lggr, nil, nil, originalFee, maxGasPrice) require.NoError(t, err) - assert.Equal(t, expectedGasLimit, gasLimit) assert.Equal(t, expectedFee, fee) }) } diff --git a/core/chains/evm/gas/gas_test.go b/core/chains/evm/gas/gas_test.go index 43a1506bc24..8f3d56b54e7 100644 --- a/core/chains/evm/gas/gas_test.go +++ b/core/chains/evm/gas/gas_test.go @@ -5,7 +5,6 @@ import ( "math/big" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -95,12 +94,11 @@ func Test_BumpLegacyGasPriceOnly(t *testing.T) { cfg.BumpMinF = test.bumpMin cfg.PriceMaxF = test.priceMax cfg.LimitMultiplierF = test.limitMultiplierPercent - actual, limit, err := gas.BumpLegacyGasPriceOnly(cfg, logger.TestSugared(t), test.currentGasPrice, test.originalGasPrice, test.originalLimit, test.priceMax) + actual, err := gas.BumpLegacyGasPriceOnly(cfg, logger.TestSugared(t), test.currentGasPrice, test.originalGasPrice, test.priceMax) require.NoError(t, err) if actual.Cmp(test.expectedGasPrice) != 0 { t.Fatalf("Expected %s but got %s", test.expectedGasPrice.String(), actual.String()) } - assert.Equal(t, int(test.expectedLimit), int(limit)) }) } } @@ -115,7 +113,7 @@ func Test_BumpLegacyGasPriceOnly_HitsMaxError(t *testing.T) { cfg.PriceMaxF = priceMax originalGasPrice := toWei("3e10") // 30 GWei - _, _, err := gas.BumpLegacyGasPriceOnly(cfg, logger.TestSugared(t), nil, originalGasPrice, 42, priceMax) + _, err := gas.BumpLegacyGasPriceOnly(cfg, logger.TestSugared(t), nil, originalGasPrice, priceMax) require.Error(t, err) require.Contains(t, err.Error(), "bumped gas price of 45 gwei would exceed configured max gas price of 40 gwei (original price was 30 gwei)") } @@ -132,13 +130,13 @@ func Test_BumpLegacyGasPriceOnly_NoBumpError(t *testing.T) { cfg.PriceMaxF = priceMax originalGasPrice := toWei("3e10") // 30 GWei - _, _, err := gas.BumpLegacyGasPriceOnly(cfg, lggr, nil, originalGasPrice, 42, priceMax) + _, err := gas.BumpLegacyGasPriceOnly(cfg, lggr, nil, originalGasPrice, priceMax) require.Error(t, err) require.Contains(t, err.Error(), "bumped gas price of 30 gwei is equal to original gas price of 30 gwei. ACTION REQUIRED: This is a configuration error, you must increase either EVM.GasEstimator.BumpPercent or EVM.GasEstimator.BumpMin") // Even if it's exactly the maximum originalGasPrice = toWei("4e10") // 40 GWei - _, _, err = gas.BumpLegacyGasPriceOnly(cfg, lggr, nil, originalGasPrice, 42, priceMax) + _, err = gas.BumpLegacyGasPriceOnly(cfg, lggr, nil, originalGasPrice, priceMax) require.Error(t, err) require.Contains(t, err.Error(), "bumped gas price of 40 gwei is equal to original gas price of 40 gwei. ACTION REQUIRED: This is a configuration error, you must increase either EVM.GasEstimator.BumpPercent or EVM.GasEstimator.BumpMin") } @@ -298,7 +296,7 @@ func Test_BumpDynamicFeeOnly(t *testing.T) { cfg.LimitMultiplierF = test.limitMultiplierPercent bufferBlocks := uint16(4) - actual, limit, err := gas.BumpDynamicFeeOnly(cfg, bufferBlocks, logger.TestSugared(t), test.currentTipCap, test.currentBaseFee, test.originalFee, test.originalLimit, test.priceMax) + actual, err := gas.BumpDynamicFeeOnly(cfg, bufferBlocks, logger.TestSugared(t), test.currentTipCap, test.currentBaseFee, test.originalFee, test.priceMax) require.NoError(t, err) if actual.TipCap.Cmp(test.expectedFee.TipCap) != 0 { t.Fatalf("TipCap not equal, expected %s but got %s", test.expectedFee.TipCap.String(), actual.TipCap.String()) @@ -306,7 +304,6 @@ func Test_BumpDynamicFeeOnly(t *testing.T) { if actual.FeeCap.Cmp(test.expectedFee.FeeCap) != 0 { t.Fatalf("FeeCap not equal, expected %s but got %s", test.expectedFee.FeeCap.String(), actual.FeeCap.String()) } - assert.Equal(t, int(test.expectedLimit), int(limit)) }) } } @@ -324,14 +321,14 @@ func Test_BumpDynamicFeeOnly_HitsMaxError(t *testing.T) { t.Run("tip cap hits max", func(t *testing.T) { originalFee := gas.DynamicFee{TipCap: assets.GWei(30), FeeCap: assets.GWei(100)} - _, _, err := gas.BumpDynamicFeeOnly(cfg, 0, logger.TestSugared(t), nil, nil, originalFee, 42, priceMax) + _, err := gas.BumpDynamicFeeOnly(cfg, 0, logger.TestSugared(t), nil, nil, originalFee, priceMax) require.Error(t, err) require.Contains(t, err.Error(), "bumped tip cap of 45 gwei would exceed configured max gas price of 40 gwei (original fee: tip cap 30 gwei, fee cap 100 gwei)") }) t.Run("fee cap hits max", func(t *testing.T) { originalFee := gas.DynamicFee{TipCap: assets.GWei(10), FeeCap: assets.GWei(100)} - _, _, err := gas.BumpDynamicFeeOnly(cfg, 0, logger.TestSugared(t), nil, nil, originalFee, 42, priceMax) + _, err := gas.BumpDynamicFeeOnly(cfg, 0, logger.TestSugared(t), nil, nil, originalFee, priceMax) require.Error(t, err) require.Contains(t, err.Error(), "bumped fee cap of 150 gwei would exceed configured max gas price of 40 gwei (original fee: tip cap 10 gwei, fee cap 100 gwei)") }) diff --git a/core/chains/evm/gas/helpers_test.go b/core/chains/evm/gas/helpers_test.go index 908674bbeeb..420c5060a90 100644 --- a/core/chains/evm/gas/helpers_test.go +++ b/core/chains/evm/gas/helpers_test.go @@ -147,6 +147,10 @@ type MockGasEstimatorConfig struct { ModeF string } +func NewMockGasConfig() *MockGasEstimatorConfig { + return &MockGasEstimatorConfig{} +} + func (m *MockGasEstimatorConfig) BumpPercent() uint16 { return m.BumpPercentF } diff --git a/core/chains/evm/gas/mocks/evm_estimator.go b/core/chains/evm/gas/mocks/evm_estimator.go index f9ea34b830d..a0b6fa62432 100644 --- a/core/chains/evm/gas/mocks/evm_estimator.go +++ b/core/chains/evm/gas/mocks/evm_estimator.go @@ -21,39 +21,32 @@ type EvmEstimator struct { mock.Mock } -// BumpDynamicFee provides a mock function with given fields: ctx, original, gasLimit, maxGasPriceWei, attempts -func (_m *EvmEstimator) BumpDynamicFee(ctx context.Context, original gas.DynamicFee, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []gas.EvmPriorAttempt) (gas.DynamicFee, uint64, error) { - ret := _m.Called(ctx, original, gasLimit, maxGasPriceWei, attempts) +// BumpDynamicFee provides a mock function with given fields: ctx, original, maxGasPriceWei, attempts +func (_m *EvmEstimator) BumpDynamicFee(ctx context.Context, original gas.DynamicFee, maxGasPriceWei *assets.Wei, attempts []gas.EvmPriorAttempt) (gas.DynamicFee, error) { + ret := _m.Called(ctx, original, maxGasPriceWei, attempts) if len(ret) == 0 { panic("no return value specified for BumpDynamicFee") } var r0 gas.DynamicFee - var r1 uint64 - var r2 error - if rf, ok := ret.Get(0).(func(context.Context, gas.DynamicFee, uint64, *assets.Wei, []gas.EvmPriorAttempt) (gas.DynamicFee, uint64, error)); ok { - return rf(ctx, original, gasLimit, maxGasPriceWei, attempts) + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, gas.DynamicFee, *assets.Wei, []gas.EvmPriorAttempt) (gas.DynamicFee, error)); ok { + return rf(ctx, original, maxGasPriceWei, attempts) } - if rf, ok := ret.Get(0).(func(context.Context, gas.DynamicFee, uint64, *assets.Wei, []gas.EvmPriorAttempt) gas.DynamicFee); ok { - r0 = rf(ctx, original, gasLimit, maxGasPriceWei, attempts) + if rf, ok := ret.Get(0).(func(context.Context, gas.DynamicFee, *assets.Wei, []gas.EvmPriorAttempt) gas.DynamicFee); ok { + r0 = rf(ctx, original, maxGasPriceWei, attempts) } else { r0 = ret.Get(0).(gas.DynamicFee) } - if rf, ok := ret.Get(1).(func(context.Context, gas.DynamicFee, uint64, *assets.Wei, []gas.EvmPriorAttempt) uint64); ok { - r1 = rf(ctx, original, gasLimit, maxGasPriceWei, attempts) - } else { - r1 = ret.Get(1).(uint64) - } - - if rf, ok := ret.Get(2).(func(context.Context, gas.DynamicFee, uint64, *assets.Wei, []gas.EvmPriorAttempt) error); ok { - r2 = rf(ctx, original, gasLimit, maxGasPriceWei, attempts) + if rf, ok := ret.Get(1).(func(context.Context, gas.DynamicFee, *assets.Wei, []gas.EvmPriorAttempt) error); ok { + r1 = rf(ctx, original, maxGasPriceWei, attempts) } else { - r2 = ret.Error(2) + r1 = ret.Error(1) } - return r0, r1, r2 + return r0, r1 } // BumpLegacyGas provides a mock function with given fields: ctx, originalGasPrice, gasLimit, maxGasPriceWei, attempts @@ -111,39 +104,32 @@ func (_m *EvmEstimator) Close() error { return r0 } -// GetDynamicFee provides a mock function with given fields: ctx, gasLimit, maxGasPriceWei -func (_m *EvmEstimator) GetDynamicFee(ctx context.Context, gasLimit uint64, maxGasPriceWei *assets.Wei) (gas.DynamicFee, uint64, error) { - ret := _m.Called(ctx, gasLimit, maxGasPriceWei) +// GetDynamicFee provides a mock function with given fields: ctx, maxGasPriceWei +func (_m *EvmEstimator) GetDynamicFee(ctx context.Context, maxGasPriceWei *assets.Wei) (gas.DynamicFee, error) { + ret := _m.Called(ctx, maxGasPriceWei) if len(ret) == 0 { panic("no return value specified for GetDynamicFee") } var r0 gas.DynamicFee - var r1 uint64 - var r2 error - if rf, ok := ret.Get(0).(func(context.Context, uint64, *assets.Wei) (gas.DynamicFee, uint64, error)); ok { - return rf(ctx, gasLimit, maxGasPriceWei) + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *assets.Wei) (gas.DynamicFee, error)); ok { + return rf(ctx, maxGasPriceWei) } - if rf, ok := ret.Get(0).(func(context.Context, uint64, *assets.Wei) gas.DynamicFee); ok { - r0 = rf(ctx, gasLimit, maxGasPriceWei) + if rf, ok := ret.Get(0).(func(context.Context, *assets.Wei) gas.DynamicFee); ok { + r0 = rf(ctx, maxGasPriceWei) } else { r0 = ret.Get(0).(gas.DynamicFee) } - if rf, ok := ret.Get(1).(func(context.Context, uint64, *assets.Wei) uint64); ok { - r1 = rf(ctx, gasLimit, maxGasPriceWei) - } else { - r1 = ret.Get(1).(uint64) - } - - if rf, ok := ret.Get(2).(func(context.Context, uint64, *assets.Wei) error); ok { - r2 = rf(ctx, gasLimit, maxGasPriceWei) + if rf, ok := ret.Get(1).(func(context.Context, *assets.Wei) error); ok { + r1 = rf(ctx, maxGasPriceWei) } else { - r2 = ret.Error(2) + r1 = ret.Error(1) } - return r0, r1, r2 + return r0, r1 } // GetLegacyGas provides a mock function with given fields: ctx, calldata, gasLimit, maxGasPriceWei, opts diff --git a/core/chains/evm/gas/models.go b/core/chains/evm/gas/models.go index ae041615f53..17ee6f6d405 100644 --- a/core/chains/evm/gas/models.go +++ b/core/chains/evm/gas/models.go @@ -95,7 +95,7 @@ func NewEstimator(lggr logger.Logger, ethClient evmclient.Client, cfg Config, ge return NewFixedPriceEstimator(geCfg, bh, lggr) } } - return NewWrappedEvmEstimator(lggr, newEstimator, df, l1Oracle) + return NewWrappedEvmEstimator(lggr, newEstimator, df, l1Oracle, geCfg) } // DynamicFee encompasses both FeeCap and TipCap for EIP1559 transactions @@ -131,13 +131,13 @@ type EvmEstimator interface { BumpLegacyGas(ctx context.Context, originalGasPrice *assets.Wei, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumpedGasPrice *assets.Wei, chainSpecificGasLimit uint64, err error) // GetDynamicFee Calculates initial gas fee for gas for EIP1559 transactions // maxGasPriceWei parameter is the highest possible gas fee cap that the function will return - GetDynamicFee(ctx context.Context, gasLimit uint64, maxGasPriceWei *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint64, err error) + GetDynamicFee(ctx context.Context, maxGasPriceWei *assets.Wei) (fee DynamicFee, err error) // BumpDynamicFee Increases gas price and/or limit for non-EIP1559 transactions // if the bumped gas fee or tip caps are greater than maxGasPriceWei, the method returns an error // attempts must: // - be sorted in order from highest price to lowest price // - all be of transaction type 0x2 - BumpDynamicFee(ctx context.Context, original DynamicFee, gasLimit uint64, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) + BumpDynamicFee(ctx context.Context, original DynamicFee, maxGasPriceWei *assets.Wei, attempts []EvmPriorAttempt) (bumped DynamicFee, err error) } var _ feetypes.Fee = (*EvmFee)(nil) @@ -166,17 +166,19 @@ type WrappedEvmEstimator struct { EvmEstimator EIP1559Enabled bool l1Oracle rollups.L1Oracle + geCfg GasEstimatorConfig } var _ EvmFeeEstimator = (*WrappedEvmEstimator)(nil) -func NewWrappedEvmEstimator(lggr logger.Logger, newEstimator func(logger.Logger) EvmEstimator, eip1559Enabled bool, l1Oracle rollups.L1Oracle) EvmFeeEstimator { +func NewWrappedEvmEstimator(lggr logger.Logger, newEstimator func(logger.Logger) EvmEstimator, eip1559Enabled bool, l1Oracle rollups.L1Oracle, geCfg GasEstimatorConfig) EvmFeeEstimator { lggr = logger.Named(lggr, "WrappedEvmEstimator") return &WrappedEvmEstimator{ lggr: lggr, EvmEstimator: newEstimator(lggr), EIP1559Enabled: eip1559Enabled, l1Oracle: l1Oracle, + geCfg: geCfg, } } @@ -245,7 +247,11 @@ func (e *WrappedEvmEstimator) GetFee(ctx context.Context, calldata []byte, feeLi // get dynamic fee if e.EIP1559Enabled { var dynamicFee DynamicFee - dynamicFee, chainSpecificFeeLimit, err = e.EvmEstimator.GetDynamicFee(ctx, feeLimit, maxFeePrice) + dynamicFee, err = e.EvmEstimator.GetDynamicFee(ctx, maxFeePrice) + if err != nil { + return + } + chainSpecificFeeLimit, err = commonfee.ApplyMultiplier(feeLimit, e.geCfg.LimitMultiplier()) fee.DynamicFeeCap = dynamicFee.FeeCap fee.DynamicTipCap = dynamicFee.TipCap return @@ -253,6 +259,11 @@ func (e *WrappedEvmEstimator) GetFee(ctx context.Context, calldata []byte, feeLi // get legacy fee fee.Legacy, chainSpecificFeeLimit, err = e.EvmEstimator.GetLegacyGas(ctx, calldata, feeLimit, maxFeePrice, opts...) + if err != nil { + return + } + chainSpecificFeeLimit, err = commonfee.ApplyMultiplier(chainSpecificFeeLimit, e.geCfg.LimitMultiplier()) + return } @@ -285,11 +296,15 @@ func (e *WrappedEvmEstimator) BumpFee(ctx context.Context, originalFee EvmFee, f // bump dynamic original if originalFee.ValidDynamic() { var bumpedDynamic DynamicFee - bumpedDynamic, chainSpecificFeeLimit, err = e.EvmEstimator.BumpDynamicFee(ctx, + bumpedDynamic, err = e.EvmEstimator.BumpDynamicFee(ctx, DynamicFee{ TipCap: originalFee.DynamicTipCap, FeeCap: originalFee.DynamicFeeCap, - }, feeLimit, maxFeePrice, attempts) + }, maxFeePrice, attempts) + if err != nil { + return + } + chainSpecificFeeLimit, err = commonfee.ApplyMultiplier(feeLimit, e.geCfg.LimitMultiplier()) bumpedFee.DynamicFeeCap = bumpedDynamic.FeeCap bumpedFee.DynamicTipCap = bumpedDynamic.TipCap return @@ -297,6 +312,10 @@ func (e *WrappedEvmEstimator) BumpFee(ctx context.Context, originalFee EvmFee, f // bump legacy fee bumpedFee.Legacy, chainSpecificFeeLimit, err = e.EvmEstimator.BumpLegacyGas(ctx, originalFee.Legacy, feeLimit, maxFeePrice, attempts) + if err != nil { + return + } + chainSpecificFeeLimit, err = commonfee.ApplyMultiplier(chainSpecificFeeLimit, e.geCfg.LimitMultiplier()) return } @@ -355,13 +374,12 @@ func HexToInt64(input interface{}) int64 { } } -// BumpLegacyGasPriceOnly will increase the price and apply multiplier to the gas limit -func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, currentGasPrice, originalGasPrice *assets.Wei, originalGasLimit uint64, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, chainSpecificGasLimit uint64, err error) { +// BumpLegacyGasPriceOnly will increase the price +func BumpLegacyGasPriceOnly(cfg bumpConfig, lggr logger.SugaredLogger, currentGasPrice, originalGasPrice *assets.Wei, maxGasPriceWei *assets.Wei) (gasPrice *assets.Wei, err error) { gasPrice, err = bumpGasPrice(cfg, lggr, currentGasPrice, originalGasPrice, maxGasPriceWei) if err != nil { - return nil, 0, err + return nil, err } - chainSpecificGasLimit, err = commonfee.ApplyMultiplier(originalGasLimit, cfg.LimitMultiplier()) return } @@ -391,12 +409,11 @@ func bumpGasPrice(cfg bumpConfig, lggr logger.SugaredLogger, currentGasPrice, or } // BumpDynamicFeeOnly bumps the tip cap and max gas price if necessary -func BumpDynamicFeeOnly(config bumpConfig, feeCapBufferBlocks uint16, lggr logger.SugaredLogger, currentTipCap, currentBaseFee *assets.Wei, originalFee DynamicFee, originalGasLimit uint64, maxGasPriceWei *assets.Wei) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) { +func BumpDynamicFeeOnly(config bumpConfig, feeCapBufferBlocks uint16, lggr logger.SugaredLogger, currentTipCap, currentBaseFee *assets.Wei, originalFee DynamicFee, maxGasPriceWei *assets.Wei) (bumped DynamicFee, err error) { bumped, err = bumpDynamicFee(config, feeCapBufferBlocks, lggr, currentTipCap, currentBaseFee, originalFee, maxGasPriceWei) if err != nil { - return bumped, 0, err + return bumped, err } - chainSpecificGasLimit, err = commonfee.ApplyMultiplier(originalGasLimit, config.LimitMultiplier()) return } diff --git a/core/chains/evm/gas/models_test.go b/core/chains/evm/gas/models_test.go index 76666143189..ec9542b4040 100644 --- a/core/chains/evm/gas/models_test.go +++ b/core/chains/evm/gas/models_test.go @@ -28,16 +28,20 @@ func TestWrappedEvmEstimator(t *testing.T) { FeeCap: assets.NewWeiI(20), TipCap: assets.NewWeiI(1), } + limitMultiplier := float32(1.5) + est := mocks.NewEvmEstimator(t) - est.On("GetDynamicFee", mock.Anything, mock.Anything, mock.Anything). - Return(dynamicFee, gasLimit, nil).Twice() + est.On("GetDynamicFee", mock.Anything, mock.Anything). + Return(dynamicFee, nil).Twice() est.On("GetLegacyGas", mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(legacyFee, gasLimit, nil).Twice() - est.On("BumpDynamicFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(dynamicFee, gasLimit, nil).Once() + est.On("BumpDynamicFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(dynamicFee, nil).Once() est.On("BumpLegacyGas", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(legacyFee, gasLimit, nil).Once() getRootEst := func(logger.Logger) gas.EvmEstimator { return est } + geCfg := gas.NewMockGasConfig() + geCfg.LimitMultiplierF = limitMultiplier mockEstimatorName := "WrappedEvmEstimator" mockEvmEstimatorName := "WrappedEvmEstimator.MockEstimator" @@ -46,13 +50,13 @@ func TestWrappedEvmEstimator(t *testing.T) { t.Run("L1Oracle", func(t *testing.T) { lggr := logger.Test(t) // expect nil - estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, false, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, false, nil, nil) l1Oracle := estimator.L1Oracle() assert.Nil(t, l1Oracle) // expect l1Oracle oracle := rollupMocks.NewL1Oracle(t) - estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, false, oracle) + estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, false, oracle, geCfg) l1Oracle = estimator.L1Oracle() assert.Equal(t, oracle, l1Oracle) }) @@ -62,20 +66,20 @@ func TestWrappedEvmEstimator(t *testing.T) { lggr := logger.Test(t) // expect legacy fee data dynamicFees := false - estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil, geCfg) fee, max, err := estimator.GetFee(ctx, nil, 0, nil) require.NoError(t, err) - assert.Equal(t, gasLimit, max) + assert.Equal(t, uint64(float32(gasLimit)*limitMultiplier), max) assert.True(t, legacyFee.Equal(fee.Legacy)) assert.Nil(t, fee.DynamicTipCap) assert.Nil(t, fee.DynamicFeeCap) // expect dynamic fee data dynamicFees = true - estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil) - fee, max, err = estimator.GetFee(ctx, nil, 0, nil) + estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil, geCfg) + fee, max, err = estimator.GetFee(ctx, nil, gasLimit, nil) require.NoError(t, err) - assert.Equal(t, gasLimit, max) + assert.Equal(t, uint64(float32(gasLimit)*limitMultiplier), max) assert.True(t, dynamicFee.FeeCap.Equal(fee.DynamicFeeCap)) assert.True(t, dynamicFee.TipCap.Equal(fee.DynamicTipCap)) assert.Nil(t, fee.Legacy) @@ -85,12 +89,12 @@ func TestWrappedEvmEstimator(t *testing.T) { t.Run("BumpFee", func(t *testing.T) { lggr := logger.Test(t) dynamicFees := false - estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil, geCfg) // expect legacy fee data fee, max, err := estimator.BumpFee(ctx, gas.EvmFee{Legacy: assets.NewWeiI(0)}, 0, nil, nil) require.NoError(t, err) - assert.Equal(t, gasLimit, max) + assert.Equal(t, uint64(float32(gasLimit)*limitMultiplier), max) assert.True(t, legacyFee.Equal(fee.Legacy)) assert.Nil(t, fee.DynamicTipCap) assert.Nil(t, fee.DynamicFeeCap) @@ -99,9 +103,9 @@ func TestWrappedEvmEstimator(t *testing.T) { fee, max, err = estimator.BumpFee(ctx, gas.EvmFee{ DynamicFeeCap: assets.NewWeiI(0), DynamicTipCap: assets.NewWeiI(0), - }, 0, nil, nil) + }, gasLimit, nil, nil) require.NoError(t, err) - assert.Equal(t, gasLimit, max) + assert.Equal(t, uint64(float32(gasLimit)*limitMultiplier), max) assert.True(t, dynamicFee.FeeCap.Equal(fee.DynamicFeeCap)) assert.True(t, dynamicFee.TipCap.Equal(fee.DynamicTipCap)) assert.Nil(t, fee.Legacy) @@ -123,18 +127,20 @@ func TestWrappedEvmEstimator(t *testing.T) { // expect legacy fee data dynamicFees := false - estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil, geCfg) total, err := estimator.GetMaxCost(ctx, val, nil, gasLimit, nil) require.NoError(t, err) fee := new(big.Int).Mul(legacyFee.ToInt(), big.NewInt(int64(gasLimit))) + fee, _ = new(big.Float).Mul(new(big.Float).SetInt(fee), big.NewFloat(float64(limitMultiplier))).Int(nil) assert.Equal(t, new(big.Int).Add(val.ToInt(), fee), total) // expect dynamic fee data dynamicFees = true - estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil) + estimator = gas.NewWrappedEvmEstimator(lggr, getRootEst, dynamicFees, nil, geCfg) total, err = estimator.GetMaxCost(ctx, val, nil, gasLimit, nil) require.NoError(t, err) fee = new(big.Int).Mul(dynamicFee.FeeCap.ToInt(), big.NewInt(int64(gasLimit))) + fee, _ = new(big.Float).Mul(new(big.Float).SetInt(fee), big.NewFloat(float64(limitMultiplier))).Int(nil) assert.Equal(t, new(big.Int).Add(val.ToInt(), fee), total) }) @@ -147,7 +153,7 @@ func TestWrappedEvmEstimator(t *testing.T) { estimator := gas.NewWrappedEvmEstimator(lggr, func(logger.Logger) gas.EvmEstimator { return evmEstimator - }, false, oracle) + }, false, oracle, geCfg) require.Equal(t, mockEstimatorName, estimator.Name()) require.Equal(t, mockEvmEstimatorName, evmEstimator.Name()) @@ -164,13 +170,13 @@ func TestWrappedEvmEstimator(t *testing.T) { oracle.On("Close").Return(nil).Once() getEst := func(logger.Logger) gas.EvmEstimator { return evmEstimator } - estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil, geCfg) err := estimator.Start(ctx) require.NoError(t, err) err = estimator.Close() require.NoError(t, err) - estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle) + estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle, geCfg) err = estimator.Start(ctx) require.NoError(t, err) err = estimator.Close() @@ -186,11 +192,11 @@ func TestWrappedEvmEstimator(t *testing.T) { oracle.On("Ready").Return(nil).Once() getEst := func(logger.Logger) gas.EvmEstimator { return evmEstimator } - estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil, geCfg) err := estimator.Ready() require.NoError(t, err) - estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle) + estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle, geCfg) err = estimator.Ready() require.NoError(t, err) }) @@ -209,13 +215,13 @@ func TestWrappedEvmEstimator(t *testing.T) { oracle.On("HealthReport").Return(map[string]error{oracleKey: oracleError}).Once() getEst := func(logger.Logger) gas.EvmEstimator { return evmEstimator } - estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil) + estimator := gas.NewWrappedEvmEstimator(lggr, getEst, false, nil, geCfg) report := estimator.HealthReport() require.True(t, pkgerrors.Is(report[evmEstimatorKey], evmEstimatorError)) require.Nil(t, report[oracleKey]) require.NotNil(t, report[mockEstimatorName]) - estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle) + estimator = gas.NewWrappedEvmEstimator(lggr, getEst, false, oracle, geCfg) report = estimator.HealthReport() require.True(t, pkgerrors.Is(report[evmEstimatorKey], evmEstimatorError)) require.True(t, pkgerrors.Is(report[oracleKey], oracleError)) diff --git a/core/chains/evm/gas/suggested_price_estimator.go b/core/chains/evm/gas/suggested_price_estimator.go index 89e497edbd3..edc1b0f92fa 100644 --- a/core/chains/evm/gas/suggested_price_estimator.go +++ b/core/chains/evm/gas/suggested_price_estimator.go @@ -154,12 +154,12 @@ func (o *SuggestedPriceEstimator) forceRefresh(ctx context.Context) (err error) func (o *SuggestedPriceEstimator) OnNewLongestChain(context.Context, *evmtypes.Head) {} -func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ uint64, _ *assets.Wei) (fee DynamicFee, chainSpecificGasLimit uint64, err error) { +func (*SuggestedPriceEstimator) GetDynamicFee(_ context.Context, _ *assets.Wei) (fee DynamicFee, err error) { err = pkgerrors.New("dynamic fees are not implemented for this estimator") return } -func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ uint64, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, chainSpecificGasLimit uint64, err error) { +func (*SuggestedPriceEstimator) BumpDynamicFee(_ context.Context, _ DynamicFee, _ *assets.Wei, _ []EvmPriorAttempt) (bumped DynamicFee, err error) { err = pkgerrors.New("dynamic fees are not implemented for this estimator") return } @@ -223,7 +223,6 @@ func (o *SuggestedPriceEstimator) BumpLegacyGas(ctx context.Context, originalFee // If the new suggested price is less than or equal to the max and the buffer puts the new price over the max, return the max price instead // The buffer is added on top of the suggested price during bumping as just a precaution. It is better to resubmit the transaction with the max gas price instead of erroring. newGasPrice = assets.NewWei(bigmath.Min(bufferedPrice, maxGasPriceWei.ToInt())) - // Return the original price if the refreshed price with the buffer is lower to ensure the bumped gas price is always equal or higher to the previous attempt if originalFee != nil && originalFee.Cmp(newGasPrice) > 0 { return originalFee, chainSpecificGasLimit, nil diff --git a/core/chains/evm/gas/suggested_price_estimator_test.go b/core/chains/evm/gas/suggested_price_estimator_test.go index ff5e004031b..0d52d6ab1b9 100644 --- a/core/chains/evm/gas/suggested_price_estimator_test.go +++ b/core/chains/evm/gas/suggested_price_estimator_test.go @@ -98,7 +98,7 @@ func TestSuggestedPriceEstimator(t *testing.T) { t.Run("calling GetDynamicFee always returns error", func(t *testing.T) { client := mocks.NewRPCClient(t) o := gas.NewSuggestedPriceEstimator(logger.Test(t), client, cfg) - _, _, 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") }) @@ -116,7 +116,7 @@ func TestSuggestedPriceEstimator(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") }) diff --git a/core/chains/evm/txmgr/broadcaster_test.go b/core/chains/evm/txmgr/broadcaster_test.go index 9547f7ee00e..d9e9364fdf0 100644 --- a/core/chains/evm/txmgr/broadcaster_test.go +++ b/core/chains/evm/txmgr/broadcaster_test.go @@ -63,9 +63,10 @@ func NewTestEthBroadcaster( lggr := logger.Test(t) ge := config.EVM().GasEstimator() + estimator := gas.NewWrappedEvmEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator { return gas.NewFixedPriceEstimator(config.EVM().GasEstimator(), ge.BlockHistory(), lggr) - }, ge.EIP1559DynamicFees(), nil) + }, ge.EIP1559DynamicFees(), nil, ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, keyStore, estimator) ethBroadcaster := txmgrcommon.NewBroadcaster(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(config.EVM().GasEstimator()), config.EVM().Transactions(), config.Database().Listener(), keyStore, txBuilder, nonceTracker, lggr, checkerFactory, nonceAutoSync) @@ -1152,7 +1153,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("callback set by ctor", func(t *testing.T) { estimator := gas.NewWrappedEvmEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator { return gas.NewFixedPriceEstimator(evmcfg.EVM().GasEstimator(), evmcfg.EVM().GasEstimator().BlockHistory(), lggr) - }, evmcfg.EVM().GasEstimator().EIP1559DynamicFees(), nil) + }, evmcfg.EVM().GasEstimator().EIP1559DynamicFees(), nil, evmcfg.EVM().GasEstimator()) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), evmcfg.EVM().GasEstimator(), ethKeyStore, estimator) localNextNonce = getLocalNextNonce(t, nonceTracker, fromAddress) eb2 := txmgr.NewEvmBroadcaster(txStore, txmClient, txmgr.NewEvmTxmConfig(evmcfg.EVM()), txmgr.NewEvmTxmFeeConfig(evmcfg.EVM().GasEstimator()), evmcfg.EVM().Transactions(), evmcfg.Database().Listener(), ethKeyStore, txBuilder, lggr, &testCheckerFactory{}, false) @@ -1738,7 +1739,7 @@ func TestEthBroadcaster_SyncNonce(t *testing.T) { estimator := gas.NewWrappedEvmEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator { return gas.NewFixedPriceEstimator(evmcfg.EVM().GasEstimator(), evmcfg.EVM().GasEstimator().BlockHistory(), lggr) - }, evmcfg.EVM().GasEstimator().EIP1559DynamicFees(), nil) + }, evmcfg.EVM().GasEstimator().EIP1559DynamicFees(), nil, evmcfg.EVM().GasEstimator()) checkerFactory := &testCheckerFactory{} ge := evmcfg.EVM().GasEstimator() diff --git a/core/chains/evm/txmgr/confirmer_test.go b/core/chains/evm/txmgr/confirmer_test.go index d00b2d9ae3d..3e200d66818 100644 --- a/core/chains/evm/txmgr/confirmer_test.go +++ b/core/chains/evm/txmgr/confirmer_test.go @@ -125,7 +125,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { newEst := func(logger.Logger) gas.EvmEstimator { return estimator } lggr := logger.Test(t) ge := config.EVM().GasEstimator() - feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil) + feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil, ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ethKeyStore, feeEstimator) ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ethKeyStore, txBuilder, lggr) ctx := testutils.Context(t) @@ -1645,7 +1645,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing newEst := func(logger.Logger) gas.EvmEstimator { return estimator } estimator.On("BumpLegacyGas", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, uint64(0), pkgerrors.Wrapf(commonfee.ErrConnectivity, "transaction...")) ge := ccfg.EVM().GasEstimator() - feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil) + feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil, ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, kst, feeEstimator) addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Maybe() @@ -1689,11 +1689,11 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing kst := ksmocks.NewEth(t) estimator := gasmocks.NewEvmEstimator(t) - estimator.On("BumpDynamicFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(gas.DynamicFee{}, uint64(0), pkgerrors.Wrapf(commonfee.ErrConnectivity, "transaction...")) + estimator.On("BumpDynamicFee", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(gas.DynamicFee{}, pkgerrors.Wrapf(commonfee.ErrConnectivity, "transaction...")) newEst := func(logger.Logger) gas.EvmEstimator { return estimator } // Create confirmer with necessary state ge := ccfg.EVM().GasEstimator() - feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil) + feeEstimator := gas.NewWrappedEvmEstimator(lggr, newEst, ge.EIP1559DynamicFees(), nil, ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, kst, feeEstimator) addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", mock.Anything, &cltest.FixtureChainID).Return(addresses, nil).Maybe() @@ -3132,7 +3132,7 @@ func newEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient client.Cl ge := config.EVM().GasEstimator() estimator := gas.NewWrappedEvmEstimator(lggr, func(lggr logger.Logger) gas.EvmEstimator { return gas.NewFixedPriceEstimator(ge, ge.BlockHistory(), lggr) - }, ge.EIP1559DynamicFees(), nil) + }, ge.EIP1559DynamicFees(), nil, ge) txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ks, estimator) ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ks, txBuilder, lggr) ec.SetResumeCallback(fn)