-
Notifications
You must be signed in to change notification settings - Fork 222
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Also, without this PR,
This is because With this PR, it will print the "no relays specified" error like we want. |
thanks! a test or two would be very nice for this |
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 |
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)) |
There was a problem hiding this comment.
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?
filtered := make([]string, 0, len(stringSlice)) | |
filtered := []string{} |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filtered := make([]string, 0, len(stringSlice)) | |
filtered := []string{} |
the final size is not known, don't initialize it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment.
Co-authored-by: Chris Hager <chris@linuxuser.at>
If #351 gets merged, this PR is no longer necessary. |
📝 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