-
Notifications
You must be signed in to change notification settings - Fork 208
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
Implement relay url provider #1328
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
) | ||
|
||
// DefaultRelayUrlProvider provides relay URL strings, based on relay key. | ||
type DefaultRelayUrlProvider struct { |
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.
DefaultRelayUrlProvider
sounds like there should be other relay URL provider implementations. Maybe we can just call it relayURLProvider
unexported?
NewRelayURLProvider
can return the struct pointer as RelayURLProvider type.
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.
nit: not sure how useful this abstraction is. It simply wraps the eth client to fetch relay info from chain. Could we just use EthClient straight from the relay client?
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.
nit: not sure how useful this abstraction is
There are two reasons I thought it makes sense to create this abstraction:
- it allows for a test implementation of the functionality
- In the (near?) future, the relay registry will need to be updated with functionality to remove and update entries. At that time, there will be much more logic, and making this split now means that future changes to the
RelayURLProvider
won't require changes to the relay client
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.
DefaultRelayUrlProvider sounds like there should be other relay URL provider implementations
Did you notice that there is a TestRelayUrlProvider
implementation? That was the reason I chose the Default
prefix, curious if that affects your opinion at all
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.
I thought you could have easily mocked this class, but I don't think that's true because you're passing in the client in the binding to generate the caller.
I'd still prefer calling this class something like relayURLProvider
though. Yes, TestRelayUrlProvider
is an alternative implementation of the interface but it's only intended for testing. In fact, I'd put TestRelayUrlProvider
and the tests in a different package (i.e. relay_test
) so that structs intended for testing aren't exported from the main package.
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.
I renamed to relayURLProvider
, and moved the test implementation into the test
package
// logic to retry initialization after a period of time in case of failure | ||
c.relayInitializationStatus.Store(key, true) | ||
|
||
relayUrl, err := c.relayUrlProvider.GetRelayUrl(ctx, key) |
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.
What happens if this fails? relayInitializationStatus
for this key has been set to true and grpcRelayClients.Load
will continue failing, right?
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.
That's how the current implementation behaves, yes.
Do you think it makes more sense to rework the method, such that a failed fetch doesn't result in the initialization flag being set to true
?
Callers would therefore infinitely retry the initialization (lazily), with the rate of retries being limited by the timeout configured on the context.
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.
Or, alternatively, I could implement more specific retry logic to limit the rate.
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.
What if we just set relayInitializationStatus
to true at the end of the method only when it's successful?
If any of these rpc calls fail, the relay client just returns error, but any subsequent calls would retry.
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.
Sounds good- done
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
@@ -0,0 +1,58 @@ | |||
package relay |
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.
nit: filename
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.
Fixed
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
Why are these changes needed?
Checks