|
|
|
@ -150,6 +150,8 @@ type worker struct { |
|
|
|
|
resubmitIntervalCh chan time.Duration |
|
|
|
|
resubmitAdjustCh chan *intervalAdjust |
|
|
|
|
|
|
|
|
|
wg sync.WaitGroup |
|
|
|
|
|
|
|
|
|
current *environment // An environment for current running cycle.
|
|
|
|
|
localUncles map[common.Hash]*types.Block // A set of side blocks generated locally as the possible uncle blocks.
|
|
|
|
|
remoteUncles map[common.Hash]*types.Block // A set of side blocks as the possible uncle blocks.
|
|
|
|
@ -225,6 +227,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus |
|
|
|
|
recommit = minRecommitInterval |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
worker.wg.Add(4) |
|
|
|
|
go worker.mainLoop() |
|
|
|
|
go worker.newWorkLoop(recommit) |
|
|
|
|
go worker.resultLoop() |
|
|
|
@ -323,6 +326,7 @@ func (w *worker) close() { |
|
|
|
|
} |
|
|
|
|
atomic.StoreInt32(&w.running, 0) |
|
|
|
|
close(w.exitCh) |
|
|
|
|
w.wg.Wait() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// recalcRecommit recalculates the resubmitting interval upon feedback.
|
|
|
|
@ -349,6 +353,7 @@ func recalcRecommit(minRecommit, prev time.Duration, target float64, inc bool) t |
|
|
|
|
|
|
|
|
|
// newWorkLoop is a standalone goroutine to submit new mining work upon received events.
|
|
|
|
|
func (w *worker) newWorkLoop(recommit time.Duration) { |
|
|
|
|
defer w.wg.Done() |
|
|
|
|
var ( |
|
|
|
|
interrupt *int32 |
|
|
|
|
minRecommit = recommit // minimal resubmit interval specified by user.
|
|
|
|
@ -446,6 +451,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { |
|
|
|
|
|
|
|
|
|
// mainLoop is a standalone goroutine to regenerate the sealing task based on the received event.
|
|
|
|
|
func (w *worker) mainLoop() { |
|
|
|
|
defer w.wg.Done() |
|
|
|
|
defer w.txsSub.Unsubscribe() |
|
|
|
|
defer w.chainHeadSub.Unsubscribe() |
|
|
|
|
defer w.chainSideSub.Unsubscribe() |
|
|
|
@ -548,6 +554,7 @@ func (w *worker) mainLoop() { |
|
|
|
|
// taskLoop is a standalone goroutine to fetch sealing task from the generator and
|
|
|
|
|
// push them to consensus engine.
|
|
|
|
|
func (w *worker) taskLoop() { |
|
|
|
|
defer w.wg.Done() |
|
|
|
|
var ( |
|
|
|
|
stopCh chan struct{} |
|
|
|
|
prev common.Hash |
|
|
|
@ -595,6 +602,7 @@ func (w *worker) taskLoop() { |
|
|
|
|
// resultLoop is a standalone goroutine to handle sealing result submitting
|
|
|
|
|
// and flush relative data to the database.
|
|
|
|
|
func (w *worker) resultLoop() { |
|
|
|
|
defer w.wg.Done() |
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case block := <-w.resultCh: |
|
|
|
|