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 api subscription endpoints #58

Merged
merged 26 commits into from
Aug 1, 2024
Merged

Conversation

lealobanov
Copy link
Collaborator

@lealobanov lealobanov commented Jun 21, 2024

Description

Access api subscription endpoints

  • SubscribeExecutionDataByBlockID
  • SubscribeExecutionDataByBlockHeight
  • SubscribeEventsByBlockID
  • SubscribeEventsByBlockHeight
  • Create structs for ExecutionData API
  • Updates to tests

ExecutionData fields: https://github.com/onflow/flow/blob/3d7cfcfd52ac2532ebe244f9f66ecc8d76bd9fed/protobuf/flow/entities/block_execution_data.proto


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced transaction and execution result retrieval capabilities with new methods for accessing data by block ID and block height.
    • Subscription functionality added for execution data and events based on block ID and height, enabling real-time updates.
    • Added support for asynchronous programming through new coroutine dependencies.
  • Bug Fixes

    • Improved error handling and response validation in transaction retrieval and subscription methods.
  • Tests

    • Added comprehensive test cases for new functionalities, ensuring robust coverage of transaction retrieval and event subscriptions.

Copy link
Contributor

coderabbitai bot commented Jun 21, 2024

Walkthrough

The recent updates significantly enhance the Flow SDK, focusing on asynchronous programming and improved data access. Key changes include the introduction of new subscription methods for execution data and events based on block ID and height. The integration of Kotlin coroutines streamlines concurrent processing, boosting the SDK's efficiency and usability while enabling real-time data handling.

Changes

Files Change Summary
sdk/build.gradle.kts Added dependencies for Kotlin coroutines (1.5.2), enhancing asynchronous capabilities.
sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt Updated newAccessApi to handle an additional ExecutionDataAPIGrpc parameter for enhanced functionality.
sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt, sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt Introduced methods for subscribing to execution data and events based on block ID and height, improving real-time data access.
sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt, sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt Expanded test suites, adding tests for new subscription functionalities in both access APIs.

Poem

A Rabbit's Poem:

🐇 In fields of code where bunnies hop,
New methods bloom, we never stop.
With coroutines swift, our tasks delight,
As transactions dance in the moonlight.
Hooray for changes, bright and clear,
The Flow SDK shines, let’s give a cheer! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lealobanov lealobanov changed the base branch from main to access-api-remove-null-returns June 21, 2024 14:04
Copy link

github-actions bot commented Jun 21, 2024

Unit Test Results

  53 files  ±  0    53 suites  ±0   23s ⏱️ ±0s
310 tests +12  310 ✔️ +12  0 💤 ±0  0 ❌ ±0 

Results for commit 10f1de8. ± Comparison against base commit 2feb1f7.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 21, 2024

Integration Test Results

2 files   -   3  2 suites   - 3   12s ⏱️ - 1m 39s
2 tests  - 29  2 ✔️  - 29  0 💤 ±0  0 ❌ ±0 

Results for commit 10f1de8. ± Comparison against base commit 2feb1f7.

This pull request removes 31 and adds 2 tests. Note that renamed tests count towards both.
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ Can parse new JSON Cadence()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeArray()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeBoolean()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeComplexDict()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeEnum()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeOptional()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeOptional2()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeReference()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeResource()
org.onflow.flow.sdk.cadence.JsonCadenceTest ‑ decodeStruct()
…
org.onflow.flow.common.extensions.ProjectTestExtensionsTest ‑ Test extensions work()
org.onflow.flow.sdk.extensions.TestExtensionsTest ‑ Test extensions work()

♻️ This comment has been updated with latest results.

@lealobanov lealobanov changed the base branch from access-api-remove-null-returns to access-api-methods-v2 June 22, 2024 12:06
@lealobanov lealobanov changed the base branch from access-api-methods-v2 to access-api-methods-v3 July 6, 2024 12:49
@lealobanov lealobanov changed the title WIP: Access api subscription endpoints Access api subscription endpoints Jul 8, 2024
@lealobanov lealobanov marked this pull request as ready for review July 8, 2024 15:17
@franklywatson franklywatson requested a review from jribbink July 8, 2024 22:02
Base automatically changed from access-api-methods-v3 to access-api-methods-v2 July 15, 2024 16:05
@lealobanov lealobanov changed the base branch from access-api-methods-v2 to main July 16, 2024 11:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
src/main/kotlin/org/onflow/flow/sdk/Flow.kt (1)

