Skip to content

[Access] Add arguments getter for data providers #6873

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

Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cb2fa7d
Added arguments getter for data providers, filled ListSubscriptionsMe…
UlyanaAndrukhiv Jan 13, 2025
0cd1186
Merge branch 'master' into UlianaAndrukhiv/6865-data-provider-arguments
UlyanaAndrukhiv Jan 13, 2025
acb6b02
Updatated TestListSubscriptions unit test
UlyanaAndrukhiv Jan 13, 2025
33e3913
Merge branch 'UlianaAndrukhiv/6865-data-provider-arguments' of github…
UlyanaAndrukhiv Jan 13, 2025
24fb036
Merge branch 'illia-malachyn/6845-unify-subscription-and-message-id' …
UlyanaAndrukhiv Jan 15, 2025
0e3d1cf
Reverted changes from illia-malachyn/6845-unify-subscription-and-mess…
UlyanaAndrukhiv Jan 15, 2025
bacec03
Updated godoc
UlyanaAndrukhiv Jan 15, 2025
4f23a22
Merge branch 'master' into UlianaAndrukhiv/6865-data-provider-arguments
UlyanaAndrukhiv Jan 16, 2025
b0c5ffa
Removed omitempty from ID and Topic for SubscriptionEntry
UlyanaAndrukhiv Jan 16, 2025
fe9f40b
Merge branch 'UlianaAndrukhiv/6865-data-provider-arguments' of github…
UlyanaAndrukhiv Jan 16, 2025
ca06def
Merge branch 'master' into UlianaAndrukhiv/6865-data-provider-arguments
UlyanaAndrukhiv Jan 20, 2025
59ce14a
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into UlianaAn…
Guitarheroua Jan 23, 2025
d89f7da
Merge branch 'master' into UlianaAndrukhiv/6865-data-provider-arguments
Guitarheroua Jan 23, 2025
d2e11f9
fixed remarks and tests
Guitarheroua Jan 23, 2025
899b691
remove error_codes.go
Guitarheroua Jan 23, 2025
93bb915
Apply suggestions from code review
peterargue Jan 23, 2025
a7f3163
Merge branch 'master' into UlianaAndrukhiv/6865-data-provider-arguments
peterargue Jan 23, 2025
7413e02
Update engine/access/rest/websockets/models/subscription_entry.go
peterargue Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions engine/access/rest/websockets/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ func (c *Controller) handleListSubscriptions(ctx context.Context, msg models.Lis
var subs []*models.SubscriptionEntry
err := c.dataProviders.ForEach(func(id uuid.UUID, provider dp.DataProvider) error {
subs = append(subs, &models.SubscriptionEntry{
ID: id.String(),
Topic: provider.Topic(),
ID: id.String(),
Topic: provider.Topic(),
Arguments: provider.Arguments(),
})
return nil
})
Expand Down
3 changes: 3 additions & 0 deletions engine/access/rest/websockets/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ func (s *WsControllerSuite) TestListSubscriptions() {

id := uuid.New()
topic := dp.BlocksTopic
arguments := models.Arguments{}
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 some value into the arguments map to ensure we're testing that the same set is returned in the asserts. Otherwise we could miss a bug where an empty argument set is passed instead

dataProvider.On("ID").Return(id)
dataProvider.On("Topic").Return(topic)
dataProvider.On("Arguments").Return(arguments)
// data provider might finish on its own or controller will close it via Close()
dataProvider.On("Close").Return(nil).Maybe()
dataProvider.
Expand Down Expand Up @@ -530,6 +532,7 @@ func (s *WsControllerSuite) TestListSubscriptions() {
require.Equal(t, 1, len(response.Subscriptions))
require.Equal(t, id.String(), response.Subscriptions[0].ID)
require.Equal(t, topic, response.Subscriptions[0].Topic)
require.Equal(t, arguments, response.Subscriptions[0].Arguments)

return websocket.ErrCloseSent
}).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func NewAccountStatusesDataProvider(

p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, accountStatusesArgs), // Set up a subscription to account statuses based on arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (

"github.com/google/uuid"

"github.com/onflow/flow-go/engine/access/rest/websockets/models"
"github.com/onflow/flow-go/engine/access/subscription"
)

