-
Notifications
You must be signed in to change notification settings - Fork 68
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
fix(rpc): remove use of magic numbers in JSON service #673
Conversation
…ptional parameters to set them
rpc/json/service.go
Outdated
defer cancel() | ||
|
||
sub, err := s.client.EventBus.Subscribe(ctx, addr, q, subBufferSize) | ||
sub, err := s.client.EventBus.Subscribe(ctx, addr, q, s.subscribeBufferSize) |
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.
- why is
Subscribe
called directly on theEventBus
and nots.client.Subscribe
? - why we adding timeout only on the
Subscribe
interact and not on all other queries?
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 wouldn't know, I was just replacing the magic numbers.
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.
now looking at the code,
s.client.Subscribe
is not exactly the same ass.client.EventBus.Subscribe
. The former has a different signature and does a bit more (publish events and whatnot)- you suggest we add it to
Unsubscribe
andUnsubscribeAll
? Apart from them, onlyTxSearch
,BlockSearch
,BroadcastTxCommit
andBroadcastTxSync
actually use the passed 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.
- I think all APIs should use
req.Context()
and notcontext.Background()
- not sure why the
Subscribe
method got it's own additional timeout timer. I would remove it whatsoever and apply global timeout on the RPC server
wdyt
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.
Makes sense.
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 just wish the implementation didn't rely so heavily on reflection
21459c8
to
9c7a321
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #673 +/- ##
==========================================
+ Coverage 44.04% 44.48% +0.43%
==========================================
Files 120 120
Lines 16531 16562 +31
==========================================
+ Hits 7281 7367 +86
+ Misses 8219 8165 -54
+ Partials 1031 1030 -1 ☔ View full report in Codecov by Sentry. |
…e-of-magic-numbers
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 think I understand, after reading func (c *Client) eventsRoutine
nice changes!
func WithSubscribeBufferSize(size int) option { | ||
return func(s *service) { | ||
s.subscribeBufferSize = size | ||
} | ||
} |
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.
unused?
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.
Ah I see it's just for later
// build the base response | ||
resultEvent := &ctypes.ResultEvent{Query: args.Query, Data: msg.Data(), Events: msg.Events()} | ||
var resp rpctypes.RPCResponse |
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.
Do you know why the old code made a new instance resultEvent
?
@@ -166,7 +160,7 @@ func (s *service) Unsubscribe(req *http.Request, args *unsubscribeArgs) (*emptyR | |||
|
|||
func (s *service) UnsubscribeAll(req *http.Request, args *unsubscribeAllArgs) (*emptyResult, error) { | |||
s.logger.Debug("unsubscribe from all queries", "remote", req.RemoteAddr) | |||
err := s.client.UnsubscribeAll(context.Background(), req.RemoteAddr) | |||
err := s.client.UnsubscribeAll(req.Context(), req.RemoteAddr) |
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.
nice 👍
defer cancel() | ||
if err := s.server.Shutdown(ctx); err != nil { | ||
s.Logger.Error("while shuting down RPC server", "error", err) | ||
s.Logger.Error("while shutting down RPC server", "error", err) |
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.
❤️
Use default values for subscribe timeout and buffer size, but leave optional parameters to set them
PR Standards
Opening a pull request should be able to meet the following requirements
Close #668
<-- Briefly describe the content of this pull request -->
For Author:
godoc
commentsFor Reviewer:
After reviewer approval: