mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
cmd, eth, les, miner: polish a bit
This commit is contained in:
parent
72f710ab87
commit
d08db95664
7 changed files with 79 additions and 78 deletions
|
|
@ -335,12 +335,12 @@ var (
|
||||||
MinerGasPriceFlag = BigFlag{
|
MinerGasPriceFlag = BigFlag{
|
||||||
Name: "miner.gasprice",
|
Name: "miner.gasprice",
|
||||||
Usage: "Minimal gas price for mining a transactions",
|
Usage: "Minimal gas price for mining a transactions",
|
||||||
Value: eth.DefaultConfig.GasPrice,
|
Value: eth.DefaultConfig.MinerGasPrice,
|
||||||
}
|
}
|
||||||
MinerLegacyGasPriceFlag = BigFlag{
|
MinerLegacyGasPriceFlag = BigFlag{
|
||||||
Name: "gasprice",
|
Name: "gasprice",
|
||||||
Usage: "Minimal gas price for mining a transactions (deprecated, use --miner.gasprice)",
|
Usage: "Minimal gas price for mining a transactions (deprecated, use --miner.gasprice)",
|
||||||
Value: eth.DefaultConfig.GasPrice,
|
Value: eth.DefaultConfig.MinerGasPrice,
|
||||||
}
|
}
|
||||||
MinerEtherbaseFlag = cli.StringFlag{
|
MinerEtherbaseFlag = cli.StringFlag{
|
||||||
Name: "miner.etherbase",
|
Name: "miner.etherbase",
|
||||||
|
|
@ -360,10 +360,10 @@ var (
|
||||||
Name: "extradata",
|
Name: "extradata",
|
||||||
Usage: "Block extra data set by the miner (default = client version, deprecated, use --miner.extradata)",
|
Usage: "Block extra data set by the miner (default = client version, deprecated, use --miner.extradata)",
|
||||||
}
|
}
|
||||||
MinerRecommitIntervalFlag = cli.IntFlag{
|
MinerRecommitIntervalFlag = cli.DurationFlag{
|
||||||
Name: "miner.recommit",
|
Name: "miner.recommit",
|
||||||
Usage: "Sealing work recommit interval(ms), will be dynamically adjusted by the system if it is too short",
|
Usage: "Time interval to recreate the block being mined.",
|
||||||
Value: 3000,
|
Value: time.Duration(3 * time.Second),
|
||||||
}
|
}
|
||||||
// Account settings
|
// Account settings
|
||||||
UnlockedAccountFlag = cli.StringFlag{
|
UnlockedAccountFlag = cli.StringFlag{
|
||||||
|
|
@ -1129,19 +1129,19 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerLegacyExtraDataFlag.Name) {
|
if ctx.GlobalIsSet(MinerLegacyExtraDataFlag.Name) {
|
||||||
cfg.ExtraData = []byte(ctx.GlobalString(MinerLegacyExtraDataFlag.Name))
|
cfg.MinerExtraData = []byte(ctx.GlobalString(MinerLegacyExtraDataFlag.Name))
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
||||||
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
cfg.MinerExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
if ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
||||||
cfg.GasPrice = GlobalBig(ctx, MinerLegacyGasPriceFlag.Name)
|
cfg.MinerGasPrice = GlobalBig(ctx, MinerLegacyGasPriceFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
||||||
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
cfg.MinerGasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
|
if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
|
||||||
cfg.RecommitInterval = time.Duration(ctx.GlobalInt(MinerRecommitIntervalFlag.Name)) * time.Millisecond
|
cfg.MinerRecommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
|
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
|
||||||
// TODO(fjl): force-enable this in --dev mode
|
// TODO(fjl): force-enable this in --dev mode
|
||||||
|
|
@ -1184,7 +1184,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
|
|
||||||
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
|
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
|
||||||
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
||||||
cfg.GasPrice = big.NewInt(1)
|
cfg.MinerGasPrice = big.NewInt(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO(fjl): move trie cache generations into config
|
// TODO(fjl): move trie cache generations into config
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.MinerNotify, chainDb),
|
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.MinerNotify, chainDb),
|
||||||
shutdownChan: make(chan bool),
|
shutdownChan: make(chan bool),
|
||||||
networkID: config.NetworkId,
|
networkID: config.NetworkId,
|
||||||
gasPrice: config.GasPrice,
|
gasPrice: config.MinerGasPrice,
|
||||||
etherbase: config.Etherbase,
|
etherbase: config.Etherbase,
|
||||||
bloomRequests: make(chan chan *bloombits.Retrieval),
|
bloomRequests: make(chan chan *bloombits.Retrieval),
|
||||||
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, bloomConfirms),
|
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, bloomConfirms),
|
||||||
|
|
@ -167,13 +167,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.RecommitInterval)
|
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit)
|
||||||
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
|
||||||
|
|
||||||
eth.APIBackend = &EthAPIBackend{eth, nil}
|
eth.APIBackend = &EthAPIBackend{eth, nil}
|
||||||
gpoParams := config.GPO
|
gpoParams := config.GPO
|
||||||
if gpoParams.Default == nil {
|
if gpoParams.Default == nil {
|
||||||
gpoParams.Default = config.GasPrice
|
gpoParams.Default = config.MinerGasPrice
|
||||||
}
|
}
|
||||||
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ var DefaultConfig = Config{
|
||||||
DatabaseCache: 768,
|
DatabaseCache: 768,
|
||||||
TrieCache: 256,
|
TrieCache: 256,
|
||||||
TrieTimeout: 60 * time.Minute,
|
TrieTimeout: 60 * time.Minute,
|
||||||
GasPrice: big.NewInt(18 * params.Shannon),
|
MinerGasPrice: big.NewInt(18 * params.Shannon),
|
||||||
|
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
GPO: gasprice.Config{
|
GPO: gasprice.Config{
|
||||||
|
|
@ -95,12 +95,12 @@ type Config struct {
|
||||||
TrieTimeout time.Duration
|
TrieTimeout time.Duration
|
||||||
|
|
||||||
// Mining-related options
|
// Mining-related options
|
||||||
Etherbase common.Address `toml:",omitempty"`
|
Etherbase common.Address `toml:",omitempty"`
|
||||||
MinerThreads int `toml:",omitempty"`
|
MinerThreads int `toml:",omitempty"`
|
||||||
MinerNotify []string `toml:",omitempty"`
|
MinerNotify []string `toml:",omitempty"`
|
||||||
ExtraData []byte `toml:",omitempty"`
|
MinerExtraData []byte `toml:",omitempty"`
|
||||||
GasPrice *big.Int
|
MinerGasPrice *big.Int
|
||||||
RecommitInterval time.Duration
|
MinerRecommit time.Duration
|
||||||
|
|
||||||
// Ethash options
|
// Ethash options
|
||||||
Ethash ethash.Config
|
Ethash ethash.Config
|
||||||
|
|
@ -119,5 +119,5 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type configMarshaling struct {
|
type configMarshaling struct {
|
||||||
ExtraData hexutil.Bytes
|
MinerExtraData hexutil.Bytes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
Etherbase common.Address `toml:",omitempty"`
|
Etherbase common.Address `toml:",omitempty"`
|
||||||
MinerThreads int `toml:",omitempty"`
|
MinerThreads int `toml:",omitempty"`
|
||||||
MinerNotify []string `toml:",omitempty"`
|
MinerNotify []string `toml:",omitempty"`
|
||||||
ExtraData hexutil.Bytes `toml:",omitempty"`
|
MinerExtraData hexutil.Bytes `toml:",omitempty"`
|
||||||
GasPrice *big.Int
|
MinerGasPrice *big.Int
|
||||||
RecommitInterval time.Duration
|
MinerRecommit time.Duration
|
||||||
Ethash ethash.Config
|
Ethash ethash.Config
|
||||||
TxPool core.TxPoolConfig
|
TxPool core.TxPoolConfig
|
||||||
GPO gasprice.Config
|
GPO gasprice.Config
|
||||||
|
|
@ -57,9 +57,9 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.Etherbase = c.Etherbase
|
enc.Etherbase = c.Etherbase
|
||||||
enc.MinerThreads = c.MinerThreads
|
enc.MinerThreads = c.MinerThreads
|
||||||
enc.MinerNotify = c.MinerNotify
|
enc.MinerNotify = c.MinerNotify
|
||||||
enc.ExtraData = c.ExtraData
|
enc.MinerExtraData = c.MinerExtraData
|
||||||
enc.GasPrice = c.GasPrice
|
enc.MinerGasPrice = c.MinerGasPrice
|
||||||
enc.RecommitInterval = c.RecommitInterval
|
enc.MinerRecommit = c.MinerRecommit
|
||||||
enc.Ethash = c.Ethash
|
enc.Ethash = c.Ethash
|
||||||
enc.TxPool = c.TxPool
|
enc.TxPool = c.TxPool
|
||||||
enc.GPO = c.GPO
|
enc.GPO = c.GPO
|
||||||
|
|
@ -85,9 +85,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
Etherbase *common.Address `toml:",omitempty"`
|
Etherbase *common.Address `toml:",omitempty"`
|
||||||
MinerThreads *int `toml:",omitempty"`
|
MinerThreads *int `toml:",omitempty"`
|
||||||
MinerNotify []string `toml:",omitempty"`
|
MinerNotify []string `toml:",omitempty"`
|
||||||
ExtraData *hexutil.Bytes `toml:",omitempty"`
|
MinerExtraData *hexutil.Bytes `toml:",omitempty"`
|
||||||
GasPrice *big.Int
|
MinerGasPrice *big.Int
|
||||||
RecommitInterval *time.Duration
|
MinerRecommit *time.Duration
|
||||||
Ethash *ethash.Config
|
Ethash *ethash.Config
|
||||||
TxPool *core.TxPoolConfig
|
TxPool *core.TxPoolConfig
|
||||||
GPO *gasprice.Config
|
GPO *gasprice.Config
|
||||||
|
|
@ -140,14 +140,14 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.MinerNotify != nil {
|
if dec.MinerNotify != nil {
|
||||||
c.MinerNotify = dec.MinerNotify
|
c.MinerNotify = dec.MinerNotify
|
||||||
}
|
}
|
||||||
if dec.ExtraData != nil {
|
if dec.MinerExtraData != nil {
|
||||||
c.ExtraData = *dec.ExtraData
|
c.MinerExtraData = *dec.MinerExtraData
|
||||||
}
|
}
|
||||||
if dec.GasPrice != nil {
|
if dec.MinerGasPrice != nil {
|
||||||
c.GasPrice = dec.GasPrice
|
c.MinerGasPrice = dec.MinerGasPrice
|
||||||
}
|
}
|
||||||
if dec.RecommitInterval != nil {
|
if dec.MinerRecommit != nil {
|
||||||
c.RecommitInterval = *dec.RecommitInterval
|
c.MinerRecommit = *dec.MinerRecommit
|
||||||
}
|
}
|
||||||
if dec.Ethash != nil {
|
if dec.Ethash != nil {
|
||||||
c.Ethash = *dec.Ethash
|
c.Ethash = *dec.Ethash
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
||||||
leth.ApiBackend = &LesApiBackend{leth, nil}
|
leth.ApiBackend = &LesApiBackend{leth, nil}
|
||||||
gpoParams := config.GPO
|
gpoParams := config.GPO
|
||||||
if gpoParams.Default == nil {
|
if gpoParams.Default == nil {
|
||||||
gpoParams.Default = config.GasPrice
|
gpoParams.Default = config.MinerGasPrice
|
||||||
}
|
}
|
||||||
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
||||||
return leth, nil
|
return leth, nil
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,13 @@ type Miner struct {
|
||||||
shouldStart int32 // should start indicates whether we should start after sync
|
shouldStart int32 // should start indicates whether we should start after sync
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommitInterval time.Duration) *Miner {
|
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
exitCh: make(chan struct{}),
|
exitCh: make(chan struct{}),
|
||||||
worker: newWorker(config, engine, eth, mux, recommitInterval),
|
worker: newWorker(config, engine, eth, mux, recommit),
|
||||||
canStart: 1,
|
canStart: 1,
|
||||||
}
|
}
|
||||||
go miner.update()
|
go miner.update()
|
||||||
|
|
@ -145,6 +145,7 @@ func (self *Miner) SetExtra(extra []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetRecommitInterval sets the interval for sealing work resubmitting.
|
||||||
func (self *Miner) SetRecommitInterval(interval time.Duration) {
|
func (self *Miner) SetRecommitInterval(interval time.Duration) {
|
||||||
self.worker.setRecommitInterval(interval)
|
self.worker.setRecommitInterval(interval)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ type worker struct {
|
||||||
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommitInterval time.Duration) *worker {
|
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration) *worker {
|
||||||
worker := &worker{
|
worker := &worker{
|
||||||
config: config,
|
config: config,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
|
|
@ -190,14 +190,14 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
|
||||||
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
|
worker.chainHeadSub = eth.BlockChain().SubscribeChainHeadEvent(worker.chainHeadCh)
|
||||||
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
||||||
|
|
||||||
// Recap recommit interval if the user-specified one is too short.
|
// Sanitize recommit interval if the user-specified one is too short.
|
||||||
if recommitInterval < minRecommitInterval {
|
if recommit < minRecommitInterval {
|
||||||
log.Info("Recap miner recommit interval", "from", recommitInterval, "to", minRecommitInterval)
|
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
|
||||||
recommitInterval = minRecommitInterval
|
recommit = minRecommitInterval
|
||||||
}
|
}
|
||||||
|
|
||||||
go worker.mainLoop()
|
go worker.mainLoop()
|
||||||
go worker.newWorkLoop(recommitInterval)
|
go worker.newWorkLoop(recommit)
|
||||||
go worker.resultLoop()
|
go worker.resultLoop()
|
||||||
go worker.taskLoop()
|
go worker.taskLoop()
|
||||||
|
|
||||||
|
|
@ -276,92 +276,92 @@ func (w *worker) close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newWorkLoop is a standalone goroutine to submit new mining work upon received events.
|
// newWorkLoop is a standalone goroutine to submit new mining work upon received events.
|
||||||
func (w *worker) newWorkLoop(recommitInterval time.Duration) {
|
func (w *worker) newWorkLoop(recommit time.Duration) {
|
||||||
var (
|
var (
|
||||||
interrupt *int32
|
interrupt *int32
|
||||||
minInterval = recommitInterval // minimal resubmit interval specified by user.
|
minRecommit = recommit // minimal resubmit interval specified by user.
|
||||||
)
|
)
|
||||||
|
|
||||||
timer := time.NewTimer(0)
|
timer := time.NewTimer(0)
|
||||||
<-timer.C // discard the initial tick
|
<-timer.C // discard the initial tick
|
||||||
|
|
||||||
// recommit aborts in-flight transaction execution with given signal and resubmits a new one.
|
// commit aborts in-flight transaction execution with given signal and resubmits a new one.
|
||||||
recommit := func(noempty bool, s int32) {
|
commit := func(noempty bool, s int32) {
|
||||||
if interrupt != nil {
|
if interrupt != nil {
|
||||||
atomic.StoreInt32(interrupt, s)
|
atomic.StoreInt32(interrupt, s)
|
||||||
}
|
}
|
||||||
interrupt = new(int32)
|
interrupt = new(int32)
|
||||||
w.newWorkCh <- &newWorkReq{interrupt: interrupt, noempty: noempty}
|
w.newWorkCh <- &newWorkReq{interrupt: interrupt, noempty: noempty}
|
||||||
timer.Reset(recommitInterval)
|
timer.Reset(recommit)
|
||||||
}
|
}
|
||||||
// recalcuInterval recalculates the resubmitting interval upon feedback.
|
// recalcRecommit recalculates the resubmitting interval upon feedback.
|
||||||
recalcuInterval := func(target float64, inc bool) {
|
recalcRecommit := func(target float64, inc bool) {
|
||||||
var (
|
var (
|
||||||
old = float64(recommitInterval.Nanoseconds())
|
prev = float64(recommit.Nanoseconds())
|
||||||
new float64
|
next float64
|
||||||
)
|
)
|
||||||
if inc {
|
if inc {
|
||||||
new = old*(1-intervalAdjustRatio) + intervalAdjustRatio*(target+intervalAdjustBias)
|
next = prev*(1-intervalAdjustRatio) + intervalAdjustRatio*(target+intervalAdjustBias)
|
||||||
// Recap if interval is larger than the maximum time interval
|
// Recap if interval is larger than the maximum time interval
|
||||||
if new > float64(maxRecommitInterval.Nanoseconds()) {
|
if next > float64(maxRecommitInterval.Nanoseconds()) {
|
||||||
new = float64(maxRecommitInterval.Nanoseconds())
|
next = float64(maxRecommitInterval.Nanoseconds())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Short circuit if the interval not larger than the minimal interval specified by user.
|
// Short circuit if the interval not larger than the minimal interval specified by user.
|
||||||
if recommitInterval <= minInterval {
|
if recommit <= minRecommit {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
new = old*(1-intervalAdjustRatio) + intervalAdjustRatio*(target-intervalAdjustBias)
|
next = prev*(1-intervalAdjustRatio) + intervalAdjustRatio*(target-intervalAdjustBias)
|
||||||
// Recap if interval is less than the user specified minimum
|
// Recap if interval is less than the user specified minimum
|
||||||
if new < float64(minInterval.Nanoseconds()) {
|
if next < float64(minRecommit.Nanoseconds()) {
|
||||||
new = float64(minInterval.Nanoseconds())
|
next = float64(minRecommit.Nanoseconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recommitInterval = time.Duration(int64(new))
|
recommit = time.Duration(int64(next))
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-w.startCh:
|
case <-w.startCh:
|
||||||
recommit(false, commitInterruptNewHead)
|
commit(false, commitInterruptNewHead)
|
||||||
|
|
||||||
case <-w.chainHeadCh:
|
case <-w.chainHeadCh:
|
||||||
recommit(false, commitInterruptNewHead)
|
commit(false, commitInterruptNewHead)
|
||||||
|
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
// If mining is running resubmit a new work cycle periodically to pull in
|
// If mining is running resubmit a new work cycle periodically to pull in
|
||||||
// higher priced transactions. Disable this overhead for pending blocks.
|
// higher priced transactions. Disable this overhead for pending blocks.
|
||||||
if w.isRunning() && (w.config.Clique == nil || w.config.Clique.Period > 0) {
|
if w.isRunning() && (w.config.Clique == nil || w.config.Clique.Period > 0) {
|
||||||
recommit(true, commitInterruptResubmit)
|
commit(true, commitInterruptResubmit)
|
||||||
}
|
}
|
||||||
|
|
||||||
case interval := <-w.resubmitIntervalCh:
|
case interval := <-w.resubmitIntervalCh:
|
||||||
// Adjust resubmit interval explicitly by user.
|
// Adjust resubmit interval explicitly by user.
|
||||||
if interval < minRecommitInterval {
|
if interval < minRecommitInterval {
|
||||||
log.Info("Recap miner recommit interval", "from", interval, "to", minRecommitInterval)
|
log.Warn("Sanitizing miner recommit interval", "provided", interval, "updated", minRecommitInterval)
|
||||||
interval = minRecommitInterval
|
interval = minRecommitInterval
|
||||||
}
|
}
|
||||||
log.Info("Miner recommit interval update", "from", minInterval, "to", interval)
|
log.Info("Miner recommit interval update", "from", minRecommit, "to", interval)
|
||||||
minInterval, recommitInterval = interval, interval
|
minRecommit, recommit = interval, interval
|
||||||
|
|
||||||
if w.resubmitHook != nil {
|
if w.resubmitHook != nil {
|
||||||
w.resubmitHook(minInterval, recommitInterval)
|
w.resubmitHook(minRecommit, recommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
case adjust := <-w.resubmitAdjustCh:
|
case adjust := <-w.resubmitAdjustCh:
|
||||||
// Adjust resubmit interval by feedback.
|
// Adjust resubmit interval by feedback.
|
||||||
if adjust.inc {
|
if adjust.inc {
|
||||||
before := recommitInterval
|
before := recommit
|
||||||
recalcuInterval(float64(recommitInterval.Nanoseconds())/adjust.ratio, true)
|
recalcRecommit(float64(recommit.Nanoseconds())/adjust.ratio, true)
|
||||||
log.Trace("Increase miner recommit interval", "from", before, "to", recommitInterval)
|
log.Trace("Increase miner recommit interval", "from", before, "to", recommit)
|
||||||
} else {
|
} else {
|
||||||
before := recommitInterval
|
before := recommit
|
||||||
recalcuInterval(float64(minInterval.Nanoseconds()), false)
|
recalcRecommit(float64(minRecommit.Nanoseconds()), false)
|
||||||
log.Trace("Decrease miner recommit interval", "from", before, "to", recommitInterval)
|
log.Trace("Decrease miner recommit interval", "from", before, "to", recommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.resubmitHook != nil {
|
if w.resubmitHook != nil {
|
||||||
w.resubmitHook(minInterval, recommitInterval)
|
w.resubmitHook(minRecommit, recommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-w.exitCh:
|
case <-w.exitCh:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue