mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 07:23:46 +00:00
eth: use gasprice.Config instead of duplicating its fields
This commit is contained in:
parent
f65fa21dc1
commit
12d627ee90
6 changed files with 28 additions and 31 deletions
|
|
@ -37,6 +37,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethstats"
|
"github.com/ethereum/go-ethereum/ethstats"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
|
@ -411,12 +412,12 @@ var (
|
||||||
GpoBlocksFlag = cli.IntFlag{
|
GpoBlocksFlag = cli.IntFlag{
|
||||||
Name: "gpoblocks",
|
Name: "gpoblocks",
|
||||||
Usage: "Number of recent blocks to check for gas prices",
|
Usage: "Number of recent blocks to check for gas prices",
|
||||||
Value: eth.DefaultConfig.GpoBlocks,
|
Value: eth.DefaultConfig.GPO.Blocks,
|
||||||
}
|
}
|
||||||
GpoPercentileFlag = cli.IntFlag{
|
GpoPercentileFlag = cli.IntFlag{
|
||||||
Name: "gpopercentile",
|
Name: "gpopercentile",
|
||||||
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
|
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
|
||||||
Value: eth.DefaultConfig.GpoPercentile,
|
Value: eth.DefaultConfig.GPO.Percentile,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -761,12 +762,12 @@ func MakeNode(ctx *cli.Context, name, gitCommit string) *node.Node {
|
||||||
return stack
|
return stack
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGPO(ctx *cli.Context, cfg *eth.Config) {
|
func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
|
||||||
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
|
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
|
||||||
cfg.GpoBlocks = ctx.GlobalInt(GpoBlocksFlag.Name)
|
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
|
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
|
||||||
cfg.GpoPercentile = ctx.GlobalInt(GpoPercentileFlag.Name)
|
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -806,7 +807,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
|
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
setEtherbase(ctx, ks, cfg)
|
setEtherbase(ctx, ks, cfg)
|
||||||
setGPO(ctx, cfg)
|
setGPO(ctx, &cfg.GPO)
|
||||||
setEthash(ctx, cfg)
|
setEthash(ctx, cfg)
|
||||||
|
|
||||||
if ctx.GlobalIsSet(FastSyncFlag.Name) {
|
if ctx.GlobalIsSet(FastSyncFlag.Name) {
|
||||||
|
|
|
||||||
|
|
@ -165,10 +165,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
||||||
|
|
||||||
eth.ApiBackend = &EthApiBackend{eth, nil}
|
eth.ApiBackend = &EthApiBackend{eth, nil}
|
||||||
gpoParams := gasprice.Config{
|
gpoParams := config.GPO
|
||||||
Blocks: config.GpoBlocks,
|
if gpoParams.Default == nil {
|
||||||
Percentile: config.GpoPercentile,
|
gpoParams.Default = config.GasPrice
|
||||||
Default: config.GasPrice,
|
|
||||||
}
|
}
|
||||||
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
|
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -38,8 +39,11 @@ var DefaultConfig = Config{
|
||||||
LightPeers: 20,
|
LightPeers: 20,
|
||||||
DatabaseCache: 128,
|
DatabaseCache: 128,
|
||||||
GasPrice: big.NewInt(20 * params.Shannon),
|
GasPrice: big.NewInt(20 * params.Shannon),
|
||||||
GpoBlocks: 10,
|
|
||||||
GpoPercentile: 50,
|
GPO: gasprice.Config{
|
||||||
|
Blocks: 10,
|
||||||
|
Percentile: 50,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -93,8 +97,7 @@ type Config struct {
|
||||||
EthashDatasetsOnDisk int
|
EthashDatasetsOnDisk int
|
||||||
|
|
||||||
// Gas Price Oracle options
|
// Gas Price Oracle options
|
||||||
GpoBlocks int
|
GPO gasprice.Config `toml:"gpo"`
|
||||||
GpoPercentile int
|
|
||||||
|
|
||||||
// Enables tracking of SHA3 preimages in the VM
|
// Enables tracking of SHA3 preimages in the VM
|
||||||
EnablePreimageRecording bool
|
EnablePreimageRecording bool
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c Config) MarshalTOML() (interface{}, error) {
|
func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
|
|
@ -32,8 +33,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
EthashDatasetDir string
|
EthashDatasetDir string
|
||||||
EthashDatasetsInMem int
|
EthashDatasetsInMem int
|
||||||
EthashDatasetsOnDisk int
|
EthashDatasetsOnDisk int
|
||||||
GpoBlocks int
|
GPO gasprice.Config `toml:"gpo"`
|
||||||
GpoPercentile int
|
|
||||||
EnablePreimageRecording bool
|
EnablePreimageRecording bool
|
||||||
SolcPath string
|
SolcPath string
|
||||||
DocRoot string `toml:"-"`
|
DocRoot string `toml:"-"`
|
||||||
|
|
@ -62,8 +62,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.EthashDatasetDir = c.EthashDatasetDir
|
enc.EthashDatasetDir = c.EthashDatasetDir
|
||||||
enc.EthashDatasetsInMem = c.EthashDatasetsInMem
|
enc.EthashDatasetsInMem = c.EthashDatasetsInMem
|
||||||
enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk
|
enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk
|
||||||
enc.GpoBlocks = c.GpoBlocks
|
enc.GPO = c.GPO
|
||||||
enc.GpoPercentile = c.GpoPercentile
|
|
||||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||||
enc.SolcPath = c.SolcPath
|
enc.SolcPath = c.SolcPath
|
||||||
enc.DocRoot = c.DocRoot
|
enc.DocRoot = c.DocRoot
|
||||||
|
|
@ -95,8 +94,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
EthashDatasetDir *string
|
EthashDatasetDir *string
|
||||||
EthashDatasetsInMem *int
|
EthashDatasetsInMem *int
|
||||||
EthashDatasetsOnDisk *int
|
EthashDatasetsOnDisk *int
|
||||||
GpoBlocks *int
|
GPO *gasprice.Config `toml:"gpo"`
|
||||||
GpoPercentile *int
|
|
||||||
EnablePreimageRecording *bool
|
EnablePreimageRecording *bool
|
||||||
SolcPath *string
|
SolcPath *string
|
||||||
DocRoot *string `toml:"-"`
|
DocRoot *string `toml:"-"`
|
||||||
|
|
@ -168,11 +166,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.EthashDatasetsOnDisk != nil {
|
if dec.EthashDatasetsOnDisk != nil {
|
||||||
c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk
|
c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk
|
||||||
}
|
}
|
||||||
if dec.GpoBlocks != nil {
|
if dec.GPO != nil {
|
||||||
c.GpoBlocks = *dec.GpoBlocks
|
c.GPO = *dec.GPO
|
||||||
}
|
|
||||||
if dec.GpoPercentile != nil {
|
|
||||||
c.GpoPercentile = *dec.GpoPercentile
|
|
||||||
}
|
}
|
||||||
if dec.EnablePreimageRecording != nil {
|
if dec.EnablePreimageRecording != nil {
|
||||||
c.EnablePreimageRecording = *dec.EnablePreimageRecording
|
c.EnablePreimageRecording = *dec.EnablePreimageRecording
|
||||||
|
|
|
||||||
|
|
@ -111,10 +111,9 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
||||||
relay.reqDist = eth.protocolManager.reqDist
|
relay.reqDist = eth.protocolManager.reqDist
|
||||||
|
|
||||||
eth.ApiBackend = &LesApiBackend{eth, nil}
|
eth.ApiBackend = &LesApiBackend{eth, nil}
|
||||||
gpoParams := gasprice.Config{
|
gpoParams := config.GPO
|
||||||
Blocks: config.GpoBlocks,
|
if gpoParams.Default == nil {
|
||||||
Percentile: config.GpoPercentile,
|
gpoParams.Default = config.GasPrice
|
||||||
Default: config.GasPrice,
|
|
||||||
}
|
}
|
||||||
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
|
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
|
||||||
return eth, nil
|
return eth, nil
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/ethstats"
|
"github.com/ethereum/go-ethereum/ethstats"
|
||||||
"github.com/ethereum/go-ethereum/les"
|
"github.com/ethereum/go-ethereum/les"
|
||||||
|
|
@ -151,8 +152,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
|
||||||
DatabaseCache: config.EthereumDatabaseCache,
|
DatabaseCache: config.EthereumDatabaseCache,
|
||||||
NetworkId: config.EthereumNetworkID,
|
NetworkId: config.EthereumNetworkID,
|
||||||
GasPrice: new(big.Int).SetUint64(20 * params.Shannon),
|
GasPrice: new(big.Int).SetUint64(20 * params.Shannon),
|
||||||
GpoBlocks: 10,
|
GPO: gasprice.Config{Blocks: 10, Percentile: 50},
|
||||||
GpoPercentile: 50,
|
|
||||||
EthashCacheDir: "ethash",
|
EthashCacheDir: "ethash",
|
||||||
EthashCachesInMem: 2,
|
EthashCachesInMem: 2,
|
||||||
EthashCachesOnDisk: 3,
|
EthashCachesOnDisk: 3,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue