Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon/engine/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var (
UnknownPayload = &EngineAPIError{code: -38001, msg: "Unknown payload"}
InvalidForkChoiceState = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"}
InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"}
TooLargeRequest = &EngineAPIError{code: -38004, msg: "Too large request"}
InvalidParams = &EngineAPIError{code: -32602, msg: "Invalid parameters"}

STATUS_INVALID = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil}
Expand Down
5 changes: 4 additions & 1 deletion eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,12 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*engin
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
// of block bodies by the engine api.
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count hexutil.Uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
if start == 0 || count == 0 || count > 1024 {
if start == 0 || count == 0 {
return nil, engine.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
}
if count > 1024 {
return nil, engine.TooLargeRequest.With(fmt.Errorf("requested count too large: %v", count))
}
// limit count up until current
current := api.eth.BlockChain().CurrentBlock().NumberU64()
last := uint64(start) + uint64(count) - 1
Expand Down
29 changes: 24 additions & 5 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,21 +1403,40 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
start: 0,
count: 0,
},
// More than 1024 blocks
{
start: 1,
count: 1025,
},
}

for _, test := range tests {
result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count)
if err == nil {
t.Fatalf("expected error, got %v", result)
} else if err.Error() != engine.InvalidParams.Error() {
t.Fatalf("expected invalid params error, got %v", err.Error())
}
}
}

func TestGetBlockBodiesByRangeRequestTooLarge(t *testing.T) {
node, eth, _ := setupBodies(t)
api := NewConsensusAPI(eth)
defer node.Close()

// More than 1024 blocks
test := struct {
start hexutil.Uint64
count hexutil.Uint64
}{
start: 1,
count: 1025,
}

result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count)
if err == nil {
t.Fatalf("expected error, got %v", result)
} else if err.Error() != engine.TooLargeRequest.Error() {
t.Fatalf("expected request too large error, got %v", err.Error())
}
}

func equalBody(a *types.Body, b *engine.ExecutionPayloadBodyV1) bool {
if a == nil && b == nil {
return true
Expand Down