Skip to content

Commit 65dd758

Browse files
committed
eth/catalyst: check timestamp for compatibility in GetPayload methods
1 parent c5593ed commit 65dd758

File tree

1 file changed

+46
-60
lines changed

1 file changed

+46
-60
lines changed

eth/catalyst/api.go

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,12 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config engine.Transit
406406

407407
// GetPayloadV1 returns a cached payload by id.
408408
func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.ExecutableData, error) {
409-
if !payloadID.Is(engine.PayloadV1) {
410-
return nil, engine.UnsupportedFork
411-
}
412-
data, err := api.getPayload(payloadID, false)
409+
data, err := api.getPayload(
410+
payloadID,
411+
false,
412+
[]engine.PayloadVersion{engine.PayloadV1},
413+
nil,
414+
)
413415
if err != nil {
414416
return nil, err
415417
}
@@ -418,59 +420,34 @@ func (api *ConsensusAPI) GetPayloadV1(payloadID engine.PayloadID) (*engine.Execu
418420

419421
// GetPayloadV2 returns a cached payload by id.
420422
func (api *ConsensusAPI) GetPayloadV2(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
421-
// executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2 where:
422-
//
423-
// - ExecutionPayloadV1 MUST be returned if the payload timestamp is lower
424-
// than the Shanghai timestamp
425-
//
426-
// - ExecutionPayloadV2 MUST be returned if the payload timestamp is greater
427-
// or equal to the Shanghai timestamp
428-
if !payloadID.Is(engine.PayloadV1, engine.PayloadV2) {
429-
return nil, engine.UnsupportedFork
430-
}
431-
data, err := api.getPayload(payloadID, false)
432-
if err != nil {
433-
return nil, err
434-
}
435-
// Check if the payload timestamp falls within the Shanghai fork timeframe
436-
if data.ExecutionPayload != nil && !api.checkFork(data.ExecutionPayload.Timestamp, forks.Shanghai) {
437-
return nil, engine.UnsupportedFork
438-
}
439-
return data, nil
423+
return api.getPayload(
424+
payloadID,
425+
false,
426+
[]engine.PayloadVersion{engine.PayloadV1, engine.PayloadV2},
427+
[]forks.Fork{forks.Shanghai},
428+
)
440429
}
441430

442431
// GetPayloadV3 returns a cached payload by id. This endpoint should only
443432
// be used for the Cancun fork.
444433
func (api *ConsensusAPI) GetPayloadV3(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
445-
if !payloadID.Is(engine.PayloadV3) {
446-
return nil, engine.UnsupportedFork
447-
}
448-
data, err := api.getPayload(payloadID, false)
449-
if err != nil {
450-
return nil, err
451-
}
452-
// Check if the payload timestamp falls within the Cancun fork timeframe
453-
if data.ExecutionPayload != nil && !api.checkFork(data.ExecutionPayload.Timestamp, forks.Cancun) {
454-
return nil, engine.UnsupportedFork
455-
}
456-
return data, nil
434+
return api.getPayload(
435+
payloadID,
436+
false,
437+
[]engine.PayloadVersion{engine.PayloadV3},
438+
[]forks.Fork{forks.Cancun},
439+
)
457440
}
458441

459442
// GetPayloadV4 returns a cached payload by id. This endpoint should only
460443
// be used for the Prague fork.
461444
func (api *ConsensusAPI) GetPayloadV4(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
462-
if !payloadID.Is(engine.PayloadV3) {
463-
return nil, engine.UnsupportedFork
464-
}
465-
data, err := api.getPayload(payloadID, false)
466-
if err != nil {
467-
return nil, err
468-
}
469-
// Check if the payload timestamp falls within the Prague fork timeframe
470-
if data.ExecutionPayload != nil && !api.checkFork(data.ExecutionPayload.Timestamp, forks.Prague) {
471-
return nil, engine.UnsupportedFork
472-
}
473-
return data, nil
445+
return api.getPayload(
446+
payloadID,
447+
false,
448+
[]engine.PayloadVersion{engine.PayloadV3},
449+
[]forks.Fork{forks.Prague},
450+
)
474451
}
475452

476453
// GetPayloadV5 returns a cached payload by id. This endpoint should only
@@ -479,26 +456,35 @@ func (api *ConsensusAPI) GetPayloadV4(payloadID engine.PayloadID) (*engine.Execu
479456
// This method follows the same specification as engine_getPayloadV4 with
480457
// changes of returning BlobsBundleV2 with BlobSidecar version 1.
481458
func (api *ConsensusAPI) GetPayloadV5(payloadID engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
482-
if !payloadID.Is(engine.PayloadV3) {
483-
return nil, engine.UnsupportedFork
484-
}
485-
data, err := api.getPayload(payloadID, false)
486-
if err != nil {
487-
return nil, err
488-
}
489-
// Check if the payload timestamp falls within the time frame of the Osaka fork or later
490-
if data.ExecutionPayload != nil && api.config().LatestFork(data.ExecutionPayload.Timestamp) < forks.Osaka {
491-
return nil, engine.UnsupportedFork
492-
}
493-
return data, nil
459+
return api.getPayload(
460+
payloadID,
461+
false,
462+
[]engine.PayloadVersion{engine.PayloadV3},
463+
[]forks.Fork{
464+
forks.Osaka,
465+
forks.BPO1,
466+
forks.BPO2,
467+
forks.BPO3,
468+
forks.BPO4,
469+
forks.BPO5,
470+
})
494471
}
495472

496-
func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID, full bool) (*engine.ExecutionPayloadEnvelope, error) {
473+
// getPayload will retreive the specified payload and verify it conforms to the
474+
// endpoint's allowed payload versions and forks.
475+
func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID, full bool, versions []engine.PayloadVersion, forks []forks.Fork) (*engine.ExecutionPayloadEnvelope, error) {
497476
log.Trace("Engine API request received", "method", "GetPayload", "id", payloadID)
477+
if !payloadID.Is(versions...) {
478+
return nil, engine.UnsupportedFork
479+
}
498480
data := api.localBlocks.get(payloadID, full)
499481
if data == nil {
500482
return nil, engine.UnknownPayload
501483
}
484+
if forks != nil && !api.checkFork(data.ExecutionPayload.Timestamp, forks...) {
485+
return nil, engine.UnsupportedFork
486+
}
487+
502488
return data, nil
503489
}
504490

0 commit comments

Comments
 (0)