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] Implement subscribe transaction statuses by transaction ID #6737

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ed80a0c
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Dec 17, 2024
103d15d
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
peterargue Dec 17, 2024
4b7275b
Apply suggestions from code review
Guitarheroua Dec 20, 2024
5ede502
fixed remarks
Guitarheroua Dec 20, 2024
80b63eb
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Dec 20, 2024
c1dc45a
Apply suggestions from code review
Guitarheroua Dec 27, 2024
0f1ad0d
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Dec 27, 2024
e53c356
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
peterargue Dec 27, 2024
93c69c1
change to irrecoverable throw
Guitarheroua Dec 30, 2024
a162ba2
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
peterargue Jan 2, 2025
383b7e8
Implement remarks. Added txRefID for subscribe calls. Added test.
Guitarheroua Jan 8, 2025
7184c8e
Started to implement state detection on transaction suscription
Guitarheroua Jan 9, 2025
725ccda
Fixed issues with test failint
Guitarheroua Jan 13, 2025
25493da
Get rid of unnecessary api calls
Guitarheroua Jan 16, 2025
733a485
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into AndriiSl…
Guitarheroua Jan 16, 2025
1170a55
Fixed crash
Guitarheroua Jan 16, 2025
b427e33
Fixed issue with statuses sending
Guitarheroua Jan 16, 2025
03c5be5
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 17, 2025
d1d0466
Added more uinit tests for subscribe tx statuses
Guitarheroua Jan 20, 2025
4aa5d14
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 20, 2025
52bc521
linted
Guitarheroua Jan 20, 2025
65a0757
extract tx_sub_metadata structure
Guitarheroua Jan 22, 2025
fd4afd1
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 22, 2025
b291085
fixed test
Guitarheroua Jan 22, 2025
a3f45e1
Merge branch 'AndriiSlisarchuk/6573-pending-should-return-immediately…
Guitarheroua Jan 22, 2025
fa5f03f
simplify logic
Guitarheroua Jan 22, 2025
a51b1fb
finished refactoring
Guitarheroua Jan 22, 2025
02e1d83
linted
Guitarheroua Jan 22, 2025
9e3bd9a
Merge branch 'master' of github.com:The-K-R-O-K/flow-go into AndriiSl…
Guitarheroua Jan 27, 2025
10ad5f9
fixed remarks
Guitarheroua Jan 30, 2025
2184fdd
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 30, 2025
6960d1f
Fixed issue with failed test
Guitarheroua Jan 30, 2025
edf5a21
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 30, 2025
5165fb7
linted
Guitarheroua Jan 30, 2025
1e72dab
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Jan 31, 2025
f9f7574
refactored tests
Guitarheroua Jan 31, 2025
41c4627
Merge branch 'AndriiSlisarchuk/6573-pending-should-return-immediately…
Guitarheroua Jan 31, 2025
bc460e9
Merge branch 'master' into AndriiSlisarchuk/6573-pending-should-retur…
Guitarheroua Feb 4, 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
44 changes: 15 additions & 29 deletions access/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,41 +203,19 @@ type API interface {
//
// If invalid parameters will be supplied SubscribeBlockDigestsFromLatest will return a failed subscription.
SubscribeBlockDigestsFromLatest(ctx context.Context, blockStatus flow.BlockStatus) subscription.Subscription
// SubscribeTransactionStatusesFromStartBlockID subscribes to transaction status updates for a given transaction ID.
// Monitoring begins from the specified block ID. The subscription streams status updates until the transaction
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
// these final statuses, the subscription will automatically terminate.
//
// Parameters:
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
// - txID: The identifier of the transaction to monitor.
// - startBlockID: The block ID from which to start monitoring.
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
SubscribeTransactionStatusesFromStartBlockID(ctx context.Context, txID flow.Identifier, startBlockID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
// SubscribeTransactionStatusesFromStartHeight subscribes to transaction status updates for a given transaction ID.
// Monitoring begins from the specified block height. The subscription streams status updates until the transaction
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
// these final statuses, the subscription will automatically terminate.
// SubscribeTransactionStatuses subscribes to transaction status updates for a given transaction ID. Monitoring begins
// from the last block ID. The subscription streams status updates until the transaction reaches the final state
// ([flow.TransactionStatusSealed] or [flow.TransactionStatusExpired]). When the transaction reaches one of these
// final states, the subscription will automatically terminate.
//
// Parameters:
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
// - txID: The unique identifier of the transaction to monitor.
// - startHeight: The block height from which to start monitoring.
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
SubscribeTransactionStatusesFromStartHeight(ctx context.Context, txID flow.Identifier, startHeight uint64, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
// SubscribeTransactionStatusesFromLatest subscribes to transaction status updates for a given transaction ID.
// Monitoring begins from the latest block. The subscription streams status updates until the transaction
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). When the transaction reaches one of
// these final statuses, the subscription will automatically terminate.
//
// Parameters:
// - ctx: The context to manage the subscription's lifecycle, including cancellation.
// - txID: The unique identifier of the transaction to monitor.
// - requiredEventEncodingVersion: The version of event encoding required for the subscription.
SubscribeTransactionStatusesFromLatest(ctx context.Context, txID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
// SendAndSubscribeTransactionStatuses sends a transaction to the network and subscribes to its status updates.
SubscribeTransactionStatuses(ctx context.Context, txID flow.Identifier, requiredEventEncodingVersion entities.EventEncodingVersion) subscription.Subscription
// SendAndSubscribeTransactionStatuses sends a transaction to the execution node and subscribes to its status updates.
// Monitoring begins from the reference block saved in the transaction itself and streams status updates until the transaction
// reaches a final state (TransactionStatusSealed or TransactionStatusExpired). Once a final status is reached, the subscription
// reaches the final state ([flow.TransactionStatusSealed] or [flow.TransactionStatusExpired]). Once the final status has been reached, the subscription
// automatically terminates.
//
// Parameters:
Expand All @@ -261,6 +239,14 @@ type TransactionResult struct {
BlockHeight uint64
}

func (r *TransactionResult) IsExecuted() bool {
return r.Status == flow.TransactionStatusExecuted || r.Status == flow.TransactionStatusSealed
}

func (r *TransactionResult) IsFinal() bool {
return r.Status == flow.TransactionStatusSealed || r.Status == flow.TransactionStatusExpired
}

func TransactionResultToMessage(result *TransactionResult) *access.TransactionResultResponse {
return &access.TransactionResultResponse{
Status: entities.TransactionStatus(result.Status),
Expand Down
46 changes: 3 additions & 43 deletions access/mock/api.go

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

25 changes: 5 additions & 20 deletions cmd/util/cmd/run-script/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/onflow/flow-go/module/metrics"
)

var ErrNotImplemented = errors.New("not implemented")

var (
flagPayloads string
flagState string
Expand Down Expand Up @@ -532,35 +534,18 @@ func (*api) SubscribeBlockDigestsFromLatest(
return nil
}

func (a *api) SubscribeTransactionStatusesFromStartBlockID(
_ context.Context,
_ flow.Identifier,
_ flow.Identifier,
_ entities.EventEncodingVersion,
) subscription.Subscription {
return nil
}

func (a *api) SubscribeTransactionStatusesFromStartHeight(
func (a *api) SubscribeTransactionStatuses(
_ context.Context,
_ flow.Identifier,
_ uint64,
_ entities.EventEncodingVersion,
) subscription.Subscription {
return nil
return subscription.NewFailedSubscription(ErrNotImplemented, "failed to call SubscribeTransactionStatuses")
}

func (a *api) SubscribeTransactionStatusesFromLatest(
_ context.Context,
_ flow.Identifier,
_ entities.EventEncodingVersion,
) subscription.Subscription {
return nil
}
func (a *api) SendAndSubscribeTransactionStatuses(
_ context.Context,
_ *flow.TransactionBody,
_ entities.EventEncodingVersion,
) subscription.Subscription {
return nil
return subscription.NewFailedSubscription(ErrNotImplemented, "failed to call SendAndSubscribeTransactionStatuses")
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *DataProviderFactorySuite) TestSupportedTopics() {
topic: TransactionStatusesTopic,
arguments: models.Arguments{},
setupSubscription: func() {
s.setupSubscription(s.accessApi.On("SubscribeTransactionStatusesFromLatest", mock.Anything, mock.Anything, mock.Anything))
s.setupSubscription(s.accessApi.On("SubscribeTransactionStatuses", mock.Anything, mock.Anything, mock.Anything))
},
assertExpectations: func() {
s.stateStreamApi.AssertExpectations(s.T())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/onflow/flow-go/access"
commonmodels "github.com/onflow/flow-go/engine/access/rest/common/models"
"github.com/onflow/flow-go/engine/access/rest/common/parser"
"github.com/onflow/flow-go/engine/access/rest/http/request"
"github.com/onflow/flow-go/engine/access/rest/websockets/models"
"github.com/onflow/flow-go/engine/access/subscription"
"github.com/onflow/flow-go/model/flow"
Expand All @@ -22,9 +21,7 @@ import (

// transactionStatusesArguments contains the arguments required for subscribing to transaction statuses
type transactionStatusesArguments struct {
TxID flow.Identifier // ID of the transaction to monitor.
StartBlockID flow.Identifier // ID of the block to start subscription from
StartBlockHeight uint64 // Height of the block to start subscription from
TxID flow.Identifier // ID of the transaction to monitor.
}

// TransactionStatusesDataProvider is responsible for providing tx statuses
Expand Down Expand Up @@ -86,15 +83,7 @@ func (p *TransactionStatusesDataProvider) createSubscription(
ctx context.Context,
args transactionStatusesArguments,
) subscription.Subscription {
if args.StartBlockID != flow.ZeroID {
return p.api.SubscribeTransactionStatusesFromStartBlockID(ctx, args.TxID, args.StartBlockID, entities.EventEncodingVersion_JSON_CDC_V0)
}

if args.StartBlockHeight != request.EmptyHeight {
return p.api.SubscribeTransactionStatusesFromStartHeight(ctx, args.TxID, args.StartBlockHeight, entities.EventEncodingVersion_JSON_CDC_V0)
}

return p.api.SubscribeTransactionStatusesFromLatest(ctx, args.TxID, entities.EventEncodingVersion_JSON_CDC_V0)
return p.api.SubscribeTransactionStatuses(ctx, args.TxID, entities.EventEncodingVersion_JSON_CDC_V0)
}

// handleResponse processes a tx statuses and sends the formatted response.
Expand Down Expand Up @@ -130,14 +119,6 @@ func parseTransactionStatusesArguments(
) (transactionStatusesArguments, error) {
var args transactionStatusesArguments

// Parse block arguments
startBlockID, startBlockHeight, err := ParseStartBlock(arguments)
if err != nil {
return args, err
}
args.StartBlockID = startBlockID
args.StartBlockHeight = startBlockHeight

if txIDIn, ok := arguments["tx_id"]; ok && txIDIn != "" {
result, ok := txIDIn.(string)
if !ok {
Expand Down
Loading
Loading