Skip to content

Commit

Permalink
cmd, les, eth, eth/gasprice: using new gas price oracle (ethereum#13853)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zsfelfoldi authored and karalabe committed Apr 6, 2017
1 parent 0ec1104 commit 9aca9e6
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 419 deletions.
8 changes: 2 additions & 6 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,8 @@ func init() {
utils.FakePoWFlag,
utils.NoCompactionFlag,
utils.SolcPathFlag,
utils.GpoMinGasPriceFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoFullBlockRatioFlag,
utils.GpobaseStepDownFlag,
utils.GpobaseStepUpFlag,
utils.GpobaseCorrectionFactorFlag,
utils.GpoBlocksFlag,
utils.GpoPercentileFlag,
utils.ExtraDataFlag,
}
app.Flags = append(app.Flags, debug.Flags...)
Expand Down
8 changes: 2 additions & 6 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,8 @@ var AppHelpFlagGroups = []flagGroup{
{
Name: "GAS PRICE ORACLE",
Flags: []cli.Flag{
utils.GpoMinGasPriceFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoFullBlockRatioFlag,
utils.GpobaseStepDownFlag,
utils.GpobaseStepUpFlag,
utils.GpobaseCorrectionFactorFlag,
utils.GpoBlocksFlag,
utils.GpoPercentileFlag,
},
},
{
Expand Down
42 changes: 9 additions & 33 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,35 +409,15 @@ var (
}

// Gas price oracle settings
GpoMinGasPriceFlag = BigFlag{
Name: "gpomin",
Usage: "Minimum suggested gas price",
Value: big.NewInt(20 * params.Shannon),
}
GpoMaxGasPriceFlag = BigFlag{
Name: "gpomax",
Usage: "Maximum suggested gas price",
Value: big.NewInt(500 * params.Shannon),
}
GpoFullBlockRatioFlag = cli.IntFlag{
Name: "gpofull",
Usage: "Full block threshold for gas price calculation (%)",
Value: 80,
}
GpobaseStepDownFlag = cli.IntFlag{
Name: "gpobasedown",
Usage: "Suggested gas price base step down ratio (1/1000)",
GpoBlocksFlag = cli.IntFlag{
Name: "gpoblocks",
Usage: "Number of recent blocks to check for gas prices",
Value: 10,
}
GpobaseStepUpFlag = cli.IntFlag{
Name: "gpobaseup",
Usage: "Suggested gas price base step up ratio (1/1000)",
Value: 100,
}
GpobaseCorrectionFactorFlag = cli.IntFlag{
Name: "gpobasecf",
Usage: "Suggested gas price base correction factor (%)",
Value: 110,
GpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile",
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
Value: 50,
}
)

Expand Down Expand Up @@ -798,12 +778,8 @@ func RegisterEthService(ctx *cli.Context, stack *node.Node, extra []byte) {
ExtraData: MakeMinerExtra(extra, ctx),
DocRoot: ctx.GlobalString(DocRootFlag.Name),
GasPrice: GlobalBig(ctx, GasPriceFlag.Name),
GpoMinGasPrice: GlobalBig(ctx, GpoMinGasPriceFlag.Name),
GpoMaxGasPrice: GlobalBig(ctx, GpoMaxGasPriceFlag.Name),
GpoFullBlockRatio: ctx.GlobalInt(GpoFullBlockRatioFlag.Name),
GpobaseStepDown: ctx.GlobalInt(GpobaseStepDownFlag.Name),
GpobaseStepUp: ctx.GlobalInt(GpobaseStepUpFlag.Name),
GpobaseCorrectionFactor: ctx.GlobalInt(GpobaseCorrectionFactorFlag.Name),
GpoBlocks: ctx.GlobalInt(GpoBlocksFlag.Name),
GpoPercentile: ctx.GlobalInt(GpoPercentileFlag.Name),
SolcPath: ctx.GlobalString(SolcPathFlag.Name),
EthashCacheDir: MakeEthashCacheDir(ctx),
EthashCachesInMem: ctx.GlobalInt(EthashCachesInMemoryFlag.Name),
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// EthApiBackend implements ethapi.Backend for full nodes
type EthApiBackend struct {
eth *Ethereum
gpo *gasprice.GasPriceOracle
gpo *gasprice.Oracle
}

func (b *EthApiBackend) ChainConfig() *params.ChainConfig {
Expand Down Expand Up @@ -186,7 +186,7 @@ func (b *EthApiBackend) ProtocolVersion() int {
}

func (b *EthApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return b.gpo.SuggestPrice(), nil
return b.gpo.SuggestPrice(ctx)
}

func (b *EthApiBackend) ChainDb() ethdb.Database {
Expand Down
23 changes: 8 additions & 15 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ type Config struct {
MinerThreads int
SolcPath string

GpoMinGasPrice *big.Int
GpoMaxGasPrice *big.Int
GpoFullBlockRatio int
GpobaseStepDown int
GpobaseStepUp int
GpobaseCorrectionFactor int
GpoBlocks int
GpoPercentile int

EnablePreimageRecording bool
}
Expand Down Expand Up @@ -211,16 +207,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.miner.SetGasPrice(config.GasPrice)
eth.miner.SetExtra(config.ExtraData)

gpoParams := &gasprice.GpoParams{
GpoMinGasPrice: config.GpoMinGasPrice,
GpoMaxGasPrice: config.GpoMaxGasPrice,
GpoFullBlockRatio: config.GpoFullBlockRatio,
GpobaseStepDown: config.GpobaseStepDown,
GpobaseStepUp: config.GpobaseStepUp,
GpobaseCorrectionFactor: config.GpobaseCorrectionFactor,
eth.ApiBackend = &EthApiBackend{eth, nil}
gpoParams := gasprice.Config{
Blocks: config.GpoBlocks,
Percentile: config.GpoPercentile,
Default: config.GasPrice,
}
gpo := gasprice.NewGasPriceOracle(eth.blockchain, chainDb, eth.eventMux, gpoParams)
eth.ApiBackend = &EthApiBackend{eth, gpo}
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)

return eth, nil
}
Expand Down
Loading

0 comments on commit 9aca9e6

Please sign in to comment.