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

optimize WS newhead #1615

Merged
merged 2 commits into from
May 1, 2024
Merged

optimize WS newhead #1615

merged 2 commits into from
May 1, 2024

Conversation

codchen
Copy link
Collaborator

@codchen codchen commented May 1, 2024

Describe your changes and provide context

instead of having each subscription subscribing to tendermint and encode to JSON independently, we will maintain a single subscription with tendermint and a single copy of encoded JSON per head, then fan it out to all outgoing subscriptions

Testing performed to validate your change

@@ -98,7 +98,8 @@
func (a *FilterAPI) NewFilter(
_ context.Context,
crit filters.FilterCriteria,
) (ethrpc.ID, error) {
) (id ethrpc.ID, err error) {
defer recordMetrics("eth_newFilter", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@@ -113,7 +114,8 @@

func (a *FilterAPI) NewBlockFilter(
_ context.Context,
) (ethrpc.ID, error) {
) (id ethrpc.ID, err error) {
defer recordMetrics("eth_newBlockFilter", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@@ -128,7 +130,8 @@
func (a *FilterAPI) GetFilterChanges(
ctx context.Context,
filterID ethrpc.ID,
) (interface{}, error) {
) (res interface{}, err error) {
defer recordMetrics("eth_getFilterChanges", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@@ -178,7 +181,8 @@
func (a *FilterAPI) GetFilterLogs(
ctx context.Context,
filterID ethrpc.ID,
) ([]*ethtypes.Log, error) {
) (res []*ethtypes.Log, err error) {
defer recordMetrics("eth_getFilterLogs", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@@ -206,7 +210,8 @@
func (a *FilterAPI) GetLogs(
ctx context.Context,
crit filters.FilterCriteria,
) ([]*ethtypes.Log, error) {
) (res []*ethtypes.Log, err error) {
defer recordMetrics("eth_getLogs", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
}

func (a *SubscriptionAPI) NewHeads(ctx context.Context) (*rpc.Subscription, error) {
func (a *SubscriptionAPI) NewHeads(ctx context.Context) (s *rpc.Subscription, err error) {
defer recordMetrics("eth_newHeads", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
return rpcSub, nil
}

func (a *SubscriptionAPI) Logs(ctx context.Context, filter *filters.FilterCriteria) (*rpc.Subscription, error) {
func (a *SubscriptionAPI) Logs(ctx context.Context, filter *filters.FilterCriteria) (s *rpc.Subscription, err error) {
defer recordMetrics("eth_logs", time.Now(), err == nil)

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
evmrpc/subscribe.go Dismissed Show dismissed Hide dismissed
evmrpc/subscribe.go Dismissed Show dismissed Hide dismissed
evmrpc/subscribe.go Dismissed Show dismissed Hide dismissed
@codecov-commenter
Copy link

codecov-commenter commented May 1, 2024

Codecov Report

Attention: Patch coverage is 70.96774% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 61.68%. Comparing base (9646724) to head (5c97ba8).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1615      +/-   ##
==========================================
+ Coverage   61.62%   61.68%   +0.06%     
==========================================
  Files         365      365              
  Lines       26135    26169      +34     
==========================================
+ Hits        16106    16143      +37     
+ Misses       8959     8956       -3     
  Partials     1070     1070              
Files Coverage Δ
evmrpc/filter.go 77.47% <100.00%> (+0.54%) ⬆️
evmrpc/server.go 90.76% <100.00%> (ø)
evmrpc/subscribe.go 65.51% <63.26%> (+3.18%) ⬆️

... and 2 files with indirect coverage changes

}
case <-rpcSub.Err():
return
break OUTER
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the same as continue here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no we want to break out of the outer loop (instead of the select clause)

}
id, subCh, err := api.subscriptionManager.Subscribe(context.Background(), NewHeadQueryBuilder(), api.subscriptonConfig.subscriptionCapacity)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need supervision or some mechanism to retry/reconnect (can the subscription die?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the subscription manager has a retry mechanism (that's what the subscription was canceled, resubscribing log we saw)

@philipsu522 philipsu522 enabled auto-merge (squash) May 1, 2024 19:12
@philipsu522 philipsu522 merged commit 5ddc349 into main May 1, 2024
47 checks passed
@philipsu522 philipsu522 deleted the subscribe-newhead branch May 1, 2024 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants