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

[Access] Add implementation BlockProvider #6636

Open
wants to merge 38 commits into
base: master
Choose a base branch
from

Conversation

UlyanaAndrukhiv
Copy link
Contributor

@UlyanaAndrukhiv UlyanaAndrukhiv commented Nov 12, 2024

Closes: #6584 , #6585

Context

In this PR implemented :

  • DataProviderFactory which is responsible for creating data providers based on the requested topic.
  • DataProvider which is the interface abstracts of the actual data provider used by the WebSocketCollector.
  • BaseDataProvider and BaseDataProviderImpl - the interface and the concrete implementation which holds common objects for the provider.
  • BlocksDataProvider which is responsible for providing blocks.
  • BlockHeadersDataProvider which is responsible for providing block headers.
  • BlockDigestsDataProvider which is responsible for providing block digests.

Added unit tests to cover this functionality.

@codecov-commenter
Copy link

codecov-commenter commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 45.03311% with 166 lines in your changes missing coverage. Please review.

Project coverage is 41.19%. Comparing base (8a3055c) to head (ff3851b).

Files with missing lines Patch % Lines
.../rest/websockets/data_providers/blocks_provider.go 61.33% 25 Missing and 4 partials ⚠️
...ckets/data_providers/mock/data_provider_factory.go 0.00% 28 Missing ⚠️
...st/websockets/data_providers/mock/data_provider.go 0.00% 24 Missing ⚠️
...ebsockets/data_providers/block_digests_provider.go 57.89% 14 Missing and 2 partials ⚠️
...ebsockets/data_providers/block_headers_provider.go 57.89% 14 Missing and 2 partials ⚠️
engine/access/rest/websockets/controller.go 0.00% 13 Missing ⚠️
access/handler.go 0.00% 10 Missing ⚠️
engine/access/state_stream/backend/handler.go 18.18% 9 Missing ⚠️
engine/access/subscription/util.go 0.00% 8 Missing ⚠️
...ss/rest/websockets/data_providers/base_provider.go 66.66% 5 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6636      +/-   ##
==========================================
- Coverage   41.26%   41.19%   -0.07%     
==========================================
  Files        2061     2066       +5     
  Lines      182702   182920     +218     
==========================================
- Hits        75384    75350      -34     
- Misses     101010   101262     +252     
  Partials     6308     6308              
Flag Coverage Δ
unittests 41.19% <45.03%> (-0.07%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Guitarheroua Guitarheroua left a comment

Choose a reason for hiding this comment

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

I have a few more minor comments, but other than that it looks cool!

@illia-malachyn
Copy link
Contributor

Please, wrap data_provider.Run() in a separate goroutine.

LGTM

// Run starts processing the subscription and handles responses.
//
// No errors are expected during normal operations.
Run() error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterargue, the idea behind separating the creation of the data provider and the Run() method is to provide better control over the subscription lifecycle. By doing this, we can immediately send a message to the client confirming that the subscription has been successfully created or failed. The actual subscription and data streaming process will only start after calling Run(), which ensures that we can handle any setup or preparation steps first. Since Run() starts processing the subscription, we do not need the ctx at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment with this context in BaseDataProvider or wherever you think makes it most clear. I think future readers will wonder this as well.

Copy link
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

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

mostly smaller comments. I think you should expand on the data provider tests to include some happy path testing. I also think there's currently a gap that covers more end-to-end functional testing. That can come in a separate PR, but wondering if we will need more control than is possible using integration tests alone. what do you think?

engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
c.dataProviders.Add(dp.ID(), dp)
dp.Run(ctx)

//TODO: return OK response to client
c.communicationChannel <- msg
Copy link
Contributor

Choose a reason for hiding this comment

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

this is returning the request back to the client?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is fixed here https://github.com/onflow/flow-go/pull/6762/files#diff-3dc4a79384159575e2c161dbc797a45dea7b38850629edef25b4a9a1cbc2533aR200

We have a bunch of places where we return sth we should not. I'll fix all of them in #6642

engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/data_providers/factory.go Outdated Show resolved Hide resolved
// Run starts processing the subscription and handles responses.
//
// No errors are expected during normal operations.
Run() error
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment with this context in BaseDataProvider or wherever you think makes it most clear. I think future readers will wonder this as well.

finalizedBlock *flow.Header
}

func TestBlocksProviderSuite(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also include happy path tests?

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.

[Access] Implement DataProvider interface and factory of data providers
6 participants