aboutsummaryrefslogtreecommitdiff
path: root/miner/worker.go
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-08-14 15:19:28 -0400
committerDeterminant <[email protected]>2019-08-14 15:19:28 -0400
commit499f682b48f914ed4af0e32ba446dd0cf56e96b4 (patch)
tree62bbe47ce4f1de674fbca9c16709c98e729b08ec /miner/worker.go
parent485da638c7b3ecd2e23299252848d99258fb6727 (diff)
allow manual block generation
Diffstat (limited to 'miner/worker.go')
-rw-r--r--miner/worker.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/miner/worker.go b/miner/worker.go
index b5448d3..5124758 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -180,9 +180,10 @@ type worker struct {
skipSealHook func(*task) bool // Method to decide whether skipping the sealing.
fullTaskHook func() // Method to call before pushing the full sealing task.
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
+ manualMining bool
}
-func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker {
+func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool, manualMining bool) *worker {
worker := &worker{
config: config,
chainConfig: chainConfig,
@@ -205,6 +206,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
startCh: make(chan struct{}, 1),
resubmitIntervalCh: make(chan time.Duration),
resubmitAdjustCh: make(chan *intervalAdjust, resubmitAdjustChanSize),
+ manualMining: manualMining,
}
// Subscribe NewTxsEvent for tx pool
worker.txsSub = eth.TxPool().SubscribeNewTxsEvent(worker.txsCh)
@@ -290,6 +292,16 @@ func (w *worker) close() {
close(w.exitCh)
}
+func (w *worker) genBlock() {
+ interrupt := new(int32)
+ *interrupt = commitInterruptNewHead
+ w.newWorkCh <- &newWorkReq{
+ interrupt: interrupt,
+ noempty: false,
+ timestamp: time.Now().Unix(),
+ }
+}
+
// newWorkLoop is a standalone goroutine to submit new mining work upon received events.
func (w *worker) newWorkLoop(recommit time.Duration) {
var (
@@ -348,12 +360,16 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
case <-w.startCh:
clearPending(w.chain.CurrentBlock().NumberU64())
timestamp = time.Now().Unix()
- commit(false, commitInterruptNewHead)
+ if !w.manualMining {
+ commit(false, commitInterruptNewHead)
+ }
case head := <-w.chainHeadCh:
clearPending(head.Block.NumberU64())
timestamp = time.Now().Unix()
- commit(false, commitInterruptNewHead)
+ if !w.manualMining {
+ commit(false, commitInterruptNewHead)
+ }
case <-timer.C:
// If mining is running resubmit a new work cycle periodically to pull in