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

Add getHeader SSZ support #734

Merged
merged 56 commits into from
Feb 17, 2025
Merged

Add getHeader SSZ support #734

merged 56 commits into from
Feb 17, 2025

Conversation

jtraglia
Copy link
Collaborator

@jtraglia jtraglia commented Feb 5, 2025

📝 Summary

This PR adds SSZ support for getHeader endpoint. Please see:

✅ I have run these commands

  • make lint
  • make test-race
  • go mod tidy

@0xTylerHolmes
Copy link
Contributor

0xTylerHolmes commented Feb 5, 2025

I think they are fine, but two things that caught my attention:

  1. Reusing a request object (it is fine if body == nil)
  2. Double close scenarios (io.Closer specifies that calls to Close after first call is considered undefined; though I think it is fine here)

First thought that addresses both of these and simplifies things a bit is if we define a doRequest function inside get_header that we can use to handle both the SSZ and JSON request attempts:

doRequest := func(accept string) (*http.Response, error) {
                req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
                if err != nil {
                    return nil, err
                }
                // <insert request prep>
                req.Header.Set("Accept", accept)
                return m.httpClientGetHeader.Do(req)
            }

Then we can do something like:

            // ssz attempt
            resp, err := doRequest("application/octet-stream")
            if err != nil {
                …
                return
            }
            // json if relay does not support ssz
            if resp.StatusCode == http.StatusNotAcceptable {
                resp.Body.Close()
                logRelay.Debug("SSZ not accepted, trying JSON")
                resp, err = doRequest("application/json")
                if err != nil {
                    …
		    return
                }
            }
            defer resp.Body.Close()
            // continue rest of execution
            ...

edit: get_header should probably use a context that we pass to the NewRequestWithContext so we can handle timeouts.

proposerPreferredContentType = MediaTypeJSON
}

// If every relay returned the bid in JSON, that means that none
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this logic actually necessary? the bid is decoded already anyway, why not directly return in the proposer preference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So if we return SSZ here, the proposer will send SSZ in its getPayload request and then mev-boost will need to convert it back to JSON for each relay. If we return JSON here it saves us the conversion.

It's not strictly necessary. I could remove it if you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just pushed a commit to remove this.

metachris
metachris previously approved these changes Feb 17, 2025
Copy link
Collaborator

@metachris metachris left a comment

Choose a reason for hiding this comment

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

nice! thanks

@jtraglia jtraglia merged commit 6af28a5 into develop Feb 17, 2025
4 checks passed
@jtraglia jtraglia deleted the ssz-get-header branch February 17, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants