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 for transaction status data providers #6586

Open
Tracked by #6163
Guitarheroua opened this issue Oct 22, 2024 · 1 comment · May be fixed by #6818
Open
Tracked by #6163

[Access] Add implementation for transaction status data providers #6586

Guitarheroua opened this issue Oct 22, 2024 · 1 comment · May be fixed by #6818
Assignees
Labels

Comments

@Guitarheroua
Copy link
Contributor

Guitarheroua commented Oct 22, 2024

Send & subscribe and subscribe transaction data providers should be implemented as part of the new WebSocket pub/sub system based on the [Draft design of new WebSockets] (#6508).

Requirements:

  1. Send & subscribe and subscribe transaction data providers constructors should be implemented. The constructors should create a corresponding subscription.Subscription based on input arguments, and store topic, subscription and other necessary parameters in a newly created instance. These constructors should be called in a DataProviderFactory::NewDataProvider method.

  2. Run should be implemented. It will start in a forever loop until the subscription is closed. This method collects streaming data from the subscription, similar to how we do it, for example in SendAndSubscribeTransactionStatuses:

flow-go/access/handler.go

Lines 1407 to 1451 in 3496c0f

// SendAndSubscribeTransactionStatuses streams transaction statuses starting from the reference block saved in the
// transaction itself until the block containing the transaction becomes sealed or expired. When the transaction
// status becomes TransactionStatusSealed or TransactionStatusExpired, the subscription will automatically shut down.
func (h *Handler) SendAndSubscribeTransactionStatuses(
request *access.SendAndSubscribeTransactionStatusesRequest,
stream access.AccessAPI_SendAndSubscribeTransactionStatusesServer,
) error {
ctx := stream.Context()
// check if the maximum number of streams is reached
if h.StreamCount.Load() >= h.MaxStreams {
return status.Errorf(codes.ResourceExhausted, "maximum number of streams reached")
}
h.StreamCount.Add(1)
defer h.StreamCount.Add(-1)
tx, err := convert.MessageToTransaction(request.GetTransaction(), h.chain)
if err != nil {
return status.Error(codes.InvalidArgument, err.Error())
}
err = h.api.SendTransaction(ctx, &tx)
if err != nil {
return err
}
sub := h.api.SubscribeTransactionStatuses(ctx, &tx, request.GetEventEncodingVersion())
messageIndex := counters.NewMonotonousCounter(0)
return subscription.HandleSubscription(sub, func(txResults []*TransactionResult) error {
for i := range txResults {
value := messageIndex.Increment()
err = stream.Send(&access.SendAndSubscribeTransactionStatusesResponse{
TransactionResults: TransactionResultToMessage(txResults[i]),
MessageIndex: value,
})
if err != nil {
return rpc.ConvertError(err, "could not send response", codes.Internal)
}
}
return nil
})
}

Then the data is formatted in response messages for the client and written to the send callback.

Also, MessageIndex should be included in the response.

  1. The Close method should be implemented to shut down the subscription gracefully.

  2. ID and Topic getters should return UUID and the topic respectively.

@Guitarheroua Guitarheroua changed the title [Access] Add implementation TransactionStatusSubscriptionHandler for transaction status subscription [Access] Add implementation for transaction status data provider Nov 22, 2024
@Guitarheroua Guitarheroua changed the title [Access] Add implementation for transaction status data provider [Access] Add implementation for transaction status data providers Nov 29, 2024
@Guitarheroua
Copy link
Contributor Author

Part of the implementation relates to issue #6767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants