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 3 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
11 changes: 6 additions & 5 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,21 @@ 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
end := uint64(start) + uint64(count)
if end > current {
end = current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
end = current
end = current + 1

}
var bodies []*engine.ExecutionPayloadBodyV1
for i := start; i < end; i++ {
bodies := make([]*engine.ExecutionPayloadBodyV1, 0, uint64(count))
for i := uint64(start); i < end; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem is here though. If we hit the end > current clause, then we need to make i < end inclusive, to get current too. Or set end = current +1.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start = 1, count = 2, current = 100: should lead to [1, 2]
start =1, count=100, current = 2, should lead to [1,2]

block := api.eth.BlockChain().GetBlockByNumber(i)
bodies = append(bodies, getBody(block))
body := getBody(block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's wrong. The returned body can be nil, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's wrong. The returned body can be nil, isn't it?

That's fine, we want a nil entry in the slice in that case (right?)

Copy link
Member

@MariusVanDerWijden MariusVanDerWijden Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the deref in line 789 should panic then, no?
I don't understand why we need to make the result an array not an array of pointers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we need to make the result an array not an array of pointers

I agree

Copy link
Contributor Author

@jwasinger jwasinger Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we need to make the result an array not an array of pointers

it was a shot-in-the-dark attempt at a fix. prob should have moved the PR back to draft at that point.

bodies = append(bodies, *body)
}
return bodies, nil
}
Expand Down
10 changes: 5 additions & 5 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1309,8 +1309,8 @@ func TestGetBlockBodiesByRange(t *testing.T) {

tests := []struct {
results []*types.Body
start uint64
count uint64
start hexutil.Uint64
count hexutil.Uint64
}{
// Genesis
{
Expand Down Expand Up @@ -1351,7 +1351,7 @@ func TestGetBlockBodiesByRange(t *testing.T) {
}
if len(result) == len(test.results) {
for i, r := range result {
if !equalBody(test.results[i], r) {
if !equalBody(test.results[i], &r) {
t.Fatalf("test %v: invalid response: expected %+v got %+v", k, test.results[i], r)
}
}
Expand All @@ -1367,8 +1367,8 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
defer node.Close()

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