Skip to content

Commit 265db06

Browse files
jsvisarjl493456442
andauthored
eth/catalyst: check osaka in engine_getBlobsV1 (#32731)
ref https://github.com/ethereum/execution-apis/blob/main/src/engine/osaka.md#cancun-api > Client software MUST return -38005: Unsupported fork error if the Osaka fork has been activated. --------- Signed-off-by: Delweng <[email protected]> Co-authored-by: rjl493456442 <[email protected]>
1 parent 943a30d commit 265db06

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

eth/catalyst/api.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ func (api *ConsensusAPI) getPayload(payloadID engine.PayloadID, full bool) (*eng
492492
// Client software MAY return an array of all null entries if syncing or otherwise
493493
// unable to serve blob pool data.
494494
func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProofV1, error) {
495+
// Reject the request if Osaka has been activated.
496+
// follow https://github.com/ethereum/execution-apis/blob/main/src/engine/osaka.md#cancun-api
497+
head := api.eth.BlockChain().CurrentHeader()
498+
if !api.checkFork(head.Time, forks.Cancun, forks.Prague) {
499+
return nil, unsupportedForkErr("engine_getBlobsV1 is only available at Cancun/Prague fork")
500+
}
495501
if len(hashes) > 128 {
496502
return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes)))
497503
}
@@ -532,16 +538,17 @@ func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProo
532538
// - if the request is [A_versioned_hash_for_blob_with_blob_proof], the response
533539
// MUST be null as well.
534540
//
535-
// Note, geth internally make the conversion from old version to new one, so the
536-
// data will be returned normally.
537-
//
538541
// Client software MUST support request sizes of at least 128 blob versioned
539542
// hashes. The client MUST return -38004: Too large request error if the number
540543
// of requested blobs is too large.
541544
//
542545
// Client software MUST return null if syncing or otherwise unable to serve
543546
// blob pool data.
544547
func (api *ConsensusAPI) GetBlobsV2(hashes []common.Hash) ([]*engine.BlobAndProofV2, error) {
548+
head := api.eth.BlockChain().CurrentHeader()
549+
if api.config().LatestFork(head.Time) < forks.Osaka {
550+
return nil, unsupportedForkErr("engine_getBlobsV2 is not available before Osaka fork")
551+
}
545552
if len(hashes) > 128 {
546553
return nil, engine.TooLargeRequest.With(fmt.Errorf("requested blob count too large: %v", len(hashes)))
547554
}

eth/catalyst/api_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,31 @@ func TestGetBlobsV1(t *testing.T) {
19911991
}
19921992
}
19931993

1994+
func TestGetBlobsV1AfterOsakaFork(t *testing.T) {
1995+
genesis := &core.Genesis{
1996+
Config: params.MergedTestChainConfig,
1997+
Alloc: types.GenesisAlloc{testAddr: {Balance: testBalance}},
1998+
Difficulty: common.Big0,
1999+
Timestamp: 1, // Timestamp > 0 to ensure Osaka fork is active
2000+
}
2001+
n, ethServ := startEthService(t, genesis, nil)
2002+
defer n.Close()
2003+
2004+
var engineErr *engine.EngineAPIError
2005+
api := newConsensusAPIWithoutHeartbeat(ethServ)
2006+
_, err := api.GetBlobsV1([]common.Hash{testrand.Hash()})
2007+
if !errors.As(err, &engineErr) {
2008+
t.Fatalf("Unexpected error: %T", err)
2009+
} else {
2010+
if engineErr.ErrorCode() != -38005 {
2011+
t.Fatalf("Expected error code -38005, got %d", engineErr.ErrorCode())
2012+
}
2013+
if engineErr.Error() != "Unsupported fork" {
2014+
t.Fatalf("Expected error message 'Unsupported fork', got '%s'", engineErr.Error())
2015+
}
2016+
}
2017+
}
2018+
19942019
func TestGetBlobsV2(t *testing.T) {
19952020
n, api := newGetBlobEnv(t, 1)
19962021
defer n.Close()

0 commit comments

Comments
 (0)