Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/catalyst: make getPayloadBodiesByRange take hex inputs #26624

Merged
merged 6 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
12 changes: 6 additions & 6 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,18 +772,18 @@ 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 uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count hexutil.Uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
if start == 0 || count == 0 || count > 1024 {
return nil, engine.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
}
// limit count up until current
current := api.eth.BlockChain().CurrentBlock().NumberU64()
end := start + count
if end > current {
end = current
last := uint64(start) + uint64(count) - 1
if last > current {
last = current
}
var bodies []*engine.ExecutionPayloadBodyV1
for i := start; i < end; i++ {
bodies := make([]*engine.ExecutionPayloadBodyV1, 0, uint64(count))
for i := uint64(start); i <= last; i++ {
block := api.eth.BlockChain().GetBlockByNumber(i)
bodies = append(bodies, getBody(block))
}
Expand Down
36 changes: 26 additions & 10 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,9 +1309,14 @@ func TestGetBlockBodiesByRange(t *testing.T) {

tests := []struct {
results []*types.Body
start uint64
count uint64
start hexutil.Uint64
count hexutil.Uint64
}{
{
results: []*types.Body{blocks[9].Body()},
start: 10,
count: 1,
},
// Genesis
{
results: []*types.Body{blocks[0].Body()},
Expand All @@ -1332,31 +1337,42 @@ func TestGetBlockBodiesByRange(t *testing.T) {
},
// unavailable block
{
results: []*types.Body{blocks[18].Body()},
results: []*types.Body{blocks[18].Body(), blocks[19].Body()},
start: 19,
count: 3,
},
// after range
// unavailable block
{
results: make([]*types.Body, 0),
results: []*types.Body{blocks[19].Body()},
start: 20,
count: 2,
},
{
results: []*types.Body{blocks[19].Body()},
start: 20,
count: 1,
},
// whole range unavailable
{
results: make([]*types.Body, 0),
start: 22,
count: 2,
},
}

for k, test := range tests {
for k, test := range tests[:] {
holiman marked this conversation as resolved.
Show resolved Hide resolved
result, err := api.GetPayloadBodiesByRangeV1(test.start, test.count)
if err != nil {
t.Fatal(err)
}
if len(result) == len(test.results) {
for i, r := range result {
if !equalBody(test.results[i], r) {
t.Fatalf("test %v: invalid response: expected %+v got %+v", k, test.results[i], r)
t.Fatalf("test %d: invalid response: expected \n%+v\ngot\n%+v", k, test.results[i], r)
}
}
} else {
t.Fatalf("invalid length want %v got %v", len(test.results), len(result))
t.Fatalf("test %d: invalid length want %v got %v", k, len(test.results), len(result))
}
}
}
Expand All @@ -1367,8 +1383,8 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
defer node.Close()

tests := []struct {
start uint64
count uint64
start hexutil.Uint64
count hexutil.Uint64
}{
// Genesis
{
Expand Down