From 12d627ee90c00ed4271f074cf4b74dbe09d58241 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 6 Apr 2017 19:25:33 +0200 Subject: [PATCH] eth: use gasprice.Config instead of duplicating its fields --- cmd/utils/flags.go | 13 +++++++------ eth/backend.go | 7 +++---- eth/config.go | 11 +++++++---- eth/gen_config.go | 17 ++++++----------- les/backend.go | 7 +++---- mobile/geth.go | 4 ++-- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 7be4d6ce78..344fdb313e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -37,6 +37,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethstats" "github.com/ethereum/go-ethereum/event" @@ -411,12 +412,12 @@ var ( GpoBlocksFlag = cli.IntFlag{ Name: "gpoblocks", Usage: "Number of recent blocks to check for gas prices", - Value: eth.DefaultConfig.GpoBlocks, + Value: eth.DefaultConfig.GPO.Blocks, } GpoPercentileFlag = cli.IntFlag{ Name: "gpopercentile", 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 } -func setGPO(ctx *cli.Context, cfg *eth.Config) { +func setGPO(ctx *cli.Context, cfg *gasprice.Config) { if ctx.GlobalIsSet(GpoBlocksFlag.Name) { - cfg.GpoBlocks = ctx.GlobalInt(GpoBlocksFlag.Name) + cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.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) setEtherbase(ctx, ks, cfg) - setGPO(ctx, cfg) + setGPO(ctx, &cfg.GPO) setEthash(ctx, cfg) if ctx.GlobalIsSet(FastSyncFlag.Name) { diff --git a/eth/backend.go b/eth/backend.go index 3f6b709872..5152f36efc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -165,10 +165,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { eth.miner.SetExtra(makeExtraData(config.ExtraData)) eth.ApiBackend = &EthApiBackend{eth, nil} - gpoParams := gasprice.Config{ - Blocks: config.GpoBlocks, - Percentile: config.GpoPercentile, - Default: config.GasPrice, + gpoParams := config.GPO + if gpoParams.Default == nil { + gpoParams.Default = config.GasPrice } eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams) diff --git a/eth/config.go b/eth/config.go index 29565fe033..d2a0ad0c0a 100644 --- a/eth/config.go +++ b/eth/config.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/params" ) @@ -38,8 +39,11 @@ var DefaultConfig = Config{ LightPeers: 20, DatabaseCache: 128, GasPrice: big.NewInt(20 * params.Shannon), - GpoBlocks: 10, - GpoPercentile: 50, + + GPO: gasprice.Config{ + Blocks: 10, + Percentile: 50, + }, } func init() { @@ -93,8 +97,7 @@ type Config struct { EthashDatasetsOnDisk int // Gas Price Oracle options - GpoBlocks int - GpoPercentile int + GPO gasprice.Config `toml:"gpo"` // Enables tracking of SHA3 preimages in the VM EnablePreimageRecording bool diff --git a/eth/gen_config.go b/eth/gen_config.go index 6f8bcb9c5b..e9f1b06611 100644 --- a/eth/gen_config.go +++ b/eth/gen_config.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/eth/gasprice" ) func (c Config) MarshalTOML() (interface{}, error) { @@ -32,8 +33,7 @@ func (c Config) MarshalTOML() (interface{}, error) { EthashDatasetDir string EthashDatasetsInMem int EthashDatasetsOnDisk int - GpoBlocks int - GpoPercentile int + GPO gasprice.Config `toml:"gpo"` EnablePreimageRecording bool SolcPath string DocRoot string `toml:"-"` @@ -62,8 +62,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.EthashDatasetDir = c.EthashDatasetDir enc.EthashDatasetsInMem = c.EthashDatasetsInMem enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk - enc.GpoBlocks = c.GpoBlocks - enc.GpoPercentile = c.GpoPercentile + enc.GPO = c.GPO enc.EnablePreimageRecording = c.EnablePreimageRecording enc.SolcPath = c.SolcPath enc.DocRoot = c.DocRoot @@ -95,8 +94,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { EthashDatasetDir *string EthashDatasetsInMem *int EthashDatasetsOnDisk *int - GpoBlocks *int - GpoPercentile *int + GPO *gasprice.Config `toml:"gpo"` EnablePreimageRecording *bool SolcPath *string DocRoot *string `toml:"-"` @@ -168,11 +166,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.EthashDatasetsOnDisk != nil { c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk } - if dec.GpoBlocks != nil { - c.GpoBlocks = *dec.GpoBlocks - } - if dec.GpoPercentile != nil { - c.GpoPercentile = *dec.GpoPercentile + if dec.GPO != nil { + c.GPO = *dec.GPO } if dec.EnablePreimageRecording != nil { c.EnablePreimageRecording = *dec.EnablePreimageRecording diff --git a/les/backend.go b/les/backend.go index 5670b77d25..1c78ba846e 100644 --- a/les/backend.go +++ b/les/backend.go @@ -111,10 +111,9 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { relay.reqDist = eth.protocolManager.reqDist eth.ApiBackend = &LesApiBackend{eth, nil} - gpoParams := gasprice.Config{ - Blocks: config.GpoBlocks, - Percentile: config.GpoPercentile, - Default: config.GasPrice, + gpoParams := config.GPO + if gpoParams.Default == nil { + gpoParams.Default = config.GasPrice } eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams) return eth, nil diff --git a/mobile/geth.go b/mobile/geth.go index 9ef4758118..2dad260f12 100644 --- a/mobile/geth.go +++ b/mobile/geth.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethstats" "github.com/ethereum/go-ethereum/les" @@ -151,8 +152,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { DatabaseCache: config.EthereumDatabaseCache, NetworkId: config.EthereumNetworkID, GasPrice: new(big.Int).SetUint64(20 * params.Shannon), - GpoBlocks: 10, - GpoPercentile: 50, + GPO: gasprice.Config{Blocks: 10, Percentile: 50}, EthashCacheDir: "ethash", EthashCachesInMem: 2, EthashCachesOnDisk: 3,