Skip to content
Closed
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
14 changes: 13 additions & 1 deletion miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,26 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs, witness bool) (*Payload
for {
select {
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()
r := miner.generateWork(fullParams, witness)
if r.err == nil {
payload.update(r, time.Since(start))
} else {
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:
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
return
Expand Down
34 changes: 19 additions & 15 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ const maxBlockSizeBufferZone = 1_000_000

// newPayloadResult is the result of payload generation.
type newPayloadResult struct {
err error
block *types.Block
fees *big.Int // total block fees
sidecars []*types.BlobTxSidecar // collected blobs of blob transactions
stateDB *state.StateDB // StateDB after executing the transactions
receipts []*types.Receipt // Receipts collected during construction
requests [][]byte // Consensus layer requests collected during block construction
witness *stateless.Witness // Witness is an optional stateless proof
err error
block *types.Block
fees *big.Int // total block fees
sidecars []*types.BlobTxSidecar // collected blobs of blob transactions
stateDB *state.StateDB // StateDB after executing the transactions
receipts []*types.Receipt // Receipts collected during construction
requests [][]byte // Consensus layer requests collected during block construction
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.
Expand Down Expand Up @@ -131,6 +132,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
// Also add size of withdrawals to work block size.
work.size += uint64(genParam.withdrawals.Size())

var interrupted bool
if !genParam.noTxs {
interrupt := new(atomic.Int32)
timer := time.AfterFunc(miner.config.Recommit, func() {
Expand All @@ -141,6 +143,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
err := miner.fillTransactions(interrupt, work)
if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit))
interrupted = true
}
}
body := types.Body{Transactions: work.txs, Withdrawals: genParam.withdrawals}
Expand Down Expand Up @@ -177,13 +180,14 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
return &newPayloadResult{err: err}
}
return &newPayloadResult{
block: block,
fees: totalFees(block, work.receipts),
sidecars: work.sidecars,
stateDB: work.state,
receipts: work.receipts,
requests: requests,
witness: work.witness,
block: block,
fees: totalFees(block, work.receipts),
sidecars: work.sidecars,
stateDB: work.state,
receipts: work.receipts,
requests: requests,
witness: work.witness,
interrupted: interrupted,
}
}

Expand Down