Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use partial gas price percentiles #1506

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion seth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ func (m *Client) CalculateGasEstimations(request GasEstimationRequest) GasEstima
defer cancel()

var disableEstimationsIfNeeded = func(err error) {
if strings.Contains(err.Error(), ZeroGasSuggestedErr) {
if strings.Contains(err.Error(), ZeroGasSuggestedErr) || strings.Contains(err.Error(), "Partial data received") {
L.Warn().Msg("Received incorrect gas estimations. Disabling them and reverting to hardcoded values. Remember to update your config!")
m.Cfg.Network.GasPriceEstimationEnabled = false
}
Expand Down
21 changes: 14 additions & 7 deletions seth/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (m *GasEstimator) Stats(fromNumber uint64, priorityPerc float64) (GasSugges
}
gasPercs, err := quantilesFromFloatArray(baseFees)
if err != nil {
return GasSuggestions{}, err
L.Debug().Err(err).Msg("Error calculating gas percentiles. Will use partial data.")
// return GasSuggestions{}, err
}
tips := make([]float64, 0)
for _, bf := range hist.Reward {
Expand All @@ -64,7 +65,8 @@ func (m *GasEstimator) Stats(fromNumber uint64, priorityPerc float64) (GasSugges
}
tipPercs, err := quantilesFromFloatArray(tips)
if err != nil {
return GasSuggestions{}, err
// return GasSuggestions{}, err
L.Debug().Err(err).Msg("Error calculating tip percentiles. Will use partial data.")
}
suggestedGasPrice, err := m.Client.Client.SuggestGasPrice(context.Background())
if err != nil {
Expand Down Expand Up @@ -105,23 +107,28 @@ type GasSuggestions struct {
func quantilesFromFloatArray(fa []float64) (*GasPercentiles, error) {
perMax, err := stats.Max(fa)
if err != nil {
return nil, err
L.Debug().Err(err).Msg("Error calculating max gas price. Continuing")
// return nil, err
}
perc99, err := stats.Percentile(fa, 99)
if err != nil {
return nil, err
L.Debug().Err(err).Msg("Error calculating p99 gas price. Continuing")
// return nil, err
}
perc75, err := stats.Percentile(fa, 75)
if err != nil {
return nil, err
L.Debug().Err(err).Msg("Error calculating p75 gas price. Continuing")
// return nil, err
}
perc50, err := stats.Percentile(fa, 50)
if err != nil {
return nil, err
L.Debug().Err(err).Msg("Error calculating p50 gas price. Continuing")
// return nil, err
}
perc25, err := stats.Percentile(fa, 25)
if err != nil {
return nil, err
L.Debug().Err(err).Msg("Error calculating p25 gas price. Continuing")
// return nil, err
}
return &GasPercentiles{
Max: perMax,
Expand Down
35 changes: 34 additions & 1 deletion seth/gas_adjuster.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,22 +467,55 @@ func (m *Client) HistoricalFeeData(priority string) (baseFee float64, historical
stats, err := estimator.Stats(m.Cfg.Network.GasPriceEstimationBlocks, 99)
if err != nil {
L.Debug().
Msgf("Failed to get fee history due to: %s. Skipping automation gas estimation", err.Error())
Err(err).
Msgf("Failed to get fee history.. Skipping automation gas estimation")

return
}

switch priority {
case Priority_Degen:
if stats.GasPrice.Max == math.NaN() || stats.TipCap.Max == math.NaN() {
err = fmt.Errorf("Partial data received. Either base fee or suggested tip is 0 for Max values")
L.Debug().
Err(err).
Msgf("Failed to get fee history.. Skipping automation gas estimation")

return
}
baseFee = stats.GasPrice.Max
historicalGasTipCap = stats.TipCap.Max
case Priority_Fast:
if stats.GasPrice.Perc99 == math.NaN() || stats.TipCap.Perc99 == math.NaN() {
err = fmt.Errorf("Partial data received. Either base fee or suggested tip is 0 for Perc99 values")
L.Debug().
Err(err).
Msgf("Failed to get fee history.. Skipping automation gas estimation")

return
}
baseFee = stats.GasPrice.Perc99
historicalGasTipCap = stats.TipCap.Perc99
case Priority_Standard:
if stats.GasPrice.Perc50 == math.NaN() || stats.TipCap.Perc50 == math.NaN() {
err = fmt.Errorf("Partial data received. Either base fee or suggested tip is 0 for Perc50 values")
L.Debug().
Err(err).
Msgf("Failed to get fee history.. Skipping automation gas estimation")

return
}
baseFee = stats.GasPrice.Perc50
historicalGasTipCap = stats.TipCap.Perc50
case Priority_Slow:
if math.IsNaN(stats.GasPrice.Perc25) || math.IsNaN(stats.TipCap.Perc25) {
err = fmt.Errorf("Partial data received. Either base fee or suggested tip is 0 for Perc25 values")
L.Debug().
Err(err).
Msgf("Failed to get fee history.. Skipping automation gas estimation")

return
}
baseFee = stats.GasPrice.Perc25
historicalGasTipCap = stats.TipCap.Perc25
default:
Expand Down
Loading