generated from flashbots/flashbots-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 279
Forward validator registrations without decoding #733
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4a1b7c3
Do not call relay monitor
jtraglia b5ce901
Forward validator registrations without decoding
jtraglia 32f0b2a
Add back sendValidatorRegistrationsToRelayMonitors
jtraglia 3de02f5
Rename payloadBytes/bodyBytes -> regBytes
jtraglia a6487be
Move functionality to new register_validator.go file
jtraglia 8a52e77
Revert change to GetURI
jtraglia 31bd723
Fix mistake
jtraglia 76b02a8
Merge branch 'develop' into forward-registrations
jtraglia 08d3702
Add some basic validator registration tests
jtraglia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "net/url" | ||
|
|
||
| "github.com/flashbots/mev-boost/server/params" | ||
| "github.com/flashbots/mev-boost/server/types" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func (m *BoostService) registerValidator(log *logrus.Entry, regBytes []byte, header http.Header) error { | ||
| respErrCh := make(chan error, len(m.relays)) | ||
|
|
||
| // Forward request to each relay | ||
| for _, relay := range m.relays { | ||
| go func(relay types.RelayEntry) { | ||
| // Get the URL for this relay | ||
| requestURL := relay.GetURI(params.PathRegisterValidator) | ||
| log := log.WithField("url", requestURL) | ||
|
|
||
| // Build the new request | ||
| req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, requestURL, bytes.NewReader(regBytes)) | ||
| if err != nil { | ||
| log.WithError(err).Warn("error creating new request") | ||
| respErrCh <- err | ||
| return | ||
| } | ||
|
|
||
| // Extend the request header with our values | ||
| for key, values := range header { | ||
| req.Header[key] = values | ||
| } | ||
|
|
||
| // Send the request | ||
| resp, err := m.httpClientRegVal.Do(req) | ||
| if err != nil { | ||
| log.WithError(err).Warn("error calling registerValidator on relay") | ||
| respErrCh <- err | ||
| return | ||
| } | ||
| resp.Body.Close() | ||
|
|
||
| // Check if response is successful | ||
| if resp.StatusCode == http.StatusOK { | ||
| respErrCh <- nil | ||
| } else { | ||
| respErrCh <- fmt.Errorf("%w: %d", errHTTPErrorResponse, resp.StatusCode) | ||
| } | ||
| }(relay) | ||
| } | ||
|
|
||
| // Return OK if any relay responds OK | ||
| for range m.relays { | ||
| respErr := <-respErrCh | ||
| if respErr == nil { | ||
| // Goroutines are independent, so if there are a lot of configured | ||
| // relays and the first one responds OK, this will continue to send | ||
| // validator registrations to the other relays. | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| // None of the relays responded OK | ||
| return errNoSuccessfulRelayResponse | ||
| } | ||
|
|
||
| func (m *BoostService) sendValidatorRegistrationsToRelayMonitors(log *logrus.Entry, regBytes []byte, header http.Header) { | ||
| // Forward request to each relay monitor | ||
| for _, relayMonitor := range m.relayMonitors { | ||
| go func(relayMonitor *url.URL) { | ||
| // Get the URL for this relay monitor | ||
| requestURL := types.GetURI(relayMonitor, params.PathRegisterValidator) | ||
| log := log.WithField("url", requestURL) | ||
|
|
||
| // Build the new request | ||
| req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, requestURL, bytes.NewReader(regBytes)) | ||
| if err != nil { | ||
| log.WithError(err).Warn("error creating new request") | ||
| return | ||
| } | ||
|
|
||
| // Extend the request header with our values | ||
| for key, values := range header { | ||
| req.Header[key] = values | ||
| } | ||
|
|
||
| // Send the request | ||
| resp, err := m.httpClientRegVal.Do(req) | ||
| if err != nil { | ||
| log.WithError(err).Warn("error calling registerValidator on relay monitor") | ||
| return | ||
| } | ||
| resp.Body.Close() | ||
| }(relayMonitor) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.