aboutsummaryrefslogtreecommitdiff
path: root/miner
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
parent485da638c7b3ecd2e23299252848d99258fb6727 (diff)
allow manual block generation
Diffstat (limited to 'miner')
-rw-r--r--miner/miner.go23
-rw-r--r--miner/worker.go22
2 files changed, 38 insertions, 7 deletions
diff --git a/miner/miner.go b/miner/miner.go
index 969dceb..4e36fed 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -20,6 +20,7 @@ package miner
import (
"fmt"
"time"
+ "math/big"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
@@ -27,8 +28,8 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state"
- eminer "github.com/ethereum/go-ethereum/miner"
)
// Backend wraps all methods required for mining.
@@ -38,15 +39,25 @@ type Backend interface {
}
// Config is the configuration parameters of mining.
-type Config = eminer.Config
+type Config struct {
+ Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
+ Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
+ ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
+ GasFloor uint64 // Target gas floor for mined blocks.
+ GasCeil uint64 // Target gas ceiling for mined blocks.
+ GasPrice *big.Int // Minimum gas price for mining a transaction
+ Recommit time.Duration // The time interval for miner to re-create mining work.
+ Noverify bool // Disable remote mining solution verification(only useful in ethash).
+ ManualMining bool
+}
type Miner struct {
w *worker
}
-func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool) *Miner {
+func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool, manualMining bool) *Miner {
return &Miner {
- w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock),
+ w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock, manualMining),
}
}
@@ -91,3 +102,7 @@ func (self *Miner) PendingBlock() *types.Block {
func (self *Miner) SetEtherbase(addr common.Address) {
self.w.setEtherbase(addr)
}
+
+func (self *Miner) GenBlock() {
+ self.w.genBlock()
+}
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