// baseDataProvider holds common objects for the provider
type baseDataProvider struct {
id uuid.UUID
topic string
arguments models.Arguments
cancel context.CancelFunc
send chan<- interface{}
subscription subscription.Subscription
Expand All @@ -20,13 +22,15 @@ type baseDataProvider struct {
// newBaseDataProvider creates a new instance of baseDataProvider.
func newBaseDataProvider(
topic string,
arguments models.Arguments,
cancel context.CancelFunc,
send chan<- interface{},
subscription subscription.Subscription,
) *baseDataProvider {
return &baseDataProvider{
id: uuid.New(),
topic: topic,
arguments: arguments,
cancel: cancel,
send: send,
subscription: subscription,
Expand All @@ -43,6 +47,11 @@ func (b *baseDataProvider) Topic() string {
return b.topic
}

// Arguments returns the arguments associated with the data provider.
func (b *baseDataProvider) Arguments() models.Arguments {
return b.arguments
}

// Close terminates the data provider.
//
// No errors are expected during normal operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func NewBlockDigestsDataProvider(
subCtx, cancel := context.WithCancel(ctx)
p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, blockArgs), // Set up a subscription to block digests based on arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewBlockHeadersDataProvider(
subCtx, cancel := context.WithCancel(ctx)
p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, blockArgs), // Set up a subscription to block headers based on arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewBlocksDataProvider(
subCtx, cancel := context.WithCancel(ctx)
p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, p.arguments), // Set up a subscription to blocks based on arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package data_providers

import (
"github.com/google/uuid"

"github.com/onflow/flow-go/engine/access/rest/websockets/models"
)

// The DataProvider is the interface abstracts of the actual data provider used by the WebSocketCollector.
// It provides methods for retrieving the provider's unique ID, topic, and a methods to close and run the provider.
// It provides methods for retrieving the provider's unique ID, topic, arguments and a methods to close and run the provider.
type DataProvider interface {
// ID returns the unique identifier of the data provider.
ID() uuid.UUID
// Topic returns the topic associated with the data provider.
Topic() string
// Arguments returns the arguments associated with the data provider.
Arguments() models.Arguments
// Close terminates the data provider.
//
// No errors are expected during normal operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewEventsDataProvider(

p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, eventArgs), // Set up a subscription to events based on arguments.
Expand Down Expand Up @@ -103,7 +104,6 @@ func (p *EventsDataProvider) handleResponse() func(eventsResponse *backend.Event

var response models.EventResponse
response.Build(eventsResponse, index)

p.send <- &response

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (s *DataProviderFactorySuite) TestSupportedTopics() {
s.Require().NotNil(provider, "Expected provider for topic %s", test.topic)
s.Require().NoError(err, "Expected no error for topic %s", test.topic)
s.Require().Equal(test.topic, provider.Topic())
s.Require().Equal(test.arguments, provider.Arguments())

test.assertExpectations()
})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewSendAndGetTransactionStatusesDataProvider(

p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, sendTxStatusesArgs), // Set up a subscription to tx statuses based on arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func NewTransactionStatusesDataProvider(

p.baseDataProvider = newBaseDataProvider(
topic,
arguments,
cancel,
send,
p.createSubscription(subCtx, txStatusesArgs), // Set up a subscription to tx statuses based on arguments.
Expand Down
5 changes: 3 additions & 2 deletions engine/access/rest/websockets/models/subscription_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

// SubscriptionEntry represents an active subscription entry.
type SubscriptionEntry struct {
Topic string `json:"topic,omitempty"` // Topic of the subscription
ID string `json:"id,omitempty"` // Unique subscription ID
Topic string `json:"topic,omitempty"` // Topic of the subscription
ID string `json:"id,omitempty"` // Unique subscription ID
Arguments Arguments `json:"arguments"` // Arguments of the subscription
}
Loading