-
Notifications
You must be signed in to change notification settings - Fork 179
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] Improvements for SubscribeTransactionStatuses
statuses handling
#6736
Open
Guitarheroua
wants to merge
10
commits into
onflow:master
Choose a base branch
from
The-K-R-O-K:AndriiSlisarchuk/6574-improve-tx-sub-statuses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−44
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2e8d95b
change tx result retrieving
Guitarheroua de3851a
Fixed unit tests
Guitarheroua dfb40cf
Merge branch 'master' into AndriiSlisarchuk/6574-improve-tx-sub-statuses
Guitarheroua edb0636
fixed comment
Guitarheroua 23a2214
simplify unit test
Guitarheroua e3a43a0
remove second block extraction
Guitarheroua ef8136d
removed unnecessary comment
Guitarheroua 543fb9e
added missing documentation
Guitarheroua 9ee3d6a
Merge branch 'master' into AndriiSlisarchuk/6574-improve-tx-sub-statuses
Guitarheroua b49bb7c
Merge branch 'master' into AndriiSlisarchuk/6574-improve-tx-sub-statuses
Guitarheroua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ type backendSubscribeTransactions struct { | |
type TransactionSubscriptionMetadata struct { | ||
*access.TransactionResult | ||
txReferenceBlockID flow.Identifier | ||
blockWithTx *flow.Header | ||
blockWithTx *flow.Block | ||
txExecuted bool | ||
eventEncodingVersion entities.EventEncodingVersion | ||
} | ||
|
@@ -126,7 +126,7 @@ func (b *backendSubscribeTransactions) getTransactionStatusResponse(txInfo *Tran | |
// When a block with the transaction is available, it is possible to receive a new transaction status while | ||
// searching for the transaction result. Otherwise, it remains unchanged. So, if the old and new transaction | ||
// statuses are the same, the current transaction status should be retrieved. | ||
txInfo.Status, err = b.txLocalDataProvider.DeriveTransactionStatus(txInfo.blockWithTx.Height, txInfo.txExecuted) | ||
txInfo.Status, err = b.txLocalDataProvider.DeriveTransactionStatus(txInfo.BlockHeight, txInfo.txExecuted) | ||
} | ||
if err != nil { | ||
if !errors.Is(err, state.ErrUnknownSnapshotReference) { | ||
|
@@ -229,7 +229,7 @@ func (b *backendSubscribeTransactions) checkBlockReady(height uint64) error { | |
func (b *backendSubscribeTransactions) searchForTransactionBlockInfo( | ||
height uint64, | ||
txInfo *TransactionSubscriptionMetadata, | ||
) (*flow.Header, flow.Identifier, uint64, flow.Identifier, error) { | ||
) (*flow.Block, flow.Identifier, uint64, flow.Identifier, error) { | ||
block, err := b.txLocalDataProvider.blocks.ByHeight(height) | ||
if err != nil { | ||
return nil, flow.ZeroID, 0, flow.ZeroID, fmt.Errorf("error looking up block: %w", err) | ||
|
@@ -241,37 +241,34 @@ func (b *backendSubscribeTransactions) searchForTransactionBlockInfo( | |
} | ||
|
||
if collectionID != flow.ZeroID { | ||
return block.Header, block.ID(), height, collectionID, nil | ||
return block, block.ID(), height, collectionID, nil | ||
} | ||
|
||
return nil, flow.ZeroID, 0, flow.ZeroID, nil | ||
} | ||
|
||
// searchForTransactionResult searches for the transaction result of a block. It retrieves the execution result for the specified block ID. | ||
// Expected errors: | ||
// - codes.Internal if an internal error occurs while retrieving execution result. | ||
// searchForTransactionResult searches for the transaction result of a block. It retrieves the transaction result from | ||
// storage and, in case of failure, attempts to fetch the transaction result directly from the execution node. | ||
// This is necessary to ensure data availability despite sync storage latency. | ||
// | ||
// No errors expected during normal operations. | ||
func (b *backendSubscribeTransactions) searchForTransactionResult( | ||
ctx context.Context, | ||
txInfo *TransactionSubscriptionMetadata, | ||
) (*access.TransactionResult, error) { | ||
_, err := b.executionResults.ByBlockID(txInfo.BlockID) | ||
txResult, err := b.backendTransactions.GetTransactionResultFromStorage(ctx, txInfo.blockWithTx, txInfo.TransactionID, txInfo.eventEncodingVersion) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: return the successful response here |
||
if errors.Is(err, storage.ErrNotFound) { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("failed to get execution result for block %s: %w", txInfo.BlockID, err) | ||
// If any error occurs with local storage - request transaction result from EN | ||
txResult, err = b.backendTransactions.GetTransactionResultFromExecutionNode( | ||
ctx, | ||
txInfo.blockWithTx, | ||
txInfo.TransactionID, | ||
txInfo.eventEncodingVersion, | ||
) | ||
} | ||
|
||
txResult, err := b.backendTransactions.GetTransactionResult( | ||
ctx, | ||
txInfo.TransactionID, | ||
txInfo.BlockID, | ||
txInfo.CollectionID, | ||
txInfo.eventEncodingVersion, | ||
) | ||
|
||
if err != nil { | ||
// if either the storage or execution node reported no results or there were not enough execution results | ||
// if either the storage or execution node reported no results | ||
if status.Code(err) == codes.NotFound { | ||
// No result yet, indicate that it has not been executed | ||
return nil, nil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if local indexing/execution sync is not enabled?