miner: retry immediately when block building is interrupted with remaining txs

This commit is contained in:
jonny rhea 2026-02-13 09:10:59 -06:00
parent ece2b19ac0
commit f2e8985c88
2 changed files with 32 additions and 16 deletions

View file

@ -254,6 +254,13 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs, witness bool) (*Payload
for { for {
select { select {
case <-timer.C: case <-timer.C:
// Select is random, so we need to check if the payload has been stopped
select {
case <-payload.stop:
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
return
default:
}
start := time.Now() start := time.Now()
r := miner.generateWork(fullParams, witness) r := miner.generateWork(fullParams, witness)
if r.err == nil { if r.err == nil {
@ -261,7 +268,12 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs, witness bool) (*Payload
} else { } else {
log.Info("Error while generating work", "id", payload.id, "err", r.err) log.Info("Error while generating work", "id", payload.id, "err", r.err)
} }
timer.Reset(miner.config.Recommit) if r.interrupted {
// Retry immediately bc there are more txs to include.
timer.Reset(0)
} else {
timer.Reset(miner.config.Recommit)
}
case <-payload.stop: case <-payload.stop:
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery") log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
return return

View file

@ -92,14 +92,15 @@ const maxBlockSizeBufferZone = 1_000_000
// newPayloadResult is the result of payload generation. // newPayloadResult is the result of payload generation.
type newPayloadResult struct { type newPayloadResult struct {
err error err error
block *types.Block block *types.Block
fees *big.Int // total block fees fees *big.Int // total block fees
sidecars []*types.BlobTxSidecar // collected blobs of blob transactions sidecars []*types.BlobTxSidecar // collected blobs of blob transactions
stateDB *state.StateDB // StateDB after executing the transactions stateDB *state.StateDB // StateDB after executing the transactions
receipts []*types.Receipt // Receipts collected during construction receipts []*types.Receipt // Receipts collected during construction
requests [][]byte // Consensus layer requests collected during block construction requests [][]byte // Consensus layer requests collected during block construction
witness *stateless.Witness // Witness is an optional stateless proof witness *stateless.Witness // Witness is an optional stateless proof
interrupted bool // true if fillTransactions was interrupted before finishing
} }
// generateParams wraps various settings for generating sealing task. // generateParams wraps various settings for generating sealing task.
@ -131,6 +132,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
// Also add size of withdrawals to work block size. // Also add size of withdrawals to work block size.
work.size += uint64(genParam.withdrawals.Size()) work.size += uint64(genParam.withdrawals.Size())
var interrupted bool
if !genParam.noTxs { if !genParam.noTxs {
interrupt := new(atomic.Int32) interrupt := new(atomic.Int32)
timer := time.AfterFunc(miner.config.Recommit, func() { timer := time.AfterFunc(miner.config.Recommit, func() {
@ -141,6 +143,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
err := miner.fillTransactions(interrupt, work) err := miner.fillTransactions(interrupt, work)
if errors.Is(err, errBlockInterruptedByTimeout) { if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit)) log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit))
interrupted = true
} }
} }
body := types.Body{Transactions: work.txs, Withdrawals: genParam.withdrawals} body := types.Body{Transactions: work.txs, Withdrawals: genParam.withdrawals}
@ -177,13 +180,14 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
return &newPayloadResult{err: err} return &newPayloadResult{err: err}
} }
return &newPayloadResult{ return &newPayloadResult{
block: block, block: block,
fees: totalFees(block, work.receipts), fees: totalFees(block, work.receipts),
sidecars: work.sidecars, sidecars: work.sidecars,
stateDB: work.state, stateDB: work.state,
receipts: work.receipts, receipts: work.receipts,
requests: requests, requests: requests,
witness: work.witness, witness: work.witness,
interrupted: interrupted,
} }
} }