51-52: Function calls to newAccessApi need to be updated to handle the new parameter.

The following files have calls to newAccessApi that need to be updated to include the new parameter for ExecutionDataAPIGrpc.newBlockingStub(channel):

  • src/testFixtures/kotlin/org/onflow/flow/sdk/test/FlowTestUtil.kt
  • src/testFixtures/kotlin/org/onflow/flow/sdk/test/AbstractFlowEmulatorExtension.kt
  • src/test/kotlin/org/onflow/flow/sdk/TestUtils.kt
  • src/intTest/org/onflow/flow/sdk/IntegrationTestUtils.kt

Please update these calls to match the new function signature.

Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to newAccessApi are updated to handle the new parameter.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `newAccessApi` handle the new parameter.

# Test: Search for the function usage. Expect: Only occurances of the updated function signature.
rg --type kotlin -A 5 $'newAccessApi'

Length of output: 3577

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 099bea9 and 92d359b.

Files selected for processing (4)
  • build.gradle.kts (2 hunks)
  • src/main/kotlin/org/onflow/flow/sdk/Flow.kt (2 hunks)
  • src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (2 hunks)
  • src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • build.gradle.kts
  • src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
Additional comments not posted (14)
src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (14)

47-48: LGTM!

The addition of the new mock for ExecutionDataAPIGrpc.ExecutionDataAPIBlockingStub is appropriate and correctly implemented.


334-343: LGTM!

The test function getTransactionsByBlockId correctly validates the retrieval of transactions by block ID.


346-361: LGTM!

The test function getTransactionsByBlockId with multiple results correctly validates the retrieval of multiple transactions by block ID.


364-373: LGTM!

The test function getTransactionResultsByBlockId correctly validates the retrieval of transaction results by block ID.


376-391: LGTM!

The test function getTransactionResultsByBlockId with multiple results correctly validates the retrieval of multiple transaction results by block ID.


394-410: LGTM!

The test function getExecutionResultByBlockId correctly validates the retrieval of execution results by block ID.


420-448: LGTM!

The test function subscribeExecutionDataByBlockHeight success case correctly validates the subscription to execution data by block height in a successful scenario.


451-479: LGTM!

The test function subscribeExecutionDataByBlockHeight error case correctly validates the subscription to execution data by block height in an error scenario.


482-510: LGTM!

The test function subscribeEventsByBlockId success case correctly validates the subscription to events by block ID in a successful scenario.


513-541: LGTM!

The test function subscribeEventsByBlockId error case correctly validates the subscription to events by block ID in an error scenario.


544-572: LGTM!

The test function subscribeEventsByBlockHeight success case correctly validates the subscription to events by block height in a successful scenario.


575-603: LGTM!

The test function subscribeEventsByBlockHeight error case correctly validates the subscription to events by block height in an error scenario.


606-634: LGTM!

The test function subscribeExecutionDataByBlockId success case correctly validates the subscription to execution data by block ID in a successful scenario.


637-665: LGTM!

The test function subscribeExecutionDataByBlockId error case correctly validates the subscription to execution data by block ID in an error scenario.


