cmd, eth, miner: disable advance sealing if user require

This commit is contained in:
rjl493456442 2019-04-18 19:15:31 +08:00
parent 78ec90717a
commit b925f4b92c
7 changed files with 24 additions and 8 deletions

View file

@ -121,6 +121,7 @@ var (
utils.MinerLegacyExtraDataFlag, utils.MinerLegacyExtraDataFlag,
utils.MinerRecommitIntervalFlag, utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag, utils.MinerNoVerfiyFlag,
utils.MinerNoAdvanceFlag,
utils.NATFlag, utils.NATFlag,
utils.NoDiscoverFlag, utils.NoDiscoverFlag,
utils.DiscoveryV5Flag, utils.DiscoveryV5Flag,

View file

@ -203,6 +203,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.MinerExtraDataFlag, utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag, utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag, utils.MinerNoVerfiyFlag,
utils.MinerNoAdvanceFlag,
}, },
}, },
{ {

View file

@ -424,6 +424,10 @@ var (
Name: "miner.noverify", Name: "miner.noverify",
Usage: "Disable remote sealing verification", Usage: "Disable remote sealing verification",
} }
MinerNoAdvanceFlag = cli.BoolFlag{
Name: "miner.noadvance",
Usage: "Disable advance sealing on an empty block",
}
// Account settings // Account settings
UnlockedAccountFlag = cli.StringFlag{ UnlockedAccountFlag = cli.StringFlag{
Name: "unlock", Name: "unlock",
@ -1392,6 +1396,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) { if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
cfg.MinerNoverify = ctx.Bool(MinerNoVerfiyFlag.Name) cfg.MinerNoverify = ctx.Bool(MinerNoVerfiyFlag.Name)
} }
if ctx.GlobalIsSet(MinerNoAdvanceFlag.Name) {
cfg.MinerNoAdvance = ctx.Bool(MinerNoAdvanceFlag.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
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name) cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)

View file

@ -194,7 +194,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return nil, err return nil, err
} }
eth.miner = miner.New(eth, chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock) // todo(rjl493456442) wrap all setting into a single config struct
eth.miner = miner.New(eth, chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock, config.MinerNoAdvance)
eth.miner.SetExtra(makeExtraData(config.MinerExtraData)) eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil} eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil}

View file

@ -127,6 +127,7 @@ type Config struct {
MinerGasPrice *big.Int MinerGasPrice *big.Int
MinerRecommit time.Duration MinerRecommit time.Duration
MinerNoverify bool MinerNoverify bool
MinerNoAdvance bool
// Ethash options // Ethash options
Ethash ethash.Config Ethash ethash.Config

View file

@ -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, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(block *types.Block) bool) *Miner { func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(block *types.Block) bool, noAdvance bool) *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, recommit, gasFloor, gasCeil, isLocalBlock), worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil, isLocalBlock, noAdvance),
canStart: 1, canStart: 1,
} }
go miner.update() go miner.update()

View file

@ -178,7 +178,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, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool) *worker { func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool, noAdvance bool) *worker {
worker := &worker{ worker := &worker{
config: config, config: config,
engine: engine, engine: engine,
@ -216,7 +216,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
} }
go worker.mainLoop() go worker.mainLoop()
go worker.newWorkLoop(recommit) go worker.newWorkLoop(recommit, noAdvance)
go worker.resultLoop() go worker.resultLoop()
go worker.taskLoop() go worker.taskLoop()
@ -287,7 +287,7 @@ 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(recommit time.Duration) { func (w *worker) newWorkLoop(recommit time.Duration, noAdvance bool) {
var ( var (
interrupt *int32 interrupt *int32
minRecommit = recommit // minimal resubmit interval specified by user. minRecommit = recommit // minimal resubmit interval specified by user.
@ -302,6 +302,10 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
if interrupt != nil { if interrupt != nil {
atomic.StoreInt32(interrupt, s) atomic.StoreInt32(interrupt, s)
} }
// Disable advance sealing explicitly if user require.
if noAdvance {
noempty = true
}
interrupt = new(int32) interrupt = new(int32)
w.newWorkCh <- &newWorkReq{interrupt: interrupt, noempty: noempty, timestamp: timestamp} w.newWorkCh <- &newWorkReq{interrupt: interrupt, noempty: noempty, timestamp: timestamp}
timer.Reset(recommit) timer.Reset(recommit)
@ -468,9 +472,10 @@ func (w *worker) mainLoop() {
w.commitTransactions(txset, coinbase, nil) w.commitTransactions(txset, coinbase, nil)
w.updateSnapshot() w.updateSnapshot()
} else { } else {
// If we're mining, but nothing is being processed, wake on new transactions // If clique is running in dev mode(period is 0), disable
// advance sealing here.
if w.config.Clique != nil && w.config.Clique.Period == 0 { if w.config.Clique != nil && w.config.Clique.Period == 0 {
w.commitNewWork(nil, false, time.Now().Unix()) w.commitNewWork(nil, true, time.Now().Unix())
} }
} }
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs))) atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))