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

feat/ibc_core_channel_module_queries #318

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

aarmoa
Copy link
Collaborator

@aarmoa aarmoa commented Apr 12, 2024

  • Added support for IBC Core Channel module queries
  • Added unit tests
  • Added example scripts

Solves CHAIN-77

Summary by CodeRabbit

  • New Features
    • Added functionality to query IBC channels, including specific channel information, client and consensus states, packet commitments, receipts, acknowledgements, unreceived packets, and next sequence receives using an asynchronous client.
    • Introduced new test cases and servicers for IBC channel queries via gRPC, enhancing the ability to fetch and test various IBC channel-related information.
  • Refactor
    • Updated import paths and class names in test files to align with new module structures and naming conventions.
  • Documentation
    • Enhanced inline documentation for new functionalities related to IBC channel queries and test implementations.

@aarmoa aarmoa requested a review from nicolasbaum April 12, 2024 19:51
Copy link
Contributor

coderabbitai bot commented Apr 12, 2024

Walkthrough

The recent updates introduce a comprehensive suite of functionalities for querying IBC channels using asynchronous clients in the Injective Protocol network. Enhancements include new scripts for querying various IBC channel states, packet commitments, and acknowledgements, alongside significant additions to the pyinjective module to support these operations. The changes streamline interactions with IBC channels and improve the testing framework for these functionalities.

Changes

Files Change Summary
examples/chain_client/ibc/channel/query/1_Channel.py to examples/.../query/13_NextSequenceReceive.py Introduces new functionalities for querying IBC channels, packets, and states using asynchronous clients.
pyinjective/async_client.py, pyinjective/core/ibc/channel/grpc/ibc_channel_grpc_api.py Updated and added new methods for IBC channel interactions; introduced IBCChannelGrpcApi class.
tests/core/ibc/channel/grpc/configurable_ibc_channel_query_servicer.py, tests/core/ibc/channel/grpc/test_ibc_channel_grpc_api.py New testing classes and cases for IBC channel queries and interactions.
tests/core/ibc/transfer/grpc/test_ibc_transfer_grpc_api.py, tests/core/tendermint/grpc/test_tendermint_grpc_api.py, tests/test_async_client_deprecation_warnings.py Updated import paths and class names reflecting new module structures and functionalities.

🐇💻
To the rhythm of code, under the moon's glow,
New queries awake, through networks they flow.
Channels and packets, in async delight,
A rabbit hops through, with tests shining bright.
Celebrate the code, for it leaps and bounds,
In the digital fields, where data surrounds. 🌟🌌


Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 3165d58 and 5207456.
Files selected for processing (20)
  • examples/chain_client/ibc/channel/query/10_PacketAcknowledgements.py (1 hunks)
  • examples/chain_client/ibc/channel/query/11_UnreceivedPackets.py (1 hunks)
  • examples/chain_client/ibc/channel/query/12_UnreceivedAcks.py (1 hunks)
  • examples/chain_client/ibc/channel/query/13_NextSequenceReceive.py (1 hunks)
  • examples/chain_client/ibc/channel/query/1_Channel.py (1 hunks)
  • examples/chain_client/ibc/channel/query/2_Channels.py (1 hunks)
  • examples/chain_client/ibc/channel/query/3_ConnectionChannels.py (1 hunks)
  • examples/chain_client/ibc/channel/query/4_ChannelClientState.py (1 hunks)
  • examples/chain_client/ibc/channel/query/5_ChannelConsensusState.py (1 hunks)
  • examples/chain_client/ibc/channel/query/6_PacketCommitment.py (1 hunks)
  • examples/chain_client/ibc/channel/query/7_PacketCommitments.py (1 hunks)
  • examples/chain_client/ibc/channel/query/8_PacketReceipt.py (1 hunks)
  • examples/chain_client/ibc/channel/query/9_PacketAcknowledgement.py (1 hunks)
  • pyinjective/async_client.py (5 hunks)
  • pyinjective/core/ibc/channel/grpc/ibc_channel_grpc_api.py (1 hunks)
  • tests/core/ibc/channel/grpc/configurable_ibc_channel_query_servicer.py (1 hunks)
  • tests/core/ibc/channel/grpc/test_ibc_channel_grpc_api.py (1 hunks)
  • tests/core/ibc/transfer/grpc/test_ibc_transfer_grpc_api.py (1 hunks)
  • tests/core/tendermint/grpc/test_tendermint_grpc_api.py (1 hunks)
  • tests/test_async_client_deprecation_warnings.py (1 hunks)
Additional comments not posted (25)
examples/chain_client/ibc/channel/query/1_Channel.py (1)

