Skip to content

Commit 86469a2

Browse files
committed
use more conservative tip, when estimating gas costs
1 parent 19e49f6 commit 86469a2

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

seth/gas_adjuster.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,38 +504,66 @@ 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 tip percentile to use, 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+
528+
// TODO remove me
529+
// percentileTip = 99
530+
507531
estimator := NewGasEstimator(m)
508-
stats, err := estimator.Stats(m.Cfg.Network.GasPriceEstimationBlocks, 99)
532+
stats, err := estimator.Stats(m.Cfg.Network.GasPriceEstimationBlocks, percentileTip)
509533
if err != nil {
510534
L.Debug().
511535
Msgf("Failed to get fee history due to: %s", err.Error())
512536

513537
return
514538
}
515539

540+
// base fee should still be based on priority, because FeeHistory returns whole history, not just the requested percentile
541+
// for the base fee (as opposed to tip cap)
516542
switch priority {
517543
case Priority_Degen:
518544
baseFee = stats.GasPrice.Max
519-
historicalGasTipCap = stats.TipCap.Max
545+
// historicalGasTipCap = stats.TipCap.Max
520546
case Priority_Fast:
521547
baseFee = stats.GasPrice.Perc99
522-
historicalGasTipCap = stats.TipCap.Perc99
548+
// historicalGasTipCap = stats.TipCap.Perc99
523549
case Priority_Standard:
524550
baseFee = stats.GasPrice.Perc50
525-
historicalGasTipCap = stats.TipCap.Perc50
551+
// historicalGasTipCap = stats.TipCap.Perc50
526552
case Priority_Slow:
527553
baseFee = stats.GasPrice.Perc25
528-
historicalGasTipCap = stats.TipCap.Perc25
554+
// historicalGasTipCap = stats.TipCap.Perc25
529555
default:
530556
err = fmt.Errorf("unknown priority: %s", priority)
531557
L.Debug().
532558
Str("Priority", priority).
533559
Msgf("Unknown priority: %s", err.Error())
534560

535561
return
536-
537562
}
538563

564+
// since we have already requested reward percentiles based on priority, let's now use the median, i.e. most common tip
565+
historicalGasTipCap = stats.TipCap.Perc50
566+
539567
return
540568
}
541569

seth/gas_test.go

Lines changed: 7 additions & 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
}
@@ -36,3 +36,9 @@ func TestGasEstimator(t *testing.T) {
3636
require.GreaterOrEqual(t, suggestions.TipCap.Perc99, suggestions.TipCap.Perc75, "Suggested 99th percentile tip cap should be greater than or equal to 75th percentile")
3737
require.GreaterOrEqual(t, suggestions.TipCap.Max, suggestions.TipCap.Perc99, "Suggested max tip cap should be greater than or equal to 99th percentile")
3838
}
39+
40+
func TestGasEstimations(t *testing.T) {
41+
c := newClient(t)
42+
txOpts := c.NewTXOpts()
43+
_ = txOpts
44+
}

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)