mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 11:31:02 +00:00
eth/catalyst: request too large error (#26722)
The method `GetPayloadBodiesByRangeV1` now returns "-38004: Too large request" error if the requested range is too large, according to spec Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
6428663faf
commit
15e5e6176b
@ -78,6 +78,7 @@ var (
|
|||||||
UnknownPayload = &EngineAPIError{code: -38001, msg: "Unknown payload"}
|
UnknownPayload = &EngineAPIError{code: -38001, msg: "Unknown payload"}
|
||||||
InvalidForkChoiceState = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"}
|
InvalidForkChoiceState = &EngineAPIError{code: -38002, msg: "Invalid forkchoice state"}
|
||||||
InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"}
|
InvalidPayloadAttributes = &EngineAPIError{code: -38003, msg: "Invalid payload attributes"}
|
||||||
|
TooLargeRequest = &EngineAPIError{code: -38004, msg: "Too large request"}
|
||||||
InvalidParams = &EngineAPIError{code: -32602, msg: "Invalid parameters"}
|
InvalidParams = &EngineAPIError{code: -32602, msg: "Invalid parameters"}
|
||||||
|
|
||||||
STATUS_INVALID = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil}
|
STATUS_INVALID = ForkChoiceResponse{PayloadStatus: PayloadStatusV1{Status: INVALID}, PayloadID: nil}
|
||||||
|
@ -785,9 +785,12 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*engin
|
|||||||
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
|
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
|
||||||
// of block bodies by the engine api.
|
// of block bodies by the engine api.
|
||||||
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count hexutil.Uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
|
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))
|
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
|
// limit count up until current
|
||||||
current := api.eth.BlockChain().CurrentBlock().NumberU64()
|
current := api.eth.BlockChain().CurrentBlock().NumberU64()
|
||||||
last := uint64(start) + uint64(count) - 1
|
last := uint64(start) + uint64(count) - 1
|
||||||
|
@ -1383,37 +1383,43 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
|
|||||||
node, eth, _ := setupBodies(t)
|
node, eth, _ := setupBodies(t)
|
||||||
api := NewConsensusAPI(eth)
|
api := NewConsensusAPI(eth)
|
||||||
defer node.Close()
|
defer node.Close()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
start hexutil.Uint64
|
start hexutil.Uint64
|
||||||
count hexutil.Uint64
|
count hexutil.Uint64
|
||||||
|
want *engine.EngineAPIError
|
||||||
}{
|
}{
|
||||||
// Genesis
|
// Genesis
|
||||||
{
|
{
|
||||||
start: 0,
|
start: 0,
|
||||||
count: 1,
|
count: 1,
|
||||||
|
want: engine.InvalidParams,
|
||||||
},
|
},
|
||||||
// No block requested
|
// No block requested
|
||||||
{
|
{
|
||||||
start: 1,
|
start: 1,
|
||||||
count: 0,
|
count: 0,
|
||||||
|
want: engine.InvalidParams,
|
||||||
},
|
},
|
||||||
// Genesis & no block
|
// Genesis & no block
|
||||||
{
|
{
|
||||||
start: 0,
|
start: 0,
|
||||||
count: 0,
|
count: 0,
|
||||||
|
want: engine.InvalidParams,
|
||||||
},
|
},
|
||||||
// More than 1024 blocks
|
// More than 1024 blocks
|
||||||
{
|
{
|
||||||
start: 1,
|
start: 1,
|
||||||
count: 1025,
|
count: 1025,
|
||||||
|
want: engine.TooLargeRequest,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
for i, tc := range tests {
|
||||||
for _, test := range tests {
|
result, err := api.GetPayloadBodiesByRangeV1(tc.start, tc.count)
|
||||||
result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error, got %v", result)
|
t.Fatalf("test %d: expected error, got %v", i, result)
|
||||||
|
}
|
||||||
|
if have, want := err.Error(), tc.want.Error(); have != want {
|
||||||
|
t.Fatalf("test %d: have %s, want %s", i, have, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user