1-22: The script 1_Channel.py is well-structured for querying a specific IBC channel. It correctly sets up an asynchronous client and fetches the channel details using the provided port_id and channel_id. The use of print for output is appropriate for an example script. Ensure that the AsyncClient and Network classes handle exceptions appropriately to avoid unhandled errors during network communication.

examples/chain_client/ibc/channel/query/4_ChannelClientState.py (1)

1-22: The script 4_ChannelClientState.py effectively queries the client state of a specific IBC channel. It follows a similar structure to other query scripts, ensuring consistency across examples. As with the previous script, ensure that error handling is robust in the AsyncClient and Network classes to manage potential issues during network interactions.

examples/chain_client/ibc/channel/query/12_UnreceivedAcks.py (1)

1-25: The script 12_UnreceivedAcks.py is structured to query unreceived acknowledgments for a specific IBC channel, maintaining consistency with other example scripts. It is crucial to ensure that the AsyncClient class handles potential exceptions during the data fetching process to prevent crashes or unhandled errors.

examples/chain_client/ibc/channel/query/2_Channels.py (1)

1-22: The script 2_Channels.py effectively queries multiple IBC channels using pagination, which is a useful feature for managing large sets of data. The introduction of the PaginationOption class is appropriate for this purpose. Ensure that the pagination parameters are validated within the AsyncClient class to avoid issues like negative values or excessively large limits.

examples/chain_client/ibc/channel/query/13_NextSequenceReceive.py (1)

1-25: The script 13_NextSequenceReceive.py is structured to query the next sequence receive for a specific IBC channel, maintaining consistency with other example scripts. It is crucial to ensure that the AsyncClient class handles potential exceptions during the data fetching process to prevent crashes or unhandled errors.

examples/chain_client/ibc/channel/query/8_PacketReceipt.py (1)

1-23: The script 8_PacketReceipt.py effectively queries a packet receipt for a specific IBC channel and sequence number. It maintains consistency with other example scripts and correctly handles the asynchronous operations. As with other scripts, ensure that the AsyncClient class has robust error handling to manage potential issues during network interactions.

examples/chain_client/ibc/channel/query/6_PacketCommitment.py (1)

1-23: The script 6_PacketCommitment.py effectively queries a packet commitment for a specific IBC channel and sequence number. It maintains consistency with other example scripts and correctly handles the asynchronous operations. As with other scripts, ensure that the AsyncClient class has robust error handling to manage potential issues during network interactions.

examples/chain_client/ibc/channel/query/9_PacketAcknowledgement.py (1)

1-25: The script 9_PacketAcknowledgement.py effectively queries a packet acknowledgement for a specific IBC channel and sequence number. It maintains consistency with other example scripts and correctly handles the asynchronous operations. As with other scripts, ensure that the AsyncClient class has robust error handling to manage potential issues during network interactions.

examples/chain_client/ibc/channel/query/11_UnreceivedPackets.py (1)

1-25: The script 11_UnreceivedPackets.py is well-structured and follows Python async conventions. The use of asyncio and asynchronous calls to fetch_ibc_unreceived_packets are appropriate for non-blocking I/O operations. The script is simple and demonstrates the functionality effectively.

examples/chain_client/ibc/channel/query/3_ConnectionChannels.py (1)

1-23: The script 3_ConnectionChannels.py effectively demonstrates the use of pagination in querying connection channels. The structure is consistent with other scripts in the series, using asynchronous programming practices appropriately.

examples/chain_client/ibc/channel/query/5_ChannelConsensusState.py (1)

1-26: The script 5_ChannelConsensusState.py is correctly implemented for fetching the consensus state of an IBC channel. The inclusion of revision details (number and height) is a good practice for precise queries.

examples/chain_client/ibc/channel/query/7_PacketCommitments.py (1)

1-28: The script 7_PacketCommitments.py effectively uses pagination to query packet commitments. The asynchronous structure and clear use of the pagination model ensure that the script is both efficient and easy to understand.

examples/chain_client/ibc/channel/query/10_PacketAcknowledgements.py (1)

1-30: The script 10_PacketAcknowledgements.py is well-implemented, combining sequence numbers and pagination to fetch packet acknowledgements. This approach is efficient for handling potentially large data sets in a scalable manner.

tests/core/ibc/channel/grpc/configurable_ibc_channel_query_servicer.py (1)

1-81: The ConfigurableIBCChannelQueryServicer class is well-designed for testing purposes. Using deque for response storage is a good choice due to its fast append and pop operations. This setup allows for easy manipulation of response data in tests.

tests/core/ibc/transfer/grpc/test_ibc_transfer_grpc_api.py (1)

4-23: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-20]

The updates in test_ibc_transfer_grpc_api.py correctly reflect the new import paths and class names. The tests are well-structured and cover a variety of scenarios, ensuring the robustness of the IBC transfer functionalities.

pyinjective/core/ibc/channel/grpc/ibc_channel_grpc_api.py (1)

1-170: The IBCChannelGrpcApi class in ibc_channel_grpc_api.py is well-implemented, providing a robust interface for querying IBC channel data. The use of optional pagination and handling of various query types is done efficiently. The methods are asynchronous, which is suitable for the I/O operations performed.

tests/core/tendermint/grpc/test_tendermint_grpc_api.py (2)

8-8: Update import path to reflect new module structure.

The import path for TendermintGrpcApi has been updated to reflect the new module structure, aligning with the reorganization of the codebase.


13-13: Update import path for ConfigurableTendermintQueryServicer.

The import path for ConfigurableTendermintQueryServicer has been updated to match the new directory structure. This change is part of the broader refactoring effort to improve code organization.

tests/core/ibc/channel/grpc/test_ibc_channel_grpc_api.py (2)

8-8: Update import path to reflect new module structure.

The import path for IBCChannelGrpcApi has been updated to reflect the new module structure, aligning with the reorganization of the codebase.


16-16: Update import path for ConfigurableIBCChannelQueryServicer.

The import path for ConfigurableIBCChannelQueryServicer has been updated to match the new directory structure. This change is part of the broader refactoring effort to improve code organization.

tests/test_async_client_deprecation_warnings.py (1)

37-37: The import statement for ConfigurableTendermintQueryServicer has been updated to reflect its new location. Ensure that all references to this class in the file have been updated accordingly.

pyinjective/async_client.py (4)

39-39: Ensure that the new import IBCChannelGrpcApi is used within the file to justify its inclusion.

Verification successful

The verification script has confirmed that the import IBCChannelGrpcApi is indeed used within the async_client.py file. The class IBCChannelGrpcApi is not only imported but also instantiated within the file, which justifies its inclusion in the import statements. This aligns with the requirement to ensure that newly added imports are utilized in the code, thereby validating the change made in the pull request.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of IBCChannelGrpcApi in async_client.py
rg --type py "IBCChannelGrpcApi" ./pyinjective/async_client.py

Length of output: 197


40-40: Ensure that the new import IBCTransferGrpcApi is used within the file to justify its inclusion.

Verification successful

The review comment asked to verify whether the newly imported IBCTransferGrpcApi is being used within the async_client.py file. The script output confirms that IBCTransferGrpcApi is not only imported but also instantiated within the file (self.ibc_transfer_api = IBCTransferGrpcApi(...)). This usage justifies the inclusion of the import in the file.

Based on this information, the review comment is verified as the import is appropriately used within the file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of IBCTransferGrpcApi in async_client.py
rg --type py "IBCTransferGrpcApi" ./pyinjective/async_client.py

Length of output: 203


43-43: Ensure that the new import TendermintGrpcApi is used within the file to justify its inclusion.

Verification successful

The verification process aimed to confirm whether the newly imported TendermintGrpcApi class is utilized within the async_client.py file. The search results from the rg command indicate that TendermintGrpcApi is not only imported but also instantiated within the file. This confirms that the import is justified as the class is actively used in the code.

Based on this information, the review comment is consistent with the codebase, and the import of TendermintGrpcApi is indeed utilized appropriately in async_client.py.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of TendermintGrpcApi in async_client.py
rg --type py "TendermintGrpcApi" ./pyinjective/async_client.py

Length of output: 194


192-195: The instantiation of IBCChannelGrpcApi is correctly placed within the AsyncClient constructor. Ensure that the cookie_assistant from the network object is properly handled in the IBCChannelGrpcApi class to maintain session integrity.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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.

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: 1

Actionable comments outside the diff hunks (1)
tests/test_async_client_deprecation_warnings.py (1)

Line range hint 589-589: The method test_stream_keepalive_deprecation_warning is redefined, which could lead to unexpected behavior as the first definition will be ignored. Consider renaming or removing one of the definitions to resolve this issue.

