Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func New(eth Backend, config *minerconfig.Config, mux *event.TypeMux, engine con
exitCh: make(chan struct{}),
startCh: make(chan struct{}),
stopCh: make(chan struct{}),
worker: newWorker(config, engine, eth, mux, false),
worker: newWorker(config, engine, eth, mux),
}

miner.bidSimulator = newBidSimulator(&config.Mev, config.DelayLeftOver, config.GasPrice, eth, eth.BlockChain().Config(), engine, miner.worker)
Expand Down
42 changes: 16 additions & 26 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const (
// staleThreshold is the maximum depth of the acceptable stale block.
staleThreshold = 11

// the current 4 mining loops could have asynchronous risk of mining block with
// save height, keep recently mined blocks to avoid double sign for safety,
// the current mining loops could have asynchronous risk of mining block with
// same height, keep recently mined blocks to avoid double sign for safety,
recentMinedCacheLimit = 20
)

Expand All @@ -79,9 +79,8 @@ var (
bestBidGasUsedGauge = metrics.NewRegisteredGauge("worker/bestBidGasUsed", nil) // MGas
bestWorkGasUsedGauge = metrics.NewRegisteredGauge("worker/bestWorkGasUsed", nil) // MGas

writeBlockTimer = metrics.NewRegisteredTimer("worker/writeblock", nil)
finalizeBlockTimer = metrics.NewRegisteredTimer("worker/finalizeblock", nil)

writeBlockTimer = metrics.NewRegisteredTimer("worker/writeblock", nil)
finalizeBlockTimer = metrics.NewRegisteredTimer("worker/finalizeblock", nil)
pendingPlainTxsTimer = metrics.NewRegisteredTimer("worker/pendingPlainTxs", nil)
pendingBlobTxsTimer = metrics.NewRegisteredTimer("worker/pendingBlobTxs", nil)

Expand Down Expand Up @@ -152,11 +151,11 @@ func (env *environment) discard() {

// task contains all information for consensus engine sealing and result submitting.
type task struct {
receipts []*types.Receipt
state *state.StateDB
block *types.Block
createdAt time.Time
receipts []*types.Receipt
state *state.StateDB
block *types.Block

createdAt time.Time
miningStartAt time.Time
}

Expand Down Expand Up @@ -250,17 +249,17 @@ type worker struct {

// recommit is the time interval to re-create sealing work or to re-build
// payload in proof-of-stake stage.
recommit time.Duration
recommit time.Duration
recentMinedBlocks *lru.Cache[uint64, []common.Hash]

// 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.
recentMinedBlocks *lru.Cache[uint64, []common.Hash]
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.
}

func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend, mux *event.TypeMux, init bool) *worker {
func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend, mux *event.TypeMux) *worker {
chainConfig := eth.BlockChain().Config()
worker := &worker{
prefetcher: core.NewStatePrefetcher(chainConfig, eth.BlockChain().HeadChain()),
Expand Down Expand Up @@ -292,10 +291,6 @@ func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend,
if worker.config.Recommit != nil && *worker.config.Recommit > minRecommitInterval {
recommit = *worker.config.Recommit
}
if recommit < minRecommitInterval {
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
recommit = minRecommitInterval
}
worker.recommit = recommit

worker.wg.Add(4)
Expand All @@ -304,11 +299,6 @@ func newWorker(config *minerconfig.Config, engine consensus.Engine, eth Backend,
go worker.resultLoop()
go worker.taskLoop()

// Submit first work to initialize pending state.
if init {
worker.startCh <- struct{}{}
}

return worker
}

Expand Down Expand Up @@ -689,7 +679,7 @@ func (w *worker) resultLoop() {
stats := w.chain.GetBlockStats(block.Hash())
stats.SendBlockTime.Store(time.Now().UnixMilli())
stats.StartMiningTime.Store(task.miningStartAt.UnixMilli())
log.Info("Successfully seal and write new block", "number", block.Number(), "sealhash", sealhash, "hash", hash,
log.Info("Successfully seal and write new block", "number", block.Number(), "hash", hash, "time", block.Header().MilliTimestamp(), "sealhash", sealhash,
"block size(noBal)", block.Size(), "balSize", block.BALSize(), "elapsed", common.PrettyDuration(time.Since(task.createdAt)))
w.mux.Post(core.NewMinedBlockEvent{Block: block})

Expand Down
2 changes: 1 addition & 1 deletion miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (b *testWorkerBackend) newRandomTx(creation bool) *types.Transaction {
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, blocks int) (*worker, *testWorkerBackend) {
backend := newTestWorkerBackend(t, chainConfig, engine, db, blocks)
backend.txPool.Add(pendingTxs, true)
w := newWorker(testConfig, engine, backend, new(event.TypeMux), false)
w := newWorker(testConfig, engine, backend, new(event.TypeMux))
w.setEtherbase(testBankAddress)
return w, backend
}
Expand Down