Skip to content

Commit

Permalink
feat: replace getPayload with getMinimizedPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
Troublor committed Oct 24, 2024
1 parent 41c8e77 commit 6063f3e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 5 deletions.
2 changes: 1 addition & 1 deletion op-node/rollup/engine/build_cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (eq *EngDeriver) onBuildCancel(ev BuildCancelEvent) {
defer cancel()
// the building job gets wrapped up as soon as the payload is retrieved, there's no explicit cancel in the Engine API
eq.log.Warn("cancelling old block building job", "info", ev.Info)
_, err := eq.ec.engine.GetPayload(ctx, ev.Info)
_, err := eq.ec.engine.GetMinimizedPayload(ctx, ev.Info)
if err != nil {
if x, ok := err.(eth.InputError); ok && x.Code == eth.UnknownPayload { //nolint:all
return // if unknown, then it did not need to be cancelled anymore.
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/engine/build_seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (eq *EngDeriver) onBuildSeal(ev BuildSealEvent) {
defer cancel()

sealingStart := time.Now()
envelope, err := eq.ec.engine.GetPayload(ctx, ev.Info)
envelope, err := eq.ec.engine.GetMinimizedPayload(ctx, ev.Info)
if err != nil {
if x, ok := err.(eth.InputError); ok && x.Code == eth.UnknownPayload { //nolint:all
eq.log.Warn("Cannot seal block, payload ID is unknown",
Expand Down
1 change: 1 addition & 0 deletions op-node/rollup/engine/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var ErrNoFCUNeeded = errors.New("no FCU call was needed")

type ExecEngine interface {
GetPayload(ctx context.Context, payloadInfo eth.PayloadInfo) (*eth.ExecutionPayloadEnvelope, error)
GetMinimizedPayload(ctx context.Context, payloadInfo eth.PayloadInfo) (*eth.ExecutionPayloadEnvelope, error)
ForkchoiceUpdate(ctx context.Context, state *eth.ForkchoiceState, attr *eth.PayloadAttributes) (*eth.ForkchoiceUpdatedResult, error)
NewPayload(ctx context.Context, payload *eth.ExecutionPayload, parentBeaconBlockRoot *common.Hash) (*eth.PayloadStatusV1, error)
NewPayloadWithPayloadId(ctx context.Context, payloadInfo eth.PayloadInfo, parentBeaconBlockRoot *common.Hash) (*eth.PayloadStatusV1, error)
Expand Down
2 changes: 1 addition & 1 deletion op-node/rollup/engine/payload_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (ev PayloadProcessEvent) String() string {
func (eq *EngDeriver) onPayloadProcess(ev PayloadProcessEvent) {
ctx, cancel := context.WithTimeout(eq.ctx, payloadProcessTimeout)
defer cancel()
eq.log.Info("payload-process, NewPayloadWithPayloadId, payload info:", ev.Info)
eq.log.Debug("payload-process, NewPayloadWithPayloadId, payload info:", "info", ev.Info)
status, err := eq.ec.engine.NewPayloadWithPayloadId(ctx,
ev.Info, ev.Envelope.ParentBeaconBlockRoot)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions op-node/rollup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ func (c *Config) NewPayloadVersion(timestamp uint64) eth.EngineAPIMethod {
}
}

// NewPayloadByIdVersion returns the EngineAPIMethod suitable for the chain hard fork version.
func (c *Config) NewPayloadByIdVersion(timestamp uint64) eth.EngineAPIMethod {
if c.IsEcotone(timestamp) {
// Cancun
return eth.NewPayloadV3ById
} else {
panic("Unsupported Engine API version")
}
}

// GetPayloadVersion returns the EngineAPIMethod suitable for the chain hard fork version.
func (c *Config) GetPayloadVersion(timestamp uint64) eth.EngineAPIMethod {
if c.IsEcotone(timestamp) {
Expand All @@ -503,6 +513,16 @@ func (c *Config) GetPayloadVersion(timestamp uint64) eth.EngineAPIMethod {
}
}

// GetMinimizedPayloadVersion returns the EngineAPIMethod suitable for the chain hard fork version.
func (c *Config) GetMinimizedPayloadVersion(timestamp uint64) eth.EngineAPIMethod {
if c.IsEcotone(timestamp) {
// Cancun
return eth.GetMinimizedPayloadV3
} else {
return eth.GetPayloadV2
}
}

// GetOPAltDAConfig validates and returns the altDA config from the rollup config.
func (c *Config) GetOPAltDAConfig() (altda.Config, error) {
if c.AltDAConfig == nil {
Expand Down
3 changes: 2 additions & 1 deletion op-service/eth/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ const (
NewPayloadV2 EngineAPIMethod = "engine_newPayloadV2"
NewPayloadV3 EngineAPIMethod = "engine_newPayloadV3"

NewPayloadV3ById EngineAPIMethod = "engine_newPayloadV3ById"
NewPayloadV3ById EngineAPIMethod = "engine_newPayloadV3ById"
GetMinimizedPayloadV3 EngineAPIMethod = "engine_getMinimizedPayloadV3"

GetPayloadV2 EngineAPIMethod = "engine_getPayloadV2"
GetPayloadV3 EngineAPIMethod = "engine_getPayloadV3"
Expand Down
35 changes: 34 additions & 1 deletion op-service/sources/engine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ type EngineAPIClient struct {
type EngineVersionProvider interface {
ForkchoiceUpdatedVersion(attr *eth.PayloadAttributes) eth.EngineAPIMethod
NewPayloadVersion(timestamp uint64) eth.EngineAPIMethod
NewPayloadByIdVersion(timestamp uint64) eth.EngineAPIMethod
GetPayloadVersion(timestamp uint64) eth.EngineAPIMethod
GetMinimizedPayloadVersion(timestamp uint64) eth.EngineAPIMethod
}

func NewEngineAPIClient(rpc client.RPC, l log.Logger, evp EngineVersionProvider) *EngineAPIClient {
Expand Down Expand Up @@ -153,7 +155,8 @@ func (s *EngineAPIClient) NewPayloadWithPayloadId(ctx context.Context, payloadIn
defer cancel()
var result eth.PayloadStatusV1

var err = s.RPC.CallContext(execCtx, &result, string(eth.NewPayloadV3ById), payloadInfo.ID, []common.Hash{}, parentBeaconBlockRoot)
method := s.evp.NewPayloadByIdVersion(payloadInfo.Timestamp)
var err = s.RPC.CallContext(execCtx, &result, string(method), payloadInfo.ID)

e.Trace("Received payload execution result", "status", result.Status, "latestValidHash", result.LatestValidHash, "message", result.ValidationError)
if err != nil {
Expand Down Expand Up @@ -193,6 +196,36 @@ func (s *EngineAPIClient) GetPayload(ctx context.Context, payloadInfo eth.Payloa
return &result, nil
}

// GetMinimizedPayload gets the execution payload associated with the PayloadId while pruning the body (i.e., transactions) of the payload except for the first trasaction.
// There may be two types of error:
// 1. `error` as eth.InputError: the payload ID may be unknown
// 2. Other types of `error`: temporary RPC errors, like timeouts.
func (s *EngineAPIClient) GetMinimizedPayload(ctx context.Context, payloadInfo eth.PayloadInfo) (*eth.ExecutionPayloadEnvelope, error) {
e := s.log.New("payload_id", payloadInfo.ID)
e.Trace("getting minimized payload")
var result eth.ExecutionPayloadEnvelope
method := s.evp.GetMinimizedPayloadVersion(payloadInfo.Timestamp)
err := s.RPC.CallContext(ctx, &result, string(method), payloadInfo.ID)
if err != nil {
e.Warn("Failed to get minimized payload", "payload_id", payloadInfo.ID, "err", err)
if rpcErr, ok := err.(rpc.Error); ok {
code := eth.ErrorCode(rpcErr.ErrorCode())
switch code {
case eth.UnknownPayload:
return nil, eth.InputError{
Inner: err,
Code: code,
}
default:
return nil, fmt.Errorf("unrecognized rpc error: %w", err)
}
}
return nil, err
}
e.Trace("Received payload", string(eth.GetMinimizedPayloadV3), *result.ExecutionPayload)
return &result, nil
}

func (s *EngineAPIClient) SignalSuperchainV1(ctx context.Context, recommended, required params.ProtocolVersion) (params.ProtocolVersion, error) {
var result params.ProtocolVersion
err := s.RPC.CallContext(ctx, &result, "engine_signalSuperchainV1", &catalyst.SuperchainSignal{
Expand Down
22 changes: 22 additions & 0 deletions op-wheel/engine/version_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ func (v StaticVersionProvider) NewPayloadVersion(uint64) eth.EngineAPIMethod {
}
}

func (v StaticVersionProvider) NewPayloadByIdVersion(uint64) eth.EngineAPIMethod {
switch int(v) {
case 1, 2:
panic("Unsupported Engine API version: " + strconv.Itoa(int(v)))
case 3:
return eth.NewPayloadV3
default:
panic("invalid Engine API version: " + strconv.Itoa(int(v)))
}
}

func (v StaticVersionProvider) GetPayloadVersion(uint64) eth.EngineAPIMethod {
switch int(v) {
case 1, 2:
Expand All @@ -42,3 +53,14 @@ func (v StaticVersionProvider) GetPayloadVersion(uint64) eth.EngineAPIMethod {
panic("invalid Engine API version: " + strconv.Itoa(int(v)))
}
}

func (v StaticVersionProvider) GetMinimizedPayloadVersion(uint64) eth.EngineAPIMethod {
switch int(v) {
case 1, 2:
return eth.GetPayloadV2
case 3:
return eth.GetMinimizedPayloadV3
default:
panic("invalid Engine API version: " + strconv.Itoa(int(v)))
}
}

0 comments on commit 6063f3e

Please sign in to comment.