Skip to content

Commit

Permalink
Update config names
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Jul 17, 2024
1 parent 7e447fd commit caaaf2d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
19 changes: 9 additions & 10 deletions core/chains/evm/gas/universal_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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))

Expand Down
26 changes: 13 additions & 13 deletions core/chains/evm/gas/universal_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit caaaf2d

Please sign in to comment.