powWorker¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | miner/worker.go |
worker_pow.go |
| Symbol | worker |
powWorker |
| Ref | dde2da0ef~1 |
etc/v1.17.3-full-node |
PoW mining worker with 4 goroutine loops: newWorkLoop (triggers work on timer/chainHead), mainLoop (processes work requests, tx events and side-block uncle candidates), taskLoop (calls engine.Seal, with test hooks), resultLoop (inserts sealed blocks and broadcasts). DELIBERATELY a fork reimplementation, NOT a byte-for-byte transplant of the pre-purge miner/worker.go. A full transplant was evaluated and rejected: the low-level block-building the pre-purge worker owns (ApplyTransaction, vm.NewEVM, txpool.Pending, FinalizeAndAssemble) is exactly what drifts most between upstream releases — roughly 40% of the worker would be forced API adaptation rather than literal revival, and the central
worker/environmenttypes collide with the modern miner/worker.go the fork keeps for upstream payloads. Decision (hybrid): delegate block-building to the modern Miner (prepareWork / fillTransactions / AssembleBlock — stable across rebases) and revive faithfully ONLY the battle-tested, drift-free uncle logic (operating on stable Header/Hash types) in miner/uncles_pow.go. That is why this entry's body diverges heavily from the pre-purge worker while uncleEnv/newUncleEnv/gatherUncles below ARE faithful revivals.
3-way merge — purge → getc ← upstream¶
core-geth validation — +35 -64
| | | |---|---| | File | [`worker.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/miner/worker.go) | | Symbol | `worker` | | Ref | `v1.12.20` |--- a/core-geth/miner/worker.go
+++ b/etc/miner/worker_pow.go
@@ -1,83 +1,54 @@
-// worker is the main object which takes care of submitting new work to consensus engine
-// and gathering the sealing result.
-type worker struct {
- config *Config
- chainConfig ctypes.ChainConfigurator
+// powWorker is the PoW mining worker that runs the sealing loops.
+// It wraps the existing Miner's block-building functions and adds
+// the active mining loops removed in upstream's purge3.
+type powWorker struct {
+ miner *Miner
engine consensus.Engine
- eth Backend
chain *core.BlockChain
-
- // Feeds
- pendingLogsFeed event.Feed
-
- // Subscriptions
+ txpool *txpool.TxPool
mux *event.TypeMux
- txsCh chan core.NewTxsEvent
- txsSub event.Subscription
- chainHeadCh chan core.ChainHeadEvent
- chainHeadSub event.Subscription
- chainSideCh chan core.ChainSideEvent
- chainSideSub event.Subscription
// Channels
newWorkCh chan *newWorkReq
- getWorkCh chan *getWorkReq
taskCh chan *task
resultCh chan *types.Block
startCh chan struct{}
exitCh chan struct{}
resubmitIntervalCh chan time.Duration
- resubmitAdjustCh chan *intervalAdjust
-
- wg sync.WaitGroup
+ uncleRecommitCh chan struct{} // signals newWorkLoop to regenerate work when a fresh uncle arrives
- 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.
- unconfirmed *unconfirmedBlocks // A set of locally mined blocks pending canonicalness confirmations.
+ // Subscriptions
+ txsCh chan core.NewTxsEvent
+ txsSub event.Subscription
+ chainHeadCh chan core.ChainHeadEvent
+ chainHeadSub event.Subscription
+ chainSideCh chan core.ChainSideEvent
+ chainSideSub event.Subscription
- mu sync.RWMutex // The lock used to protect the coinbase and extra fields
+ // Uncle candidates sourced from the fork-choice side-block feed. Accessed
+ // only from mainLoop (single goroutine), so they need no extra locking.
+ localUncles map[common.Hash]*types.Header
+ remoteUncles map[common.Hash]*types.Header
+
+ // Test hooks (nil in production) that let worker_test.go drive the sealing
+ // loops deterministically.
+ newTaskHook func(*task)
+ skipSealHook func(*task) bool
+ fullTaskHook func()
+
+ // State
+ running atomic.Bool
+ newTxs atomic.Int32
+ syncing atomic.Bool
coinbase common.Address
- extra []byte
- tip *uint256.Int // Minimum tip needed for non-local transaction to include them
+ mu sync.RWMutex // protects coinbase
+ // Pending tasks for seal result correlation
pendingMu sync.RWMutex
pendingTasks map[common.Hash]*task
- snapshotMu sync.RWMutex // The lock used to protect the snapshots below
- snapshotBlock *types.Block
- snapshotReceipts types.Receipts
- snapshotState *state.StateDB
-
- // atomic status counters
- running atomic.Bool // The indicator whether the consensus engine is running or not.
- newTxs atomic.Int32 // New arrival transaction count since last sealing work submitting.
- syncing atomic.Bool // The indicator whether the node is still syncing.
-
- // noempty is the flag used to control whether the feature of pre-seal empty
- // block is enabled. The default value is false(pre-seal is enabled by default).
- // But in some special scenario the consensus engine will seal blocks instantaneously,
- // in this case this feature will add all empty blocks into canonical chain
- // non-stop and no real transaction will be included.
- noempty atomic.Bool
-
- // newpayloadTimeout is the maximum timeout allowance for creating payload.
- // The default value is 2 seconds but node operator can set it to arbitrary
- // large value. A large timeout allowance may cause Geth to fail creating
- // a non-empty payload within the specified time and eventually miss the slot
- // in case there are some computation expensive transactions in txpool.
- newpayloadTimeout time.Duration
-
- // recommit is the time interval to re-create sealing work or to re-build
- // payload in proof-of-stake stage.
- recommit time.Duration
-
- // External functions
- isLocalBlock func(header *types.Header) bool // Function used to determine whether the specified block is mined by local miner.
-
- // Test hooks
- newTaskHook func(*task) // Method to call upon receiving a new sealing task.
- 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.
+ // Block tracking
+ unconfirmed *unconfirmedBlocks
+
+ wg sync.WaitGroup
}