Skip to content

Commit 328901c

Browse files
authored
cmd, eth: offer maxprice flag for overwritting price cap (#21531)
* cmd, eth: offer maxprice flag for overwritting price cap * eth: rename default price cap
1 parent 3a98c6f commit 328901c

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ var (
154154
utils.LegacyGpoBlocksFlag,
155155
utils.GpoPercentileFlag,
156156
utils.LegacyGpoPercentileFlag,
157+
utils.GpoMaxGasPriceFlag,
157158
utils.EWASMInterpreterFlag,
158159
utils.EVMInterpreterFlag,
159160
configFileFlag,

‎cmd/geth/usage.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
189189
Flags: []cli.Flag{
190190
utils.GpoBlocksFlag,
191191
utils.GpoPercentileFlag,
192+
utils.GpoMaxGasPriceFlag,
192193
},
193194
},
194195
{

‎cmd/utils/flags.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,11 @@ var (
631631
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
632632
Value: eth.DefaultConfig.GPO.Percentile,
633633
}
634+
GpoMaxGasPriceFlag = cli.Int64Flag{
635+
Name: "gpo.maxprice",
636+
Usage: "Maximum gas price will be recommended by gpo",
637+
Value: eth.DefaultConfig.GPO.MaxPrice.Int64(),
638+
}
634639
WhisperEnabledFlag = cli.BoolFlag{
635640
Name: "shh",
636641
Usage: "Enable Whisper",
@@ -1291,6 +1296,9 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
12911296
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
12921297
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
12931298
}
1299+
if ctx.GlobalIsSet(GpoMaxGasPriceFlag.Name) {
1300+
cfg.MaxPrice = big.NewInt(ctx.GlobalInt64(GpoMaxGasPriceFlag.Name))
1301+
}
12941302
}
12951303

12961304
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {

‎eth/config.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ import (
3737
var DefaultFullGPOConfig = gasprice.Config{
3838
Blocks: 20,
3939
Percentile: 60,
40+
MaxPrice: gasprice.DefaultMaxPrice,
4041
}
4142

4243
// DefaultLightGPOConfig contains default gasprice oracle settings for light client.
4344
var DefaultLightGPOConfig = gasprice.Config{
4445
Blocks: 2,
4546
Percentile: 60,
47+
MaxPrice: gasprice.DefaultMaxPrice,
4648
}
4749

4850
// DefaultConfig contains default settings for use on the Ethereum main net.

‎eth/gasprice/gasprice.go‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ import (
2424

2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/core/types"
27+
"github.com/ethereum/go-ethereum/log"
2728
"github.com/ethereum/go-ethereum/params"
2829
"github.com/ethereum/go-ethereum/rpc"
2930
)
3031

3132
const sampleNumber = 3 // Number of transactions sampled in a block
3233

33-
var maxPrice = big.NewInt(500 * params.GWei)
34+
var DefaultMaxPrice = big.NewInt(500 * params.GWei)
3435

3536
type Config struct {
3637
Blocks int
3738
Percentile int
3839
Default *big.Int `toml:",omitempty"`
40+
MaxPrice *big.Int `toml:",omitempty"`
3941
}
4042

4143
// OracleBackend includes all necessary background APIs for oracle.
@@ -51,6 +53,7 @@ type Oracle struct {
5153
backend OracleBackend
5254
lastHead common.Hash
5355
lastPrice *big.Int
56+
maxPrice *big.Int
5457
cacheLock sync.RWMutex
5558
fetchLock sync.Mutex
5659

@@ -64,17 +67,26 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
6467
blocks := params.Blocks
6568
if blocks < 1 {
6669
blocks = 1
70+
log.Warn("Sanitizing invalid gasprice oracle sample blocks", "provided", params.Blocks, "updated", blocks)
6771
}
6872
percent := params.Percentile
6973
if percent < 0 {
7074
percent = 0
75+
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
7176
}
7277
if percent > 100 {
7378
percent = 100
79+
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
80+
}
81+
maxPrice := params.MaxPrice
82+
if maxPrice == nil || maxPrice.Int64() <= 0 {
83+
maxPrice = DefaultMaxPrice
84+
log.Warn("Sanitizing invalid gasprice oracle price cap", "provided", params.MaxPrice, "updated", maxPrice)
7485
}
7586
return &Oracle{
7687
backend: backend,
7788
lastPrice: params.Default,
89+
maxPrice: maxPrice,
7890
checkBlocks: blocks,
7991
percentile: percent,
8092
}
@@ -146,8 +158,8 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
146158
sort.Sort(bigIntArray(txPrices))
147159
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
148160
}
149-
if price.Cmp(maxPrice) > 0 {
150-
price = new(big.Int).Set(maxPrice)
161+
if price.Cmp(gpo.maxPrice) > 0 {
162+
price = new(big.Int).Set(gpo.maxPrice)
151163
}
152164
gpo.cacheLock.Lock()
153165
gpo.lastHead = headHash

0 commit comments

Comments
 (0)