aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-08-22 03:56:54 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-22 03:56:54 +0800
commitb2c644ffb5c283a171ddf3889693673939917541 (patch)
tree501d3c337f5fb59404fd8d530eb247cdcc2144eb /eth
parent522cfc68ff496aee4205add982db049dc3092024 (diff)
downloaddexon-b2c644ffb5c283a171ddf3889693673939917541.tar
dexon-b2c644ffb5c283a171ddf3889693673939917541.tar.gz
dexon-b2c644ffb5c283a171ddf3889693673939917541.tar.bz2
dexon-b2c644ffb5c283a171ddf3889693673939917541.tar.lz
dexon-b2c644ffb5c283a171ddf3889693673939917541.tar.xz
dexon-b2c644ffb5c283a171ddf3889693673939917541.tar.zst
dexon-b2c644ffb5c283a171ddf3889693673939917541.zip
cmd, eth, miner: make recommit configurable (#17444)
* cmd, eth, miner: make recommit configurable * cmd, eth, les, miner: polish a bit * miner: filter duplicate sealing work * cmd: remove uncessary conversion * miner: avoid microptimization in favor of cleaner code
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go6
-rw-r--r--eth/backend.go8
-rw-r--r--eth/config.go15
-rw-r--r--eth/gen_config.go53
4 files changed, 61 insertions, 21 deletions
diff --git a/eth/api.go b/eth/api.go
index c1fbcb6d4..4b0ba8edb 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -25,6 +25,7 @@ import (
"math/big"
"os"
"strings"
+ "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -160,6 +161,11 @@ func (api *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
return true
}
+// SetRecommitInterval updates the interval for miner sealing work recommitting.
+func (api *PrivateMinerAPI) SetRecommitInterval(interval int) {
+ api.e.Miner().SetRecommitInterval(time.Duration(interval) * time.Millisecond)
+}
+
// GetHashrate returns the current hashrate of the miner.
func (api *PrivateMinerAPI) GetHashrate() uint64 {
return api.e.miner.HashRate()
diff --git a/eth/backend.go b/eth/backend.go
index 588b78256..648175acf 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -127,7 +127,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.MinerNotify, chainDb),
shutdownChan: make(chan bool),
networkID: config.NetworkId,
- gasPrice: config.GasPrice,
+ gasPrice: config.MinerGasPrice,
etherbase: config.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, bloomConfirms),
@@ -167,13 +167,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return nil, err
}
- eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine)
- eth.miner.SetExtra(makeExtraData(config.ExtraData))
+ eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit)
+ eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
eth.APIBackend = &EthAPIBackend{eth, nil}
gpoParams := config.GPO
if gpoParams.Default == nil {
- gpoParams.Default = config.GasPrice
+ gpoParams.Default = config.MinerGasPrice
}
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
diff --git a/eth/config.go b/eth/config.go
index 0c82f2923..cbd02416b 100644
--- a/eth/config.go
+++ b/eth/config.go
@@ -48,7 +48,7 @@ var DefaultConfig = Config{
DatabaseCache: 768,
TrieCache: 256,
TrieTimeout: 60 * time.Minute,
- GasPrice: big.NewInt(18 * params.Shannon),
+ MinerGasPrice: big.NewInt(18 * params.Shannon),
TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
@@ -95,11 +95,12 @@ type Config struct {
TrieTimeout time.Duration
// Mining-related options
- Etherbase common.Address `toml:",omitempty"`
- MinerThreads int `toml:",omitempty"`
- MinerNotify []string `toml:",omitempty"`
- ExtraData []byte `toml:",omitempty"`
- GasPrice *big.Int
+ Etherbase common.Address `toml:",omitempty"`
+ MinerThreads int `toml:",omitempty"`
+ MinerNotify []string `toml:",omitempty"`
+ MinerExtraData []byte `toml:",omitempty"`
+ MinerGasPrice *big.Int
+ MinerRecommit time.Duration
// Ethash options
Ethash ethash.Config
@@ -118,5 +119,5 @@ type Config struct {
}
type configMarshaling struct {
- ExtraData hexutil.Bytes
+ MinerExtraData hexutil.Bytes
}
diff --git a/eth/gen_config.go b/eth/gen_config.go
index 4f2e82d94..62556be7e 100644
--- a/eth/gen_config.go
+++ b/eth/gen_config.go
@@ -4,6 +4,7 @@ package eth
import (
"math/big"
+ "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -15,20 +16,26 @@ import (
var _ = (*configMarshaling)(nil)
+// MarshalTOML marshals as TOML.
func (c Config) MarshalTOML() (interface{}, error) {
type Config struct {
Genesis *core.Genesis `toml:",omitempty"`
NetworkId uint64
SyncMode downloader.SyncMode
+ NoPruning bool
LightServ int `toml:",omitempty"`
LightPeers int `toml:",omitempty"`
SkipBcVersionCheck bool `toml:"-"`
DatabaseHandles int `toml:"-"`
DatabaseCache int
+ TrieCache int
+ TrieTimeout time.Duration
Etherbase common.Address `toml:",omitempty"`
MinerThreads int `toml:",omitempty"`
- ExtraData hexutil.Bytes `toml:",omitempty"`
- GasPrice *big.Int
+ MinerNotify []string `toml:",omitempty"`
+ MinerExtraData hexutil.Bytes `toml:",omitempty"`
+ MinerGasPrice *big.Int
+ MinerRecommit time.Duration
Ethash ethash.Config
TxPool core.TxPoolConfig
GPO gasprice.Config
@@ -39,15 +46,20 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.Genesis = c.Genesis
enc.NetworkId = c.NetworkId
enc.SyncMode = c.SyncMode
+ enc.NoPruning = c.NoPruning
enc.LightServ = c.LightServ
enc.LightPeers = c.LightPeers
enc.SkipBcVersionCheck = c.SkipBcVersionCheck
enc.DatabaseHandles = c.DatabaseHandles
enc.DatabaseCache = c.DatabaseCache
+ enc.TrieCache = c.TrieCache
+ enc.TrieTimeout = c.TrieTimeout
enc.Etherbase = c.Etherbase
enc.MinerThreads = c.MinerThreads
- enc.ExtraData = c.ExtraData
- enc.GasPrice = c.GasPrice
+ enc.MinerNotify = c.MinerNotify
+ enc.MinerExtraData = c.MinerExtraData
+ enc.MinerGasPrice = c.MinerGasPrice
+ enc.MinerRecommit = c.MinerRecommit
enc.Ethash = c.Ethash
enc.TxPool = c.TxPool
enc.GPO = c.GPO
@@ -56,20 +68,26 @@ func (c Config) MarshalTOML() (interface{}, error) {
return &enc, nil
}
+// UnmarshalTOML unmarshals from TOML.
func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
type Config struct {
Genesis *core.Genesis `toml:",omitempty"`
NetworkId *uint64
SyncMode *downloader.SyncMode
+ NoPruning *bool
LightServ *int `toml:",omitempty"`
LightPeers *int `toml:",omitempty"`
SkipBcVersionCheck *bool `toml:"-"`
DatabaseHandles *int `toml:"-"`
DatabaseCache *int
+ TrieCache *int
+ TrieTimeout *time.Duration
Etherbase *common.Address `toml:",omitempty"`
MinerThreads *int `toml:",omitempty"`
- ExtraData *hexutil.Bytes `toml:",omitempty"`
- GasPrice *big.Int
+ MinerNotify []string `toml:",omitempty"`
+ MinerExtraData *hexutil.Bytes `toml:",omitempty"`
+ MinerGasPrice *big.Int
+ MinerRecommit *time.Duration
Ethash *ethash.Config
TxPool *core.TxPoolConfig
GPO *gasprice.Config
@@ -89,6 +107,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.SyncMode != nil {
c.SyncMode = *dec.SyncMode
}
+ if dec.NoPruning != nil {
+ c.NoPruning = *dec.NoPruning
+ }
if dec.LightServ != nil {
c.LightServ = *dec.LightServ
}
@@ -104,17 +125,29 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.DatabaseCache != nil {
c.DatabaseCache = *dec.DatabaseCache
}
+ if dec.TrieCache != nil {
+ c.TrieCache = *dec.TrieCache
+ }
+ if dec.TrieTimeout != nil {
+ c.TrieTimeout = *dec.TrieTimeout
+ }
if dec.Etherbase != nil {
c.Etherbase = *dec.Etherbase
}
if dec.MinerThreads != nil {
c.MinerThreads = *dec.MinerThreads
}
- if dec.ExtraData != nil {
- c.ExtraData = *dec.ExtraData
+ if dec.MinerNotify != nil {
+ c.MinerNotify = dec.MinerNotify
+ }
+ if dec.MinerExtraData != nil {
+ c.MinerExtraData = *dec.MinerExtraData
+ }
+ if dec.MinerGasPrice != nil {
+ c.MinerGasPrice = dec.MinerGasPrice
}
- if dec.GasPrice != nil {
- c.GasPrice = dec.GasPrice
+ if dec.MinerRecommit != nil {
+ c.MinerRecommit = *dec.MinerRecommit
}
if dec.Ethash != nil {
c.Ethash = *dec.Ethash