diff options
author | Determinant <[email protected]> | 2019-08-14 23:55:12 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2019-08-14 23:55:12 -0400 |
commit | 03513e267d25b5086b3f905b6d1bc5635fcda845 (patch) | |
tree | d2c800a6d04f7def64b4061ceb97f5faa13cf8ea /miner | |
parent | 63fc17f85121f84d597742a49b99ab3d022aa6bd (diff) |
...
Diffstat (limited to 'miner')
-rw-r--r-- | miner/miner.go | 5 | ||||
-rw-r--r-- | miner/worker.go | 20 |
2 files changed, 18 insertions, 7 deletions
diff --git a/miner/miner.go b/miner/miner.go index 4e36fed..53a37b0 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -49,15 +49,16 @@ type Config struct { 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 + ManualUncle 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, manualMining bool) *Miner { +func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool) *Miner { return &Miner { - w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock, manualMining), + w: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock), } } diff --git a/miner/worker.go b/miner/worker.go index cb0ec7b..c1a82ce 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -181,9 +181,10 @@ type worker struct { 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 + manualUncle bool } -func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool, manualMining bool) *worker { +func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker { worker := &worker{ config: config, chainConfig: chainConfig, @@ -206,7 +207,8 @@ 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, + manualMining: config.ManualMining, + manualUncle: config.ManualUncle, } // Subscribe NewTxsEvent for tx pool worker.txsSub = eth.TxPool().SubscribeNewTxsEvent(worker.txsCh) @@ -361,6 +363,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { clearPending(w.chain.CurrentBlock().NumberU64()) timestamp = time.Now().Unix() if !w.manualMining { + log.Warn("commit ch") commit(false, commitInterruptNewHead) } @@ -368,6 +371,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { clearPending(head.Block.NumberU64()) timestamp = time.Now().Unix() if !w.manualMining { + log.Warn("commit update") commit(false, commitInterruptNewHead) } @@ -380,6 +384,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { timer.Reset(recommit) continue } + log.Warn("commit resubmit") commit(true, commitInterruptResubmit) } @@ -445,7 +450,8 @@ func (w *worker) mainLoop() { } // If our mining block contains less than 2 uncle blocks, // add the new uncle block if valid and regenerate a mining block. - if w.isRunning() && w.current != nil && w.current.uncles.Cardinality() < 2 { + if w.isRunning() && w.current != nil && w.current.uncles.Cardinality() < 2 && !w.manualUncle { + log.Warn("wtf") start := time.Now() if err := w.commitUncle(w.current, ev.Block.Header()); err == nil { var uncles []*types.Header @@ -611,7 +617,9 @@ func (w *worker) resultLoop() { logs = append(logs, receipt.Logs...) } // Commit block and state to database. + //fmt.Printf("parent1: %s\n", w.chain.CurrentBlock().Hash().String()) stat, err := w.chain.WriteBlockWithState(block, receipts, task.state) + //fmt.Printf("parent2: %s\n", w.chain.CurrentBlock().Hash().String()) if err != nil { log.Error("Failed writing block to chain", "err", err) continue @@ -938,9 +946,10 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) commitUncles(w.localUncles) commitUncles(w.remoteUncles) - if !noempty { + if !noempty && !w.manualUncle { // Create an empty block based on temporary copied state for sealing in advance without waiting block // execution finished. + log.Warn("commit n1") w.commit(uncles, nil, false, tstart) } @@ -951,7 +960,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) return } // Short circuit if there is no available pending transactions - if len(pending) == 0 { + if len(pending) == 0 && !w.manualMining { w.updateSnapshot() return } @@ -975,6 +984,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) return } } + log.Warn("commit n2") w.commit(uncles, w.fullTaskHook, true, tstart) } |