aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2017-11-24 22:10:27 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-11-24 22:10:27 +0800
commitf14047dae57aa69e4fa08d57e19ee9c0283dfa54 (patch)
treeb1b9523a4ce12e2b3cc472bdcf38df7ddbd4bdcc /eth
parentb0056f5bd096adf42a2c28cd76264f230c7cae20 (diff)
downloaddexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar.gz
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar.bz2
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar.lz
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar.xz
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.tar.zst
dexon-f14047dae57aa69e4fa08d57e19ee9c0283dfa54.zip
cmd, consensus, eth: split ethash related config to it own (#15520)
* cmd, consensus, eth: split ethash related config to it own * eth, consensus: minor polish * eth, consenus, console: compress pow testing config field to single one * consensus, eth: document pow mode
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go20
-rw-r--r--eth/config.go39
-rw-r--r--eth/gen_config.go51
3 files changed, 50 insertions, 60 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 1cd9e8fff..e7f0f57dd 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -125,7 +125,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
chainConfig: chainConfig,
eventMux: ctx.EventMux,
accountManager: ctx.AccountManager,
- engine: CreateConsensusEngine(ctx, config, chainConfig, chainDb),
+ engine: CreateConsensusEngine(ctx, &config.Ethash, chainConfig, chainDb),
shutdownChan: make(chan bool),
stopDbUpgrade: stopDbUpgrade,
networkId: config.NetworkId,
@@ -209,25 +209,31 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data
}
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
-func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
+func CreateConsensusEngine(ctx *node.ServiceContext, config *ethash.Config, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
if chainConfig.Clique != nil {
return clique.New(chainConfig.Clique, db)
}
// Otherwise assume proof-of-work
switch {
- case config.PowFake:
+ case config.PowMode == ethash.ModeFake:
log.Warn("Ethash used in fake mode")
return ethash.NewFaker()
- case config.PowTest:
+ case config.PowMode == ethash.ModeTest:
log.Warn("Ethash used in test mode")
return ethash.NewTester()
- case config.PowShared:
+ case config.PowMode == ethash.ModeShared:
log.Warn("Ethash used in shared mode")
return ethash.NewShared()
default:
- engine := ethash.New(ctx.ResolvePath(config.EthashCacheDir), config.EthashCachesInMem, config.EthashCachesOnDisk,
- config.EthashDatasetDir, config.EthashDatasetsInMem, config.EthashDatasetsOnDisk)
+ engine := ethash.New(ethash.Config{
+ CacheDir: ctx.ResolvePath(config.CacheDir),
+ CachesInMem: config.CachesInMem,
+ CachesOnDisk: config.CachesOnDisk,
+ DatasetDir: config.DatasetDir,
+ DatasetsInMem: config.DatasetsInMem,
+ DatasetsOnDisk: config.DatasetsOnDisk,
+ })
engine.SetThreads(-1) // Disable CPU mining
return engine
}
diff --git a/eth/config.go b/eth/config.go
index 7bcfd403e..383cd6783 100644
--- a/eth/config.go
+++ b/eth/config.go
@@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
+ "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
@@ -33,16 +34,18 @@ import (
// DefaultConfig contains default settings for use on the Ethereum main net.
var DefaultConfig = Config{
- SyncMode: downloader.FastSync,
- EthashCacheDir: "ethash",
- EthashCachesInMem: 2,
- EthashCachesOnDisk: 3,
- EthashDatasetsInMem: 1,
- EthashDatasetsOnDisk: 2,
- NetworkId: 1,
- LightPeers: 20,
- DatabaseCache: 128,
- GasPrice: big.NewInt(18 * params.Shannon),
+ SyncMode: downloader.FastSync,
+ Ethash: ethash.Config{
+ CacheDir: "ethash",
+ CachesInMem: 2,
+ CachesOnDisk: 3,
+ DatasetsInMem: 1,
+ DatasetsOnDisk: 2,
+ },
+ NetworkId: 1,
+ LightPeers: 20,
+ DatabaseCache: 128,
+ GasPrice: big.NewInt(18 * params.Shannon),
TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
@@ -59,9 +62,9 @@ func init() {
}
}
if runtime.GOOS == "windows" {
- DefaultConfig.EthashDatasetDir = filepath.Join(home, "AppData", "Ethash")
+ DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
} else {
- DefaultConfig.EthashDatasetDir = filepath.Join(home, ".ethash")
+ DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
}
}
@@ -92,12 +95,7 @@ type Config struct {
GasPrice *big.Int
// Ethash options
- EthashCacheDir string
- EthashCachesInMem int
- EthashCachesOnDisk int
- EthashDatasetDir string
- EthashDatasetsInMem int
- EthashDatasetsOnDisk int
+ Ethash ethash.Config
// Transaction pool options
TxPool core.TxPoolConfig
@@ -109,10 +107,7 @@ type Config struct {
EnablePreimageRecording bool
// Miscellaneous options
- DocRoot string `toml:"-"`
- PowFake bool `toml:"-"`
- PowTest bool `toml:"-"`
- PowShared bool `toml:"-"`
+ DocRoot string `toml:"-"`
}
type configMarshaling struct {
diff --git a/eth/gen_config.go b/eth/gen_config.go
index 4a4cd7b9c..e2d50e1f6 100644
--- a/eth/gen_config.go
+++ b/eth/gen_config.go
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
+ "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
@@ -36,10 +37,8 @@ func (c Config) MarshalTOML() (interface{}, error) {
TxPool core.TxPoolConfig
GPO gasprice.Config
EnablePreimageRecording bool
- DocRoot string `toml:"-"`
- PowFake bool `toml:"-"`
- PowTest bool `toml:"-"`
- PowShared bool `toml:"-"`
+ DocRoot string `toml:"-"`
+ PowMode ethash.Mode `toml:"-"`
}
var enc Config
enc.Genesis = c.Genesis
@@ -54,19 +53,17 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.MinerThreads = c.MinerThreads
enc.ExtraData = c.ExtraData
enc.GasPrice = c.GasPrice
- enc.EthashCacheDir = c.EthashCacheDir
- enc.EthashCachesInMem = c.EthashCachesInMem
- enc.EthashCachesOnDisk = c.EthashCachesOnDisk
- enc.EthashDatasetDir = c.EthashDatasetDir
- enc.EthashDatasetsInMem = c.EthashDatasetsInMem
- enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk
+ enc.EthashCacheDir = c.Ethash.CacheDir
+ enc.EthashCachesInMem = c.Ethash.CachesInMem
+ enc.EthashCachesOnDisk = c.Ethash.CachesOnDisk
+ enc.EthashDatasetDir = c.Ethash.DatasetDir
+ enc.EthashDatasetsInMem = c.Ethash.DatasetsInMem
+ enc.EthashDatasetsOnDisk = c.Ethash.DatasetsOnDisk
enc.TxPool = c.TxPool
enc.GPO = c.GPO
enc.EnablePreimageRecording = c.EnablePreimageRecording
enc.DocRoot = c.DocRoot
- enc.PowFake = c.PowFake
- enc.PowTest = c.PowTest
- enc.PowShared = c.PowShared
+ enc.PowMode = c.Ethash.PowMode
return &enc, nil
}
@@ -94,10 +91,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
TxPool *core.TxPoolConfig
GPO *gasprice.Config
EnablePreimageRecording *bool
- DocRoot *string `toml:"-"`
- PowFake *bool `toml:"-"`
- PowTest *bool `toml:"-"`
- PowShared *bool `toml:"-"`
+ DocRoot *string `toml:"-"`
+ PowMode *ethash.Mode `toml:"-"`
}
var dec Config
if err := unmarshal(&dec); err != nil {
@@ -140,22 +135,22 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
c.GasPrice = dec.GasPrice
}
if dec.EthashCacheDir != nil {
- c.EthashCacheDir = *dec.EthashCacheDir
+ c.Ethash.CacheDir = *dec.EthashCacheDir
}
if dec.EthashCachesInMem != nil {
- c.EthashCachesInMem = *dec.EthashCachesInMem
+ c.Ethash.CachesInMem = *dec.EthashCachesInMem
}
if dec.EthashCachesOnDisk != nil {
- c.EthashCachesOnDisk = *dec.EthashCachesOnDisk
+ c.Ethash.CachesOnDisk = *dec.EthashCachesOnDisk
}
if dec.EthashDatasetDir != nil {
- c.EthashDatasetDir = *dec.EthashDatasetDir
+ c.Ethash.DatasetDir = *dec.EthashDatasetDir
}
if dec.EthashDatasetsInMem != nil {
- c.EthashDatasetsInMem = *dec.EthashDatasetsInMem
+ c.Ethash.DatasetsInMem = *dec.EthashDatasetsInMem
}
if dec.EthashDatasetsOnDisk != nil {
- c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk
+ c.Ethash.DatasetsOnDisk = *dec.EthashDatasetsOnDisk
}
if dec.TxPool != nil {
c.TxPool = *dec.TxPool
@@ -169,14 +164,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DocRoot != nil {
c.DocRoot = *dec.DocRoot
}
- if dec.PowFake != nil {
- c.PowFake = *dec.PowFake
- }
- if dec.PowTest != nil {
- c.PowTest = *dec.PowTest
- }
- if dec.PowShared != nil {
- c.PowShared = *dec.PowShared
+ if dec.PowMode != nil {
+ c.Ethash.PowMode = *dec.PowMode
}
return nil
}