-    async def test_stream_keepalive_deprecation_warning(
+    async def test_stream_keepalive_deprecation_warning_redefined(

Comment on lines +3048 to +3128
async def fetch_ibc_channel(self, port_id: str, channel_id: str) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_channel(port_id=port_id, channel_id=channel_id)

async def fetch_ibc_channels(self, pagination: Optional[PaginationOption] = None) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_channels(pagination=pagination)

async def fetch_ibc_connection_channels(
self, connection: str, pagination: Optional[PaginationOption] = None
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_connection_channels(connection=connection, pagination=pagination)

async def fetch_ibc_channel_client_state(self, port_id: str, channel_id: str) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_channel_client_state(port_id=port_id, channel_id=channel_id)

async def fetch_ibc_channel_consensus_state(
self,
port_id: str,
channel_id: str,
revision_number: int,
revision_height: int,
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_channel_consensus_state(
port_id=port_id,
channel_id=channel_id,
revision_number=revision_number,
revision_height=revision_height,
)

async def fetch_ibc_packet_commitment(self, port_id: str, channel_id: str, sequence: int) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_packet_commitment(
port_id=port_id, channel_id=channel_id, sequence=sequence
)

async def fetch_ibc_packet_commitments(
self, port_id: str, channel_id: str, pagination: Optional[PaginationOption] = None
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_packet_commitments(
port_id=port_id, channel_id=channel_id, pagination=pagination
)

async def fetch_ibc_packet_receipt(self, port_id: str, channel_id: str, sequence: int) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_packet_receipt(
port_id=port_id, channel_id=channel_id, sequence=sequence
)

async def fetch_ibc_packet_acknowledgement(self, port_id: str, channel_id: str, sequence: int) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_packet_acknowledgement(
port_id=port_id, channel_id=channel_id, sequence=sequence
)

async def fetch_ibc_packet_acknowledgements(
self,
port_id: str,
channel_id: str,
packet_commitment_sequences: Optional[List[int]] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_packet_acknowledgements(
port_id=port_id,
channel_id=channel_id,
packet_commitment_sequences=packet_commitment_sequences,
pagination=pagination,
)

async def fetch_ibc_unreceived_packets(
self, port_id: str, channel_id: str, packet_commitment_sequences: Optional[List[int]] = None
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_unreceived_packets(
port_id=port_id, channel_id=channel_id, packet_commitment_sequences=packet_commitment_sequences
)

async def fetch_ibc_unreceived_acks(
self, port_id: str, channel_id: str, packet_ack_sequences: Optional[List[int]] = None
) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_unreceived_acks(
port_id=port_id, channel_id=channel_id, packet_ack_sequences=packet_ack_sequences
)

async def fetch_next_sequence_receive(self, port_id: str, channel_id: str) -> Dict[str, Any]:
return await self.ibc_channel_api.fetch_next_sequence_receive(port_id=port_id, channel_id=channel_id)

Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The additional verification script searched for unit tests related to other IBC channel methods in async_client.py. The output indicates the presence of a test named test_fetch_ibc_transfer_txs within a file related to the gRPC explorer API. However, this test does not appear to be directly related to the newly added methods in async_client.py that handle various IBC channel queries.

Given the results from both scripts, it seems that there are no specific unit tests for the newly added IBC channel methods in async_client.py. This lack of tests could pose a risk to the stability and reliability of these methods, as comprehensive testing is crucial for ensuring that the methods handle different scenarios and error conditions effectively.

Therefore, it is recommended to implement unit tests for these new methods to ensure their functionality and robustness are thoroughly validated.

Analysis chain

The newly added methods for IBC channel queries are well-structured and follow the async pattern. Ensure comprehensive unit tests cover these methods to validate their functionality against a range of input scenarios and error conditions.


The verification script aimed to check for the presence of unit tests for the newly added IBC channel methods in async_client.py by searching for the string "test_fetch_ibc_channel" within the ./tests/ directory. The script did not produce any output, indicating that no tests matching this description were found.

Given the absence of detected unit tests for these methods, it is crucial to ensure that comprehensive testing is implemented to verify the functionality and robustness of these new methods. This is especially important as these methods handle network operations and data fetching, which are critical components and prone to various edge cases and error conditions.

To further verify the presence of tests for other related methods or to ensure that no relevant tests were overlooked due to naming conventions or file locations, I will run an additional script to search for tests related to other IBC channel methods.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for the presence of unit tests for the new IBC channel methods in async_client.py
rg --type py "test_fetch_ibc_channel" ./tests/

Length of output: 46



Script:

#!/bin/bash
# Check for the presence of unit tests for other IBC channel methods in async_client.py
rg --type py "test_fetch_ibc_" ./tests/

Length of output: 144

@aarmoa aarmoa merged commit 72407b4 into dev Apr 15, 2024
12 checks passed
@aarmoa aarmoa deleted the feat/ibc_core_channel_module_queries branch April 15, 2024 13:24
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