Skip to content

Commit

Permalink
testing suggested gas with buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
simsonraj committed Jul 2, 2024
1 parent 3462b53 commit a8c23c4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/chains/evm/gas/suggested_price_estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,27 @@ func (o *SuggestedPriceEstimator) GetLegacyGas(ctx context.Context, _ []byte, Ga
} else if err != nil {
return
}

gasPrice = o.gasPriceWithBuffer(gasPrice, maxGasPriceWei)

// For L2 chains, submitting a transaction that is not priced high enough will cause the call to fail, so if the cap is lower than the RPC suggested gas price, this transaction cannot succeed
if gasPrice != nil && gasPrice.Cmp(maxGasPriceWei) > 0 {
return nil, 0, pkgerrors.Errorf("estimated gas price: %s is greater than the maximum gas price configured: %s", gasPrice.String(), maxGasPriceWei.String())
}
return
}

func (o *SuggestedPriceEstimator) gasPriceWithBuffer(gasPrice *assets.Wei, maxGasPriceWei *assets.Wei) *assets.Wei {
const BufferPercent = 20
gasPrice = gasPrice.AddPercentage(BufferPercent)
if gasPrice.Cmp(maxGasPriceWei) > 0 {
o.logger.Warnw("Updated gasPrice with buffer is higher than the max gas price limit. Falling back to max gas price", "gasPriceWithBuffer", gasPrice, "maxGasPriceWei", maxGasPriceWei)
gasPrice = maxGasPriceWei
}
o.logger.Debugw("gasPriceWithBuffer", "updatedGasPrice", gasPrice)
return gasPrice
}

// Refreshes the gas price by making a call to the RPC in case the current one has gone stale.
// Adds the larger of BumpPercent and BumpMin configs as a buffer on top of the price returned from the RPC.
// The only reason bumping logic would be called on the SuggestedPriceEstimator is if there was a significant price spike
Expand Down

0 comments on commit a8c23c4

Please sign in to comment.