miner: deduplicate code

This commit is contained in:
Felix Lange 2026-03-16 18:14:46 +01:00
parent 5fe62fec5c
commit a5477289a0

View file

@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"go.opentelemetry.io/otel/trace"
) )
// BuildPayloadArgs contains the provided parameters for building payload. // BuildPayloadArgs contains the provided parameters for building payload.
@ -305,13 +306,7 @@ func (miner *Miner) buildPayload(ctx context.Context, args *BuildPayloadArgs, wi
// Check payload.stop first to avoid an unnecessary generateWork. // Check payload.stop first to avoid an unnecessary generateWork.
select { select {
case <-payload.stop: case <-payload.stop:
payload.lock.Lock() payload.updateSpanForDelivery(bSpan)
emptyDelivered := payload.full == nil
payload.lock.Unlock()
bSpan.SetAttributes(
telemetry.StringAttribute("exit.reason", "delivery"),
telemetry.BoolAttribute("empty.delivered", emptyDelivered),
)
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery") log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
return return
default: default:
@ -321,13 +316,7 @@ func (miner *Miner) buildPayload(ctx context.Context, args *BuildPayloadArgs, wi
miner.runBuildIteration(bCtx, start, iteration, payload, fullParams, witness) miner.runBuildIteration(bCtx, start, iteration, payload, fullParams, witness)
timer.Reset(max(0, miner.config.Recommit-time.Since(start))) timer.Reset(max(0, miner.config.Recommit-time.Since(start)))
case <-payload.stop: case <-payload.stop:
payload.lock.Lock() payload.updateSpanForDelivery(bSpan)
emptyDelivered := payload.full == nil
payload.lock.Unlock()
bSpan.SetAttributes(
telemetry.StringAttribute("exit.reason", "delivery"),
telemetry.BoolAttribute("empty.delivered", emptyDelivered),
)
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery") log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
return return
case <-endTimer.C: case <-endTimer.C:
@ -340,6 +329,16 @@ func (miner *Miner) buildPayload(ctx context.Context, args *BuildPayloadArgs, wi
return payload, nil return payload, nil
} }
func (p *Payload) updateSpanForDelivery(bSpan trace.Span) {
p.lock.Lock()
emptyDelivered := p.full == nil
p.lock.Unlock()
bSpan.SetAttributes(
telemetry.StringAttribute("exit.reason", "delivery"),
telemetry.BoolAttribute("empty.delivered", emptyDelivered),
)
}
// BuildTestingPayload is for testing_buildBlockV*. It creates a block with the exact content given // BuildTestingPayload is for testing_buildBlockV*. It creates a block with the exact content given
// by the parameters instead of using the locally available transactions. // by the parameters instead of using the locally available transactions.
func (miner *Miner) BuildTestingPayload(args *BuildPayloadArgs, transactions []*types.Transaction, empty bool, extraData []byte) (*engine.ExecutionPayloadEnvelope, error) { func (miner *Miner) BuildTestingPayload(args *BuildPayloadArgs, transactions []*types.Transaction, empty bool, extraData []byte) (*engine.ExecutionPayloadEnvelope, error) {