when (val result = flowAccessApiImpl.subscribeExecutionDataByBlockHeight(blockHeight)) {
is FlowAccessApi.AccessApiCallResponse.Success -> {
fail("Expected error but got success")
val (_, errorChannel) = result.data
Copy link
Collaborator Author

@lealobanov lealobanov Jul 25, 2024

Choose a reason for hiding this comment

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

@jribbink after switching the implementation to be fully non-blocking the result of the error channel is fed through FlowAccessApi.AccessApiCallResponse.Success which is not ideal.

I was playing around with a few different options of how to handle this, but I think we would be forced to add a blocking step to the function, e.g. something along the lines of

var receivedException: Throwable? = null
        runBlocking {
            // Try to receive from the error channel
            try {
                receivedException = errorChannel.receive()
            } catch (e: ClosedReceiveChannelException) {
                // No errors
            }
        }

        if (receivedException != null) {
            FlowAccessApi.AccessApiCallResponse.Error("Failed to subscribe execution data by block height", receivedException)
        } else {
            FlowAccessApi.AccessApiCallResponse.Success(responseChannel to errorChannel)
        }

which is not what we want to have. Let me know what you think - thanks!

Choose a reason for hiding this comment

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

I think that wrapping this response in a FlowAccessApi.AccessApiCallResponse is probably just redundant here since for these streams we have the error channel anyways. It implies a success/failure state when it will always return "Success" anyways with this implementation.

Copy link

github-actions bot commented Jul 25, 2024

SDK Examples Unit Test Results

2 files  2 suites   34s ⏱️
6 tests 6 ✔️ 0 💤 0 ❌

Results for commit 10f1de8.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 92d359b and 21708dc.

Files selected for processing (8)
  • sdk/build.gradle.kts (1 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/AsyncFlowAccessApiImpl.kt (1 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt (13 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt (2 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (2 hunks)
Files skipped from review due to trivial changes (1)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/AsyncFlowAccessApiImpl.kt
Additional comments not posted (33)
sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt (4)

76-78: LGTM! But verify the function implementation.

The code changes are approved.

However, ensure that the function is implemented correctly and that error handling is in place.

Verification successful

The previous search did not yield any results. Let's adjust our search pattern to ensure we capture the correct function implementation and search again.


LGTM! The function subscribeEventsByBlockHeight is implemented correctly with proper error handling.

  • The implementation in sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt creates response and error channels.
  • It uses a coroutine to handle asynchronous event subscription.
  • Exceptions are caught, and channels are closed in the finally block to ensure resource cleanup.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `subscribeEventsByBlockHeight`.

# Test: Search for the function implementation. Expect: Proper implementation with error handling.
rg --type kotlin -A 10 $'fun subscribeEventsByBlockHeight(height: Long)'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the implementation of `subscribeEventsByBlockHeight`.

# Test: Search for the function implementation. Expect: Proper implementation with error handling.
rg --type kotlin -A 20 'fun subscribeEventsByBlockHeight'

Length of output: 2768


68-71: LGTM! But verify the function implementation.

The code changes are approved.

However, ensure that the function is implemented correctly and that error handling is in place.

Verification successful

LGTM! The function implementation is correct and includes error handling.

The function subscribeExecutionDataByBlockHeight is implemented in sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt with proper error handling using a try-catch block.

  • Implementation location: sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `subscribeExecutionDataByBlockHeight`.

# Test: Search for the function implementation. Expect: Proper implementation with error handling.
rg --type kotlin -A 10 $'fun subscribeExecutionDataByBlockHeight(height: Long)'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the implementation of `subscribeExecutionDataByBlockHeight`.

# Test: Search for the function implementation using ast-grep. Expect: Proper implementation with error handling.
ast-grep --lang kotlin --pattern $'fun subscribeExecutionDataByBlockHeight(height: Long): AccessApiCallResponse<Pair<ReceiveChannel<FlowBlockExecutionData>, ReceiveChannel<Throwable>>> {
  $$$
}'

Length of output: 196


Script:

#!/bin/bash
# Description: Verify the implementation of `subscribeExecutionDataByBlockHeight`.

# Test: Perform a broader search for the function name.
rg --type kotlin -A 10 'fun subscribeExecutionDataByBlockHeight'

Length of output: 2474


64-67: LGTM! But verify the function implementation.

The code changes are approved.

However, ensure that the function is implemented correctly and that error handling is in place.


72-75: LGTM! But verify the function implementation.

The code changes are approved.

However, ensure that the function is implemented correctly and that error handling is in place.

sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt (1)

51-52: LGTM! But verify the function implementation.

The code changes are approved.

However, ensure that the function is implemented correctly and that the coroutine scope is properly managed.

Verification successful

LGTM! But verify the function implementation.

The function newAccessApi is correctly implemented and the coroutine scope is properly managed.

  • sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `newAccessApi`.

# Test: Search for the function implementation. Expect: Proper implementation with coroutine scope management.
rg --type kotlin -A 10 $'fun newAccessApi(host: String, port: Int = 9000, secure: Boolean = false, userAgent: String = DEFAULT_USER_AGENT, maxMessageSize: Int = DEFAULT_MAX_MESSAGE_SIZE): FlowAccessApi'

Length of output: 203


Script:

#!/bin/bash
# Description: Verify the implementation of `newAccessApi`.

# Test: Search for the function implementation with a more general pattern.
rg --type kotlin -A 20 'fun newAccessApi'

Length of output: 2281

sdk/build.gradle.kts (3)

37-37: Approved: Added dependency for Kotlin coroutines core.

The addition of kotlinx-coroutines-core:1.5.2 is necessary for coroutine support in Kotlin.


38-38: Approved: Added dependency for Kotlin coroutines core JVM.

The addition of kotlinx-coroutines-core-jvm:1.5.2 is necessary for coroutine support in JVM-based Kotlin projects.


39-39: Approved: Added dependency for Kotlin coroutines Guava.

The addition of kotlinx-coroutines-guava:1.5.2 is necessary for coroutine support with Guava in Kotlin.

sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (5)

17-19: Constructor changes approved.

The addition of executionDataApi and coroutineScope parameters is necessary for the new subscription methods.


390-415: Method implementation approved.

The subscribeExecutionDataByBlockId method correctly handles errors, closes channels, and uses coroutines efficiently.

However, ensure that all function calls to subscribeExecutionDataByBlockId match the new implementation.

Verification successful

Method implementation approved.

The subscribeExecutionDataByBlockId method correctly handles errors, closes channels, and uses coroutines efficiently. The usage of the method in the test files FlowAccessApiTest.kt and FlowAccessApiImplTest.kt matches the new implementation.

  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt

These test cases cover both success and error scenarios, ensuring that the new implementation is thoroughly tested.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeExecutionDataByBlockId` match the new implementation.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type kotlin -A 5 $'subscribeExecutionDataByBlockId'

Length of output: 6872


472-497: Method implementation approved.

The subscribeEventsByBlockHeight method correctly handles errors, closes channels, and uses coroutines efficiently.

However, ensure that all function calls to subscribeEventsByBlockHeight match the new implementation.

Verification successful

Method implementation approved.

The subscribeEventsByBlockHeight method correctly handles errors, closes channels, and uses coroutines efficiently. The function calls in the test files FlowAccessApiTest.kt and FlowAccessApiImplTest.kt match the new implementation and comprehensively test various scenarios.

  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeEventsByBlockHeight` match the new implementation.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type kotlin -A 5 $'subscribeEventsByBlockHeight'

Length of output: 6501


445-470: Method implementation approved.

The subscribeEventsByBlockId method correctly handles errors, closes channels, and uses coroutines efficiently.

However, ensure that all function calls to subscribeEventsByBlockId match the new implementation.

Verification successful

Method implementation approved.

The subscribeEventsByBlockId method correctly handles errors, closes channels, and uses coroutines efficiently. The function calls to subscribeEventsByBlockId match the new implementation, and the tests cover both success and error cases.

  • FlowAccessApi.kt: Definition of subscribeEventsByBlockId.
  • FlowAccessApiImpl.kt: Implementation of subscribeEventsByBlockId.
  • FlowAccessApiTest.kt: Tests for subscribeEventsByBlockId.
  • FlowAccessApiImplTest.kt: Additional tests for subscribeEventsByBlockId.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeEventsByBlockId` match the new implementation.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type kotlin -A 5 $'subscribeEventsByBlockId'

Length of output: 6628


417-443: Method implementation approved.

The subscribeExecutionDataByBlockHeight method correctly handles errors, closes channels, and uses coroutines efficiently.

However, ensure that all function calls to subscribeExecutionDataByBlockHeight match the new implementation.

Verification successful

Method implementation approved.

The subscribeExecutionDataByBlockHeight method correctly handles errors, closes channels, and uses coroutines efficiently.

The function calls to subscribeExecutionDataByBlockHeight are consistent with the new implementation across the codebase. The method is being used and tested appropriately.

  • Instances found in sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt and sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt.
  • Tests found in sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt and sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeExecutionDataByBlockHeight` match the new implementation.

# Test: Search for the function usage. Expect: Only occurances of the new implementation.
rg --type kotlin -A 5 $'subscribeExecutionDataByBlockHeight'

Length of output: 6939

sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt (4)

332-372: Test case approved.

The Test subscribeExecutionDataByBlockId test case covers both success and error scenarios and uses coroutines correctly.


374-414: Test case approved.

The Test subscribeExecutionDataByBlockHeight test case covers both success and error scenarios and uses coroutines correctly.


417-456: Test case approved.

The Test subscribeEventsByBlockId test case covers both success and error scenarios and uses coroutines correctly.


458-498: Test case approved.

The Test subscribeEventsByBlockHeight test case covers both success and error scenarios and uses coroutines correctly.

sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (8)

419-448: Test case approved.

The Test subscribeExecutionDataByBlockHeight success case test case covers the success scenario and uses coroutines correctly.


450-479: Test case approved.

The Test subscribeExecutionDataByBlockHeight error case test case covers the error scenario and uses coroutines correctly.


481-510: Test case approved.

The Test subscribeEventsByBlockId success case test case covers the success scenario and uses coroutines correctly.


512-541: Test case approved.

The Test subscribeEventsByBlockId error case test case covers the error scenario and uses coroutines correctly.


543-572: Test case approved.

The Test subscribeEventsByBlockHeight success case test case covers the success scenario and uses coroutines correctly.


575-603: Test case approved.

The Test subscribeEventsByBlockHeight error case test case covers the error scenario and uses coroutines correctly.


605-634: Test case approved.

The Test subscribeExecutionDataByBlockId success case test case covers the success scenario and uses coroutines correctly.


636-665: Test case approved.

The Test subscribeExecutionDataByBlockId error case test case covers the error scenario and uses coroutines correctly.

sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt (8)

784-798: Ensure proper handling of grpcExecutionResult in FlowChunkExecutionData.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


800-830: Ensure proper handling of grpcExecutionResult in FlowTrieUpdate.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


832-858: Ensure proper handling of grpcExecutionResult in FlowPayload.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


860-886: Ensure proper handling of grpcExecutionResult in FlowKeyPart.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


888-901: Ensure proper handling of grpcExecutionResult in FlowExecutionDataTransactionResult.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


903-911: Ensure proper handling of grpcExecutionResult in FlowExecutionDataCollection.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


913-925: Ensure proper handling of grpcExecutionResult in FlowBlockExecutionData.

The of function in the companion object should handle potential null values and errors from grpcExecutionResult.

Ensure that grpcExecutionResult is always non-null and valid before calling this function. If not, consider adding null checks or error handling.


1087-1089: Ensure proper error handling in decodeToAny.

The decodeToAny function should handle potential errors during decoding.

Ensure that the decodeToAny function properly handles errors during decoding. If not, consider adding error handling.

Comment on lines +431 to +445
val signerList: List<FlowAddress>
get() {
val ret = mutableListOf<FlowAddress>()
val seen = mutableSetOf<FlowAddress>()
val addSigner = fun(address: FlowAddress) {
if (address in seen) {
return
}
ret.add(address)
seen.add(address)
}
ret.add(address)
seen.add(address)
addSigner(proposalKey.address)
addSigner(payerAddress)
authorizers.forEach(addSigner)
return ret
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve the performance of the signerList property.

The current implementation of signerList uses a mutable list and a set to track seen addresses, which can be optimized. Consider using a LinkedHashSet to maintain insertion order and eliminate duplicates in a single data structure.

val signerList: List<FlowAddress>
    get() {
        val seen = LinkedHashSet<FlowAddress>()
        seen.add(proposalKey.address)
        seen.add(payerAddress)
        seen.addAll(authorizers)
        return seen.toList()
    }

Comment on lines 448 to 453
val signerMap: Map<FlowAddress, Int>
get() {
return signerList.withIndex()
.map { it.value to it.index }
.toMap()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the signerMap property.

The current implementation of signerMap can be simplified by using the associateWith function.

val signerMap: Map<FlowAddress, Int>
    get() = signerList.withIndex().associate { it.value to it.index }

Comment on lines 306 to 312
val ret = this.events.filter {
if (exact) {
it.type == type
} else {
it.type.endsWith(type)
}
}.map { it.event }
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the getEventsOfType function.

The current implementation of getEventsOfType can be simplified by using the filter function directly.

val ret = this.events.filter {
    if (exact) it.type == type else it.type.endsWith(type)
}.map { it.event }

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 21708dc and be7cf19.

Files selected for processing (1)
  • sdk/build.gradle.kts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sdk/build.gradle.kts

Comment on lines 51 to 52
val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
return FlowAccessApiImpl(AccessAPIGrpc.newBlockingStub(channel), ExecutionDataAPIGrpc.newBlockingStub(channel), coroutineScope)

Choose a reason for hiding this comment

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

I believe that we should be passing the coroutineScope in on each individual subscription call instead so that the caller has control over the lifecycle of the subscription (i.e. can terminate it).

Comment on lines 417 to 419
override fun subscribeExecutionDataByBlockHeight(
height: Long
): FlowAccessApi.AccessApiCallResponse<Pair<ReceiveChannel<FlowBlockExecutionData>, ReceiveChannel<Throwable>>> {

Choose a reason for hiding this comment

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

e.g.

Suggested change
override fun subscribeExecutionDataByBlockHeight(
height: Long
): FlowAccessApi.AccessApiCallResponse<Pair<ReceiveChannel<FlowBlockExecutionData>, ReceiveChannel<Throwable>>> {
override fun subscribeExecutionDataByBlockHeight(
scope: CoroutineScope
height: Long,
): FlowAccessApi.AccessApiCallResponse<Pair<ReceiveChannel<FlowBlockExecutionData>, ReceiveChannel<Throwable>>> {

Copy link

@jribbink jribbink left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the previous feedback @lealobanov 🎉 . I just left a couple other comments.

@lealobanov
Copy link
Collaborator Author

Thank you, will follow up on these shortly!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between be7cf19 and 063810f.

Files selected for processing (7)
  • sdk/build.gradle.kts (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt (14 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt (2 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (2 hunks)
Files skipped from review due to trivial changes (1)
  • sdk/build.gradle.kts
Files skipped from review as they are similar to previous changes (1)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt
Additional comments not posted (25)
sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt (4)

65-69: LGTM!

The method subscribeExecutionDataByBlockId is correctly defined with appropriate parameters and return type.


70-74: LGTM!

The method subscribeExecutionDataByBlockHeight is correctly defined with appropriate parameters and return type.


75-79: LGTM!

The method subscribeEventsByBlockId is correctly defined with appropriate parameters and return type.


80-83: LGTM!

The method subscribeEventsByBlockHeight is correctly defined with appropriate parameters and return type.

sdk/src/main/kotlin/org/onflow/flow/sdk/Flow.kt (2)

14-14: LGTM!

The import statement for ExecutionDataAPIGrpc is necessary for the new functionality.


48-48: LGTM!

The method newAccessApi is correctly updated to include the new parameter for ExecutionDataAPIGrpc.

sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt (4)

332-373: LGTM!

The test case Test subscribeExecutionDataByBlockId is correctly defined and validates the subscription to execution data using a block ID.


375-416: LGTM!

The test case Test subscribeEventsByBlockId is correctly defined and validates the subscription to events using a block ID.


418-459: LGTM!

The test case Test subscribeEventsByBlockHeight is correctly defined and validates the subscription to events using a block height.


419-459: LGTM!

The test case Test subscribeExecutionDataByBlockHeight is correctly defined and validates the subscription to execution data using a block height.

sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (5)

17-18: Constructor update approved.

The constructor now correctly accepts an additional parameter executionDataApi.


417-444: Method subscribeExecutionDataByBlockHeight looks good.

The method correctly handles data and error channels using coroutines.

Verify the method usage in the codebase to ensure proper integration.

Verification successful

Method subscribeExecutionDataByBlockHeight is correctly integrated and used in the codebase.

  • The method's definition is consistent with the new signature in FlowAccessApi.kt.
  • The implementation in FlowAccessApiImpl.kt matches the expected behavior.
  • Test cases in FlowAccessApiImplTest.kt cover both success and error scenarios adequately.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeExecutionDataByBlockHeight` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin -A 5 $'subscribeExecutionDataByBlockHeight'

Length of output: 4588


446-472: Method subscribeEventsByBlockId looks good.

The method correctly handles data and error channels using coroutines.

Verify the method usage in the codebase to ensure proper integration.

Verification successful

Method subscribeEventsByBlockId usage is consistent.

The method subscribeEventsByBlockId is correctly used in the codebase with the new signature.

  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeEventsByBlockId` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin -A 5 $'subscribeEventsByBlockId'

Length of output: 6738


389-415: Method subscribeExecutionDataByBlockId looks good.

The method correctly handles data and error channels using coroutines.

Verify the method usage in the codebase to ensure proper integration.

Verification successful

Method subscribeExecutionDataByBlockId is correctly integrated.

The method signature is consistent across the codebase, including in the main implementation files and test cases.

  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeExecutionDataByBlockId` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin -A 5 $'subscribeExecutionDataByBlockId'

Length of output: 6982


474-500: Method subscribeEventsByBlockHeight looks good.

The method correctly handles data and error channels using coroutines.

Verify the method usage in the codebase to ensure proper integration.

Verification successful

Method subscribeEventsByBlockHeight is correctly integrated and tested.

The method is properly used across the codebase, and the tests cover both success and error scenarios.

  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `subscribeEventsByBlockHeight` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type kotlin -A 5 $'subscribeEventsByBlockHeight'

Length of output: 6689

sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (10)

4-9: Imports approved.

The new imports for testing coroutines and mock dependencies are necessary and correctly used.

Also applies to: 20-25


47-48: Setup method update approved.

The setup method correctly initializes the new mock dependency mockExecutionDataApi.


420-448: Test subscribeExecutionDataByBlockHeight success case approved.

The test correctly mocks the responses and validates the expected behavior.


451-479: Test subscribeExecutionDataByBlockHeight error case approved.

The test correctly mocks the responses and validates the expected error handling.


482-510: Test subscribeEventsByBlockId success case approved.

The test correctly mocks the responses and validates the expected behavior.


513-541: Test subscribeEventsByBlockId error case approved.

The test correctly mocks the responses and validates the expected error handling.


544-572: Test subscribeEventsByBlockHeight success case approved.

The test correctly mocks the responses and validates the expected behavior.


575-603: Test subscribeEventsByBlockHeight error case approved.

The test correctly mocks the responses and validates the expected error handling.


606-634: Test subscribeExecutionDataByBlockId success case approved.

The test correctly mocks the responses and validates the expected behavior.


637-665: Test subscribeExecutionDataByBlockId error case approved.

The test correctly mocks the responses and validates the expected error handling.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 063810f and 10f1de8.

Files selected for processing (5)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt (2 hunks)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt (13 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt (2 hunks)
  • sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • sdk/src/main/kotlin/org/onflow/flow/sdk/FlowAccessApi.kt
  • sdk/src/main/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImpl.kt
  • sdk/src/test/kotlin/org/onflow/flow/sdk/FlowAccessApiTest.kt
Additional comments not posted (16)
sdk/src/test/kotlin/org/onflow/flow/sdk/impl/FlowAccessApiImplTest.kt (8)

412-434: LGTM!

The test method successfully verifies the subscription to execution data by block height using mocks and coroutines.


436-457: LGTM!

The test method successfully verifies the error handling for subscription to execution data by block height using mocks and coroutines.


459-481: LGTM!

The test method successfully verifies the subscription to events by block ID using mocks and coroutines.


483-503: LGTM!

The test method successfully verifies the error handling for subscription to events by block ID using mocks and coroutines.


505-527: LGTM!

The test method successfully verifies the subscription to events by block height using mocks and coroutines.


529-549: LGTM!

The test method successfully verifies the error handling for subscription to events by block height using mocks and coroutines.


551-573: LGTM!

The test method successfully verifies the subscription to execution data by block ID using mocks and coroutines.


575-595: LGTM!

The test method successfully verifies the error handling for subscription to execution data by block ID using mocks and coroutines.

sdk/src/main/kotlin/org/onflow/flow/sdk/models.kt (8)

420-434: LGTM!

The refactoring of the signerList property improves readability without altering functionality.


436-438: LGTM!

The update to the signerMap property aligns with the new structure of signerList and maintains the existing functionality.


761-775: LGTM!

The new FlowChunkExecutionData data class enhances the SDK's capabilities for handling execution data.


777-807: LGTM!

The new FlowTrieUpdate data class enhances the SDK's capabilities for handling trie updates.


809-835: LGTM!

The new FlowPayload data class enhances the SDK's capabilities for handling payloads.


837-863: LGTM!

The new FlowKeyPart data class enhances the SDK's capabilities for handling key parts.


865-878: LGTM!

The new FlowExecutionDataTransactionResult data class enhances the SDK's capabilities for handling execution data transaction results.


880-902: LGTM!

The new FlowExecutionDataCollection and FlowBlockExecutionData data classes enhance the SDK's capabilities for handling execution data collections and block execution data.

@lealobanov lealobanov requested a review from jribbink July 31, 2024 16:59
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.

2 participants