diff --git a/core/chains/evm/gas/universal_estimator.go b/core/chains/evm/gas/universal_estimator.go index 645d94fb362..c8f7a6e25a4 100644 --- a/core/chains/evm/gas/universal_estimator.go +++ b/core/chains/evm/gas/universal_estimator.go @@ -64,9 +64,9 @@ type UniversalEstimatorConfig struct { BumpPercent uint16 CacheTimeout time.Duration - BlockHistoryRange uint64 // inclusive range - RewardPercentile float64 - HasMempool bool + BlockHistorySize uint64 + RewardPercentile float64 + HasMempool bool } //go:generate mockery --quiet --name universalEstimatorClient --output ./mocks/ --case=underscore --structname UniversalEstimatorClient @@ -108,7 +108,6 @@ func NewUniversalEstimator(lggr logger.Logger, client universalEstimatorClient, } func (u *UniversalEstimator) Start(context.Context) error { - // This is not an actual start since it's not a service, just a sanity check for configs if u.config.BumpPercent < MinimumBumpPercentage { u.logger.Warnf("BumpPercent: %s is less than minimum allowed percentage: %s. Bumping attempts might result in rejections due to replacement transaction underpriced error!", strconv.FormatUint(uint64(u.config.BumpPercent), 10), strconv.Itoa(MinimumBumpPercentage)) @@ -117,8 +116,8 @@ func (u *UniversalEstimator) Start(context.Context) error { u.logger.Warnf("RewardPercentile: %s is greater than maximum allowed connectivity percentage: %s. Lower reward percentile percentage otherwise connectivity checks will fail!", strconv.FormatUint(uint64(u.config.RewardPercentile), 10), strconv.Itoa(ConnectivityPercentile)) } - if u.config.BlockHistoryRange == 0 { - u.logger.Warn("BlockHistoryRange is set to 0. Using dynamic transactions will result in an error!", + if u.config.BlockHistorySize == 0 { + u.logger.Warn("BlockHistorySize is set to 0. Using dynamic transactions will result in an error!", strconv.FormatUint(uint64(u.config.RewardPercentile), 10), strconv.Itoa(ConnectivityPercentile)) } return nil @@ -217,11 +216,11 @@ func (u *UniversalEstimator) fetchDynamicPrice(parentCtx context.Context, forceR ctx, cancel := context.WithTimeout(parentCtx, queryTimeout) defer cancel() - if u.config.BlockHistoryRange == 0 { - return fee, fmt.Errorf("BlockHistoryRange cannot be 0") + if u.config.BlockHistorySize == 0 { + return fee, fmt.Errorf("BlockHistorySize cannot be 0") } // RewardPercentile will be used for maxPriorityFeePerGas estimations and connectivityPercentile to set the highest threshold for bumping. - feeHistory, err := u.client.FeeHistory(ctx, u.config.BlockHistoryRange, []float64{u.config.RewardPercentile, ConnectivityPercentile}) + feeHistory, err := u.client.FeeHistory(ctx, u.config.BlockHistorySize, []float64{u.config.RewardPercentile, ConnectivityPercentile}) if err != nil { return fee, fmt.Errorf("failed to fetch dynamic prices: %s", err) } @@ -240,7 +239,7 @@ func (u *UniversalEstimator) fetchDynamicPrice(parentCtx context.Context, forceR u.priorityFeeThreshold = (*assets.Wei)(priorityFeeThreshold) u.priorityFeeThresholdMu.Unlock() - maxPriorityFeePerGas := (*assets.Wei)(priorityFee.Div(priorityFee, big.NewInt(int64(u.config.BlockHistoryRange)))) + maxPriorityFeePerGas := (*assets.Wei)(priorityFee.Div(priorityFee, big.NewInt(int64(u.config.BlockHistorySize)))) // baseFeeBufferPercentage is used as a safety to catch fluctuations in the next block. maxFeePerGas := baseFee.AddPercentage(BaseFeeBufferPercentage).Add((maxPriorityFeePerGas)) diff --git a/core/chains/evm/gas/universal_estimator_test.go b/core/chains/evm/gas/universal_estimator_test.go index b61e7cbd711..f68a4d8da0a 100644 --- a/core/chains/evm/gas/universal_estimator_test.go +++ b/core/chains/evm/gas/universal_estimator_test.go @@ -213,7 +213,7 @@ func TestUniversalEstimatorGetDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() blockHistoryLength := 2 - cfg := gas.UniversalEstimatorConfig{BlockHistoryRange: uint64(blockHistoryLength)} + cfg := gas.UniversalEstimatorConfig{BlockHistorySize: uint64(blockHistoryLength)} avrgPriorityFee := big.NewInt(0) avrgPriorityFee.Add(maxPriorityFeePerGas1, maxPriorityFeePerGas2).Div(avrgPriorityFee, big.NewInt(int64(blockHistoryLength))) maxFee := (*assets.Wei)(baseFee).AddPercentage(gas.BaseFeeBufferPercentage).Add((*assets.Wei)(avrgPriorityFee)) @@ -225,10 +225,10 @@ func TestUniversalEstimatorGetDynamicFee(t *testing.T) { assert.Equal(t, (*assets.Wei)(avrgPriorityFee), dynamicFee.TipCap) }) - t.Run("fails if BlockHistoryRange is zero and tries to fetch new prices", func(t *testing.T) { + t.Run("fails if BlockHistorySize is zero and tries to fetch new prices", func(t *testing.T) { client := mocks.NewUniversalEstimatorClient(t) - cfg := gas.UniversalEstimatorConfig{BlockHistoryRange: 0} + cfg := gas.UniversalEstimatorConfig{BlockHistorySize: 0} u := gas.NewUniversalEstimator(logger.Test(t), client, cfg, chainID, nil) _, err := u.GetDynamicFee(tests.Context(t), maxPrice) @@ -250,7 +250,7 @@ func TestUniversalEstimatorGetDynamicFee(t *testing.T) { cfg := gas.UniversalEstimatorConfig{ CacheTimeout: 4 * time.Hour, - BlockHistoryRange: 1, + BlockHistorySize: 1, } maxFee := (*assets.Wei)(baseFee).AddPercentage(gas.BaseFeeBufferPercentage).Add((*assets.Wei)(maxPriorityFeePerGas)) @@ -279,7 +279,7 @@ func TestUniversalEstimatorGetDynamicFee(t *testing.T) { } client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() - cfg := gas.UniversalEstimatorConfig{BlockHistoryRange: 1} + cfg := gas.UniversalEstimatorConfig{BlockHistorySize: 1} maxFee := (*assets.Wei)(baseFee).AddPercentage(gas.BaseFeeBufferPercentage).Add((*assets.Wei)(maxPriorityFeePerGas)) u := gas.NewUniversalEstimator(logger.Test(t), client, cfg, chainID, nil) @@ -303,7 +303,7 @@ func TestUniversalEstimatorGetDynamicFee(t *testing.T) { } client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() - cfg := gas.UniversalEstimatorConfig{BlockHistoryRange: 1} + cfg := gas.UniversalEstimatorConfig{BlockHistorySize: 1} u := gas.NewUniversalEstimator(logger.Test(t), client, cfg, chainID, nil) dynamicFee, err := u.GetDynamicFee(tests.Context(t), maxPrice) @@ -336,7 +336,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 2, + BlockHistorySize: 2, BumpPercent: 50, HasMempool: true, } @@ -354,7 +354,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { t.Run("fails if the original attempt is invalid", func(t *testing.T) { client := mocks.NewUniversalEstimatorClient(t) maxPrice := assets.NewWeiI(20) - cfg := gas.UniversalEstimatorConfig{BlockHistoryRange: 1} + cfg := gas.UniversalEstimatorConfig{BlockHistorySize: 1} u := gas.NewUniversalEstimator(logger.Test(t), client, cfg, chainID, nil) // nil original fee @@ -400,7 +400,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { maxFee := (*assets.Wei)(baseFee).AddPercentage(gas.BaseFeeBufferPercentage).Add((*assets.Wei)(maxPriorityFeePerGas)) cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 1, + BlockHistorySize: 1, BumpPercent: 50, HasMempool: true, } @@ -431,7 +431,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 1, + BlockHistorySize: 1, BumpPercent: 50, HasMempool: true, } @@ -461,7 +461,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 1, + BlockHistorySize: 1, BumpPercent: 50, HasMempool: true, } @@ -493,7 +493,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 1, + BlockHistorySize: 1, BumpPercent: 50, } @@ -521,7 +521,7 @@ func TestUniversalEstimatorBumpDynamicFee(t *testing.T) { client.On("FeeHistory", mock.Anything, mock.Anything, mock.Anything).Return(feeHistoryResult, nil).Once() cfg := gas.UniversalEstimatorConfig{ - BlockHistoryRange: 1, + BlockHistorySize: 1, BumpPercent: 20, HasMempool: false, }