• Sam Stokes's avatar
    op-node: log mgasps across block building/inserting lifecycle (#12907) · 1c36df3e
    Sam Stokes authored
    * op-node: log mgasps across block processing lifecycle
    
    * op-node: add 'import_time' field to block processing log
    
    * op-node: make log message more descriptive
    
    * op-node: log legacy codepath for InsertUnsafePayload
    
    * op-node: include final ForkchoiceUpdate in block insertion time
    
    * op-node: remove unused BuildTime field from events
    
    * op-node: encapsulate log logic in TryUpdateEngineEvent methods
    
    * op-node: linter fix
    
    * op-node: add comment and adjust sync log wording
    
    * op-node: fix BlockHash, BlockNumber in log
    
    * op-node: seq add BuildStarted to PayloadProcessEvent
    
    * op-node: refactor getBlockProcessingMetrics, protect against divide-by-zero
    1c36df3e
payload_process.go 1.97 KB
package engine

import (
	"context"
	"fmt"
	"time"

	"github.com/ethereum-optimism/optimism/op-node/rollup"
	"github.com/ethereum-optimism/optimism/op-service/eth"
)

type PayloadProcessEvent struct {
	// if payload should be promoted to (local) safe (must also be pending safe, see DerivedFrom)
	Concluding bool
	// payload is promoted to pending-safe if non-zero
	DerivedFrom  eth.L1BlockRef
	BuildStarted time.Time

	Envelope *eth.ExecutionPayloadEnvelope
	Ref      eth.L2BlockRef
}

func (ev PayloadProcessEvent) String() string {
	return "payload-process"
}

func (eq *EngDeriver) onPayloadProcess(ev PayloadProcessEvent) {
	ctx, cancel := context.WithTimeout(eq.ctx, payloadProcessTimeout)
	defer cancel()

	insertStart := time.Now()
	status, err := eq.ec.engine.NewPayload(ctx,
		ev.Envelope.ExecutionPayload, ev.Envelope.ParentBeaconBlockRoot)
	if err != nil {
		eq.emitter.Emit(rollup.EngineTemporaryErrorEvent{
			Err: fmt.Errorf("failed to insert execution payload: %w", err),
		})
		return
	}
	switch status.Status {
	case eth.ExecutionInvalid, eth.ExecutionInvalidBlockHash:
		// Depending on execution engine, not all block-validity checks run immediately on build-start
		// at the time of the forkchoiceUpdated engine-API call, nor during getPayload.
		if ev.DerivedFrom != (eth.L1BlockRef{}) && eq.cfg.IsHolocene(ev.DerivedFrom.Time) {
			eq.emitDepositsOnlyPayloadAttributesRequest(ev.Ref.ParentID(), ev.DerivedFrom)
			return
		}

		eq.emitter.Emit(PayloadInvalidEvent{
			Envelope: ev.Envelope,
			Err:      eth.NewPayloadErr(ev.Envelope.ExecutionPayload, status),
		})
		return
	case eth.ExecutionValid:
		eq.emitter.Emit(PayloadSuccessEvent{
			Concluding:    ev.Concluding,
			DerivedFrom:   ev.DerivedFrom,
			BuildStarted:  ev.BuildStarted,
			InsertStarted: insertStart,
			Envelope:      ev.Envelope,
			Ref:           ev.Ref,
		})
		return
	default:
		eq.emitter.Emit(rollup.EngineTemporaryErrorEvent{
			Err: eth.NewPayloadErr(ev.Envelope.ExecutionPayload, status),
		})
		return
	}
}