payload_process.go 1.97 KB
Newer Older
1 2 3 4 5
package engine

import (
	"context"
	"fmt"
6
	"time"
7 8 9 10 11 12

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

type PayloadProcessEvent struct {
13 14
	// if payload should be promoted to (local) safe (must also be pending safe, see DerivedFrom)
	Concluding bool
15
	// payload is promoted to pending-safe if non-zero
16 17
	DerivedFrom  eth.L1BlockRef
	BuildStarted time.Time
18 19 20 21 22 23 24 25 26 27 28 29 30

	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()

31
	insertStart := time.Now()
32 33 34 35
	status, err := eq.ec.engine.NewPayload(ctx,
		ev.Envelope.ExecutionPayload, ev.Envelope.ParentBeaconBlockRoot)
	if err != nil {
		eq.emitter.Emit(rollup.EngineTemporaryErrorEvent{
36 37
			Err: fmt.Errorf("failed to insert execution payload: %w", err),
		})
38 39 40 41
		return
	}
	switch status.Status {
	case eth.ExecutionInvalid, eth.ExecutionInvalidBlockHash:
42 43 44 45 46 47 48
		// 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
		}

49 50
		eq.emitter.Emit(PayloadInvalidEvent{
			Envelope: ev.Envelope,
51 52
			Err:      eth.NewPayloadErr(ev.Envelope.ExecutionPayload, status),
		})
53 54
		return
	case eth.ExecutionValid:
55 56 57 58 59 60 61 62
		eq.emitter.Emit(PayloadSuccessEvent{
			Concluding:    ev.Concluding,
			DerivedFrom:   ev.DerivedFrom,
			BuildStarted:  ev.BuildStarted,
			InsertStarted: insertStart,
			Envelope:      ev.Envelope,
			Ref:           ev.Ref,
		})
63 64 65
		return
	default:
		eq.emitter.Emit(rollup.EngineTemporaryErrorEvent{
66 67
			Err: eth.NewPayloadErr(ev.Envelope.ExecutionPayload, status),
		})
68 69 70
		return
	}
}