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

Builder client #10703

Merged
merged 30 commits into from
May 23, 2022
Merged

Builder client #10703

merged 30 commits into from
May 23, 2022

Conversation

kasey
Copy link
Contributor

@kasey kasey commented May 17, 2022

What type of PR is this?

(branch-to-branch comparison)

Feature

What does this PR do? Why is it needed?

Adds a client for the builder api, described at https://ethereum.github.io/builder-specs/#/Builder

Which issues(s) does this PR fix?

This covers the "Implement builder APIs" Requirements at #10593

Other notes for review

@kasey kasey marked this pull request as ready for review May 19, 2022 17:28
@kasey kasey requested a review from a team as a code owner May 19, 2022 17:28
@kasey kasey requested review from saolyn and removed request for a team May 19, 2022 17:28
@terencechain
Copy link
Member

I tested this with mergemock, they look good. We can merge this to develop @kasey

@kasey kasey changed the base branch from builder-1 to develop May 19, 2022 23:34
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Nice!

api/client/builder/client.go Outdated Show resolved Hide resolved
api/client/builder/client_test.go Show resolved Hide resolved
api/client/builder/client_test.go Show resolved Hide resolved
api/client/builder/types.go Outdated Show resolved Hide resolved
api/client/builder/types.go Outdated Show resolved Hide resolved
return s.Bytes(), nil
}

type Uint64String uint64
Copy link
Member

Choose a reason for hiding this comment

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

Can use hexutil.Uint64

Copy link
Contributor Author

@kasey kasey May 20, 2022

Choose a reason for hiding this comment

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

Unfortunately this seems to produce 0x01 style hex-encoded output when I just swap the Uint64String types for hexutil.Uint64. I wonder if I'm doing something wrong?

api/client/builder/types.go Outdated Show resolved Hide resolved
api/client/builder/types.go Outdated Show resolved Hide resolved
api/client/builder/types.go Outdated Show resolved Hide resolved
api/client/builder/types.go Outdated Show resolved Hide resolved
// sszBytesToUint256 creates a Uint256 from a ssz-style (little-endian byte slice) representation.
func sszBytesToUint256(b []byte) Uint256 {
bi := new(big.Int)
return Uint256{Int: bi.SetBytes(bytesutil.ReverseByteOrder(b))}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not so sure about reverse byte order here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a few additional tests to improve confidence in the round trip:
https://github.com/prysmaticlabs/prysm/pull/10703/files#diff-9ed81b08538dbc58eb053d34c85e5425a58aab751d51e785294ea649b12c7020R696-R727

Interested in other ideas for test cases, I have a few more I want to write.

@terencechain terencechain added Ready For Review A pull request ready for code review and removed OK to merge labels May 23, 2022
terencechain
terencechain previously approved these changes May 23, 2022
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Lgtm

@prylabs-bulldozer prylabs-bulldozer bot merged commit c66d9e9 into develop May 23, 2022
@delete-merged-branch delete-merged-branch bot deleted the builder-client branch May 23, 2022 17:30
type reqOption func(*http.Request)

// do is a generic, opinionated GET function to reduce boilerplate amongst the getters in this packageapi/client/builder/types.go.
func (c *Client) do(ctx context.Context, method string, path string, body io.Reader, opts ...reqOption) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I recall seeing something similar when you were writing a beacon client. I wonder if there's room for unifying these so that next time we have to write a client, we don't have to write most of this boilerplate for request and response handling

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. This version is a slight iteration on the previous one, would like to circle back and unify them but wanted to limit scope of this change.

Comment on lines +216 to +219
body, err := json.Marshal(v)
if err != nil {
return nil, errors.Wrap(err, "error encoding the SignedBlindedBeaconBlockBellatrix value body in SubmitBlindedBlock")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it preferred to do something like:

json.NewEncoder(w).Encode(dataToWrite)

which directly uses the http response writer variable as the target for the encoding? I think it could reduce some duplicated code across this file, same with unmarshaling

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would that reduce duplicated code? Are you suggesting we could change the signature of do to take an interface and do the encoding there instead? like:

func (c *Client) do(ctx context.Context, method string, path string, body interface{}, opts ...reqOption) ([]byte, error) {

    rb := bytes.NewBuffer(nil)
    json.NewEncoder(rb).Encode(body)
    req, err := http.NewRequestWithContext(ctx, method, u.String(), io.NopCloser(rb))
    ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants