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

Filter out duplicate relays & monitors #348

Closed
wants to merge 4 commits into from
Closed

Filter out duplicate relays & monitors #348

wants to merge 4 commits into from

Conversation

jtraglia
Copy link
Collaborator

@jtraglia jtraglia commented Sep 23, 2022

📝 Summary

Noticed that there were no duplication checks. You could specify the same relay or monitor multiple times.

⛱ Motivation and Context

May prevent unnecessary work by the MEV client and relays.


✅ I have run these commands

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

@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2022

Codecov Report

Merging #348 (00f9d46) into main (bca8407) will decrease coverage by 10.29%.
The diff coverage is 95.00%.

@@             Coverage Diff             @@
##             main     #348       +/-   ##
===========================================
- Coverage   82.50%   72.20%   -10.30%     
===========================================
  Files           5        6        +1     
  Lines         680      806      +126     
===========================================
+ Hits          561      582       +21     
- Misses         91      192      +101     
- Partials       28       32        +4     
Flag Coverage Δ
unittests 72.20% <95.00%> (-10.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cli/main.go 20.47% <95.00%> (ø)
server/service.go 80.00% <0.00%> (-1.04%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@jtraglia
Copy link
Collaborator Author

Also, without this PR, mev-boost will return a not-so-useful error if the -relays flag isn't set:

$ make build && ./mev-boost -mainnet  
go build -trimpath -ldflags "-s -X 'github.com/flashbots/mev-boost/config.Version=v1.3.2-5-gece7a08'" -v -o mev-boost .
github.com/flashbots/mev-boost
INFO[2022-09-23T13:59:38-05:00] mev-boost v1.3.2-5-gece7a08                  
INFO[2022-09-23T13:59:38-05:00] using genesis fork version: 0x00000000       
FATA[2022-09-23T13:59:38-05:00] Invalid relay URL                             error="missing relay public key" relayURL=

This is because relayURLs is an empty string ("") when not specified. That's its default value.

With this PR, it will print the "no relays specified" error like we want.

@metachris
Copy link
Collaborator

metachris commented Sep 24, 2022

thanks! a test or two would be very nice for this

@jtraglia
Copy link
Collaborator Author

Yeah tests are a good idea. Added some. I would have done some relay monitor tests but it very repetitive since it's essentially the same thing. Also, it's not really possible to test invalid relay cases because parseRelayURLs will immediately exit without returning an error if something is wrong, like a missing pubkey.

for _, entry := range strings.Split(relayURLs, ",") {
// Deletes whitespace from beginning and end, removes empty strings
func trim(stringSlice []string) []string {
filtered := make([]string, 0, len(stringSlice))
Copy link
Collaborator

Choose a reason for hiding this comment

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

since the final size is not known, don't initialize the slice with a size?

Suggested change
filtered := make([]string, 0, len(stringSlice))
filtered := []string{}

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 that third argument is the capacity, not size. This is an optimization.

func make([]T, len, cap) []T

Since we know the maximum number of items there can be (the length of the input slice), I think this is reasonable. Pre-allocations can speed things up quite a bit, not that this is a time sensitive operation.

Here's some random article that explains it pretty well:


// Returns a slice of unique items
func unique(stringSlice []string) []string {
filtered := make([]string, 0, len(stringSlice))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
filtered := make([]string, 0, len(stringSlice))
filtered := []string{}

the final size is not known, don't initialize it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See my other comment.

cli/main.go Outdated Show resolved Hide resolved
Co-authored-by: Chris Hager <chris@linuxuser.at>
@jtraglia
Copy link
Collaborator Author

If #351 gets merged, this PR is no longer necessary.

@jtraglia jtraglia closed this Sep 26, 2022
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.

3 participants