Skip to content

Commit 9aca9e6

Browse files
zsfelfoldikaralabe
authored andcommitted
cmd, les, eth, eth/gasprice: using new gas price oracle (#13853)
* cmd, les, eth, eth/gasprice: using new gas price oracle * eth/gasprice: renamed source file * eth/gasprice: added security checks for gpo params * eth/gasprice: fixed naming issues * eth/gasprice: max limit, maxEmpty
1 parent 0ec1104 commit 9aca9e6

10 files changed

Lines changed: 167 additions & 419 deletions

File tree

‎cmd/geth/main.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,8 @@ func init() {
147147
utils.FakePoWFlag,
148148
utils.NoCompactionFlag,
149149
utils.SolcPathFlag,
150-
utils.GpoMinGasPriceFlag,
151-
utils.GpoMaxGasPriceFlag,
152-
utils.GpoFullBlockRatioFlag,
153-
utils.GpobaseStepDownFlag,
154-
utils.GpobaseStepUpFlag,
155-
utils.GpobaseCorrectionFactorFlag,
150+
utils.GpoBlocksFlag,
151+
utils.GpoPercentileFlag,
156152
utils.ExtraDataFlag,
157153
}
158154
app.Flags = append(app.Flags, debug.Flags...)

‎cmd/geth/usage.go‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,8 @@ var AppHelpFlagGroups = []flagGroup{
151151
{
152152
Name: "GAS PRICE ORACLE",
153153
Flags: []cli.Flag{
154-
utils.GpoMinGasPriceFlag,
155-
utils.GpoMaxGasPriceFlag,
156-
utils.GpoFullBlockRatioFlag,
157-
utils.GpobaseStepDownFlag,
158-
utils.GpobaseStepUpFlag,
159-
utils.GpobaseCorrectionFactorFlag,
154+
utils.GpoBlocksFlag,
155+
utils.GpoPercentileFlag,
160156
},
161157
},
162158
{

‎cmd/utils/flags.go‎

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -409,35 +409,15 @@ var (
409409
}
410410

411411
// Gas price oracle settings
412-
GpoMinGasPriceFlag = BigFlag{
413-
Name: "gpomin",
414-
Usage: "Minimum suggested gas price",
415-
Value: big.NewInt(20 * params.Shannon),
416-
}
417-
GpoMaxGasPriceFlag = BigFlag{
418-
Name: "gpomax",
419-
Usage: "Maximum suggested gas price",
420-
Value: big.NewInt(500 * params.Shannon),
421-
}
422-
GpoFullBlockRatioFlag = cli.IntFlag{
423-
Name: "gpofull",
424-
Usage: "Full block threshold for gas price calculation (%)",
425-
Value: 80,
426-
}
427-
GpobaseStepDownFlag = cli.IntFlag{
428-
Name: "gpobasedown",
429-
Usage: "Suggested gas price base step down ratio (1/1000)",
412+
GpoBlocksFlag = cli.IntFlag{
413+
Name: "gpoblocks",
414+
Usage: "Number of recent blocks to check for gas prices",
430415
Value: 10,
431416
}
432-
GpobaseStepUpFlag = cli.IntFlag{
433-
Name: "gpobaseup",
434-
Usage: "Suggested gas price base step up ratio (1/1000)",
435-
Value: 100,
436-
}
437-
GpobaseCorrectionFactorFlag = cli.IntFlag{
438-
Name: "gpobasecf",
439-
Usage: "Suggested gas price base correction factor (%)",
440-
Value: 110,
417+
GpoPercentileFlag = cli.IntFlag{
418+
Name: "gpopercentile",
419+
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
420+
Value: 50,
441421
}
442422
)
443423

@@ -798,12 +778,8 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
798778
ExtraData: MakeMinerExtra(extra, ctx),
799779
DocRoot: ctx.GlobalString(DocRootFlag.Name),
800780
GasPrice: GlobalBig(ctx, GasPriceFlag.Name),
801-
GpoMinGasPrice: GlobalBig(ctx, GpoMinGasPriceFlag.Name),
802-
GpoMaxGasPrice: GlobalBig(ctx, GpoMaxGasPriceFlag.Name),
803-
GpoFullBlockRatio: ctx.GlobalInt(GpoFullBlockRatioFlag.Name),
804-
GpobaseStepDown: ctx.GlobalInt(GpobaseStepDownFlag.Name),
805-
GpobaseStepUp: ctx.GlobalInt(GpobaseStepUpFlag.Name),
806-
GpobaseCorrectionFactor: ctx.GlobalInt(GpobaseCorrectionFactorFlag.Name),
781+
GpoBlocks: ctx.GlobalInt(GpoBlocksFlag.Name),
782+
GpoPercentile: ctx.GlobalInt(GpoPercentileFlag.Name),
807783
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
808784
EthashCacheDir: MakeEthashCacheDir(ctx),
809785
EthashCachesInMem: ctx.GlobalInt(EthashCachesInMemoryFlag.Name),

‎eth/api_backend.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
// EthApiBackend implements ethapi.Backend for full nodes
4040
type EthApiBackend struct {
4141
eth *Ethereum
42-
gpo *gasprice.GasPriceOracle
42+
gpo *gasprice.Oracle
4343
}
4444

4545
func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
@@ -186,7 +186,7 @@ func (b *EthApiBackend) ProtocolVersion() int {
186186
}
187187

188188
func (b *EthApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
189-
return b.gpo.SuggestPrice(), nil
189+
return b.gpo.SuggestPrice(ctx)
190190
}
191191

192192
func (b *EthApiBackend) ChainDb() ethdb.Database {

‎eth/backend.go‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ type Config struct {
8484
MinerThreads int
8585
SolcPath string
8686

87-
GpoMinGasPrice *big.Int
88-
GpoMaxGasPrice *big.Int
89-
GpoFullBlockRatio int
90-
GpobaseStepDown int
91-
GpobaseStepUp int
92-
GpobaseCorrectionFactor int
87+
GpoBlocks int
88+
GpoPercentile int
9389

9490
EnablePreimageRecording bool
9591
}
@@ -211,16 +207,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
211207
eth.miner.SetGasPrice(config.GasPrice)
212208
eth.miner.SetExtra(config.ExtraData)
213209

214-
gpoParams := &gasprice.GpoParams{
215-
GpoMinGasPrice: config.GpoMinGasPrice,
216-
GpoMaxGasPrice: config.GpoMaxGasPrice,
217-
GpoFullBlockRatio: config.GpoFullBlockRatio,
218-
GpobaseStepDown: config.GpobaseStepDown,
219-
GpobaseStepUp: config.GpobaseStepUp,
220-
GpobaseCorrectionFactor: config.GpobaseCorrectionFactor,
210+
eth.ApiBackend = &EthApiBackend{eth, nil}
211+
gpoParams := gasprice.Config{
212+
Blocks: config.GpoBlocks,
213+
Percentile: config.GpoPercentile,
214+
Default: config.GasPrice,
221215
}
222-
gpo := gasprice.NewGasPriceOracle(eth.blockchain, chainDb, eth.eventMux, gpoParams)
223-
eth.ApiBackend = &EthApiBackend{eth, gpo}
216+
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
224217

225218
return eth, nil
226219
}

0 commit comments

Comments
 (0)