Skip to content

Commit 74b656e

Browse files
authored
Seth more gas conservative tip (#1668)
1 parent 19e49f6 commit 74b656e

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

seth/.changeset/v1.51.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Use more conservative gas tip estimation, i.e. call `FeeHistory` endpoint with tip percentile corresponding to given priory and then select median value

seth/gas_adjuster.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,38 +504,58 @@ func classifyCongestion(congestionMetric float64) string {
504504
}
505505

506506
func (m *Client) HistoricalFeeData(priority string) (baseFee float64, historicalGasTipCap float64, err error) {
507+
var percentileTip float64
508+
509+
// based on priority decide, which percentile to use to get historical tip values, when calling FeeHistory
510+
switch priority {
511+
case Priority_Degen:
512+
percentileTip = 100
513+
case Priority_Fast:
514+
percentileTip = 99
515+
case Priority_Standard:
516+
percentileTip = 50
517+
case Priority_Slow:
518+
percentileTip = 25
519+
default:
520+
err = fmt.Errorf("unknown priority: %s", priority)
521+
L.Debug().
522+
Str("Priority", priority).
523+
Msgf("Unknown priority: %s", err.Error())
524+
525+
return
526+
}
527+
507528
estimator := NewGasEstimator(m)
508-
stats, err := estimator.Stats(m.Cfg.Network.GasPriceEstimationBlocks, 99)
529+
stats, err := estimator.Stats(m.Cfg.Network.GasPriceEstimationBlocks, percentileTip)
509530
if err != nil {
510531
L.Debug().
511532
Msgf("Failed to get fee history due to: %s", err.Error())
512533

513534
return
514535
}
515536

537+
// base fee should still be based on priority, because FeeHistory returns whole base fee history, not just the requested percentile
516538
switch priority {
517539
case Priority_Degen:
518540
baseFee = stats.GasPrice.Max
519-
historicalGasTipCap = stats.TipCap.Max
520541
case Priority_Fast:
521542
baseFee = stats.GasPrice.Perc99
522-
historicalGasTipCap = stats.TipCap.Perc99
523543
case Priority_Standard:
524544
baseFee = stats.GasPrice.Perc50
525-
historicalGasTipCap = stats.TipCap.Perc50
526545
case Priority_Slow:
527546
baseFee = stats.GasPrice.Perc25
528-
historicalGasTipCap = stats.TipCap.Perc25
529547
default:
530548
err = fmt.Errorf("unknown priority: %s", priority)
531549
L.Debug().
532550
Str("Priority", priority).
533551
Msgf("Unknown priority: %s", err.Error())
534552

535553
return
536-
537554
}
538555

556+
// since we have already requested reward percentiles based on priority, let's now use the median, i.e. most common tip
557+
historicalGasTipCap = stats.TipCap.Perc50
558+
539559
return
540560
}
541561

seth/gas_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestGasEstimator(t *testing.T) {
1313
c := newClient(t)
1414
bn, err := c.Client.BlockNumber(context.Background())
1515
require.NoError(t, err, "BlockNumber should not error")
16-
for i := 0; i < 10; i++ {
16+
for range 10 {
1717
_, err := c.DeployContractFromContractStore(c.NewTXOpts(), "NetworkDebugSubContract")
1818
require.NoError(t, err, "Deploying contract should not error")
1919
}

seth/seth.toml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ root_key_funds_buffer = 10 # 10 ether
4949

5050
# feature-flagged expriments; first one sets funds return priority to 'slow' (core only!), second one
5151
# sets the tip/base fee to the higher value in case there's 3+ orders of magnitude difference between them
52-
experiments_enabled = ["slow_funds_return", "eip_1559_fee_equalizer"]
52+
# experiments_enabled = ["slow_funds_return", "eip_1559_fee_equalizer"]
5353

5454
# when enabled when creating a new Seth client we will send 10k wei from root address to root address
5555
# to make sure transaction can be submitted and mined
@@ -81,6 +81,32 @@ key_sync_retries = 10
8181
[block_stats]
8282
rpc_requests_per_second_limit = 15
8383

84+
[[networks]]
85+
name = "Ethereum_Mainnet"
86+
dial_timeout = "1m"
87+
transaction_timeout = "30s"
88+
eip_1559_dynamic_fees = true
89+
90+
# automated gas estimation
91+
gas_price_estimation_enabled = true
92+
gas_price_estimation_blocks = 20
93+
gas_price_estimation_tx_priority = "standard"
94+
# how many times to try fetching & calculating gas price data in case of errors, defaults to 1 if empty
95+
gas_price_estimation_attempt_count = 2
96+
# urls_secret = ["xxx"]
97+
98+
# gas limits
99+
transfer_gas_fee = 21_000
100+
# gas limit should be explicitly set only if you are connecting to a node that's incapable of estimating gas limit itself (should only happen for very old versions)
101+
# gas_limit = 14_000_000
102+
103+
# manual settings, used when gas_price_estimation_enabled is false or when it fails
104+
# legacy transactions
105+
gas_price = 1_000_000_000
106+
# EIP-1559 transactions
107+
gas_fee_cap = 25_000_000_000
108+
gas_tip_cap = 5_000_000_000
109+
84110
[[networks]]
85111
name = "Anvil"
86112
dial_timeout = "1m"

0 commit comments

Comments
 (0)