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

Problem: packet_sequence is not indexed in relayer event #1318

Merged
merged 14 commits into from
Feb 19, 2024

Conversation

mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Feb 19, 2024

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

  • New Features
    • Enhanced event handling in smart contracts with additional indexed parameters for improved query efficiency and data organization.
    • Introduced the ability to specify the order of results in transaction searches.
  • Improvements
    • Improved the flexibility and accuracy of balance change checks in IBC transactions.
    • Updated ABI retrieval methods across various modules for more efficient contract interactions.
  • Documentation
    • Updated CHANGELOG to include recent improvements and feature additions.

Copy link
Contributor

coderabbitai bot commented Feb 19, 2024

Walkthrough

The recent updates enhance the blockchain's event handling and transaction search capabilities, particularly focusing on the IBC (Inter-Blockchain Communication) protocol and smart contract ABI (Application Binary Interface) management. Improvements include the addition of a packet_sequence index for event tracking, an order parameter in transaction searches for result sorting, and a shift to using metadata for ABI retrieval in smart contracts. These changes aim to refine data querying, event logging, and contract interaction within the blockchain ecosystem.

Changes

Files Change Summary
CHANGELOG.md Added packet_sequence index in relayer event.
integration_tests/cosmoscli.py Added order parameter in tx_search_rpc method.
integration_tests/ibc_utils.py, integration_tests/test_ibc_rly.py Enhanced packet handling and added packet_seq parameter.
integration_tests/utils.py Added by_name parameter in get_method_map function.
x/cronos/events/bindings/.../*.abigen.go Shifted ABI retrieval to use metadata and added abi.ConvertType.
x/cronos/events/bindings/src/Relayer.sol, x/cronos/events/events.go Updated event definitions and value decoders for improved attribute handling and event logging.

"In the world of code and cosmic chains,
A rabbit hopped, bringing updates in its reins.
🌟 With sequences tracked and ABIs keen,
Events are logged, more clearly seen.
Through cosmos vast, our data flows,
As the blockchain's heart, steadily grows."
🚀🐇💾

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: mmsqe <[email protected]>
@mmsqe mmsqe marked this pull request as ready for review February 19, 2024 01:36
@mmsqe mmsqe requested a review from a team as a code owner February 19, 2024 01:36
@mmsqe mmsqe requested review from JayT106 and devashishdxt and removed request for a team February 19, 2024 01:36
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4e65bd9 and 303f5d8.
Files selected for processing (13)
  • CHANGELOG.md (1 hunks)
  • integration_tests/cosmoscli.py (1 hunks)
  • integration_tests/ibc_utils.py (1 hunks)
  • integration_tests/test_ibc_rly.py (8 hunks)
  • integration_tests/utils.py (1 hunks)
  • x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go (2 hunks)
  • x/cronos/events/bindings/cosmos/precompile/bank/i_bank_module.abigen.go (2 hunks)
  • x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go (2 hunks)
  • x/cronos/events/bindings/cosmos/precompile/icacallback/i_ica_callback.abigen.go (2 hunks)
  • x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go (2 hunks)
  • x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go (16 hunks)
  • x/cronos/events/bindings/src/Relayer.sol (1 hunks)
  • x/cronos/events/events.go (1 hunks)
Additional comments: 30
x/cronos/events/bindings/src/Relayer.sol (4)
  • 12-20: The addition of indexed parameters to the RecvPacket event enhances the ability to filter and search for events based on packetSequence, packetSrcPort, and packetSrcChannel. This is a positive change for data querying capabilities. However, ensure that the size of the indexed parameters, especially if they are strings, does not lead to increased gas costs or exceed block gas limits when emitting these events.
  • 22-27: The WriteAcknowledgement event has been updated similarly to RecvPacket with indexed parameters for better searchability. This change follows the same positive pattern as the RecvPacket event. Again, be mindful of potential gas cost implications due to the use of strings as indexed parameters.
  • 31-36: The AcknowledgePacket event now includes connectionId as a parameter, replacing packetConnection and packetChannelOrdering from the previous version. This simplification could improve the event's usability, assuming connectionId provides sufficient context for event consumers. Ensure that all event consumers are updated to accommodate this change.
  • 39-44: The TimeoutPacket event has been updated in a manner consistent with the AcknowledgePacket event, including the same set of indexed parameters. This consistency across event definitions is good for maintainability and understanding of the code. As with other events, consider the implications of using strings as indexed parameters.
x/cronos/events/events.go (1)
  • 20-35: The updates to the RelayerValueDecoders map include new attribute keys and their corresponding decoder functions. This is a necessary change to support the new event attributes introduced by the PR. Ensure that all new attribute keys are correctly mapped to their decoders and that these decoders are implemented correctly to handle the data types of the attributes.
x/cronos/events/bindings/cosmos/precompile/icacallback/i_ica_callback.abigen.go (2)
  • 29-29: The addition of _ = abi.ConvertType is a good practice to suppress unused import errors and indicates that type conversion functionality from the abi package might be used elsewhere in the generated code. This is a standard pattern in Go for generated code.
  • 138-142: Changing the ABI retrieval method to use ICACallbackMetaData.GetAbi() instead of parsing JSON directly is a cleaner and more maintainable approach. This change ensures that the ABI is retrieved in a consistent manner, leveraging the metadata structure. Ensure that the GetAbi() method correctly handles any potential errors and returns the expected ABI object.
x/cronos/events/bindings/cosmos/lib/cosmos_types.abigen.go (2)
  • 29-29: The inclusion of _ = abi.ConvertType in the variable declarations section is appropriate for suppressing unused import errors in generated Go code. This indicates the potential use of type conversion features provided by the abi package.
  • 166-170: Switching to CosmosTypesMetaData.GetAbi() for ABI retrieval instead of parsing JSON directly is a positive change, aligning with best practices for handling contract ABIs in Go. This method provides a more structured and error-handling capable approach to ABI retrieval. Verify that the GetAbi() method is implemented correctly and handles errors as expected.
integration_tests/test_ibc_rly.py (6)
  • 38-39: The introduction of method_name_map and method_with_seq variables is a good practice for managing method names and identifying those that require sequence numbers. This approach improves code readability and maintainability.
  • 112-119: The recv_packet function now includes a seq parameter and additional packet information. It's crucial to ensure that the packetSequence is correctly formatted and that all packet-related parameters are accurately represented.

Please verify the correctness of the packetSequence formatting and the inclusion of all necessary packet information.

  • 124-131: Similar to the recv_packet function, the acknowledge_packet function has been updated to include a seq parameter. Ensure that the sequence number is correctly handled and that the function aligns with the expected behavior for acknowledging packets.

Confirm that the sequence number handling in the acknowledge_packet function is accurate and meets the requirements for packet acknowledgment.

  • 141-148: The write_ack function's modifications to include a seq parameter and additional packet information should be carefully reviewed to ensure that acknowledgments are correctly processed and that the packet data is accurately represented.

Double-check the write_ack function's handling of the sequence number and packet data to ensure correctness and alignment with expected behavior.

  • 175-189: The get_send_packet_seq function's addition is a significant enhancement for retrieving the sequence number of sent packets. It's important to validate the logic for extracting the sequence number from transaction events and ensure that it functions correctly in all scenarios.

Please validate the logic and functionality of the get_send_packet_seq function to ensure it accurately retrieves the sequence number from sent packet events.

  • 192-201: The filter_logs_since function's update to include a seq parameter for filtering logs by sequence number is a valuable addition. Ensure that the filtering logic is correctly implemented and that it effectively narrows down the logs based on the provided sequence number.

Confirm the effectiveness and correctness of the log filtering logic in the filter_logs_since function, especially in relation to sequence number handling.

x/cronos/events/bindings/cosmos/precompile/bank/i_bank_module.abigen.go (2)
  • 29-29: The addition of the abi.ConvertType import suggests that type conversion functionality is being utilized in the module. Ensure that this import is necessary and correctly used wherever type conversions are required.

Please verify the usage of abi.ConvertType to ensure it's necessary and correctly applied in the context of this module.

  • 138-142: The modification in the ABI retrieval method from abi.JSON to BankModuleMetaData.GetAbi() is a positive change towards a more structured approach in handling contract ABIs. This change should improve the maintainability and readability of the code by leveraging the contract metadata.
x/cronos/events/bindings/cosmos/precompile/ica/i_ica_module.abigen.go (2)
  • 29-29: The addition of abi.ConvertType in the imports is appropriate given its usage in the QueryAccount method to convert the output type. This ensures type safety and clarity in the contract method bindings.
  • 138-142: The modification in the bindICAModule function to use ICAModuleMetaData.GetAbi() instead of directly parsing the ABI string is a significant improvement. This change leverages the GetAbi method, which likely provides a more structured and error-handled way to retrieve the ABI, enhancing maintainability and reducing the risk of runtime errors due to incorrect ABI parsing.
integration_tests/utils.py (1)
  • 690-702: The addition of the by_name parameter to the get_method_map function introduces a useful feature that allows users to map method names to keys instead of the default behavior of mapping keys to signatures. This change enhances the flexibility and usability of the function, especially in scenarios where method names are more intuitive or easier to work with than signatures.

However, it's important to ensure that:

  • The documentation is updated to reflect this new feature and its usage.
  • Any potential impact on existing tests or utilities that rely on the default behavior is carefully considered and addressed.

Overall, the implementation appears to be correct and logically sound. Great job on improving the functionality of this utility function!

integration_tests/ibc_utils.py (1)
  • 430-430: The modification to the check_balance_change function to return a tuple containing both amount and packet_seq is a logical enhancement. This change allows for more detailed assertions in tests, particularly those involving IBC transfers where both the amount transferred and the packet sequence are relevant.

However, it's crucial to ensure that all calls to check_balance_change throughout the integration tests have been updated to handle the new tuple return type. Failing to update these calls could lead to runtime errors or incorrect test assertions.

CHANGELOG.md (1)
  • 7-7: The addition of the packet_sequence index in the relayer event is correctly documented in the CHANGELOG under the "Improvements" section for the UNRELEASED version. This follows the standard format and provides a clear link to the pull request for more details.
integration_tests/cosmoscli.py (1)
  • 225-234: The addition of the order parameter to the tx_search_rpc method enhances the method's functionality by allowing users to specify the order of transaction search results. This change is correctly implemented and follows good coding practices. However, it's important to ensure that the order parameter values are validated against expected values (e.g., "asc" or "desc") to prevent potential errors or misuse of the API.

Additionally, consider adding documentation for the order parameter to describe its purpose, expected values, and impact on the method's behavior. This will improve the maintainability and usability of the method for future developers and users.

x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_functions.abigen.go (1)
  • 138-142: The modification to use RelayerFunctionsMetaData.GetAbi() for ABI retrieval instead of parsing it from a hardcoded string is a significant improvement in terms of maintainability and error reduction. This change abstracts the ABI retrieval process, making the code cleaner and more robust. It's crucial to ensure that the GetAbi() method is correctly implemented and reliably returns the correct ABI. The introduction of error handling for the ABI retrieval process is also a positive change, enhancing the robustness of the contract binding.
x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go (6)
  • 47-47: The ABI string has been updated to include new parameters (packetSequence, packetSrcPort, packetSrcChannel, packetDstPort, packetDstChannel, and connectionId) in various event definitions. This change aligns with the PR's objective to enhance event handling capabilities by indexing packet_sequence and including additional packet information.
  • 265-271: The RelayerModuleAcknowledgePacket struct has been updated to include new fields corresponding to the added event parameters. This update is necessary for correctly parsing and handling AcknowledgePacket events. Ensure that the types of the new fields (PacketSequence, PacketSrcPort, PacketSrcChannel as common.Hash and PacketDstPort, PacketDstChannel, ConnectionId as string) are appropriate for the data they are intended to hold.
  • 1766-1773: The RelayerModuleRecvPacket struct has been updated to include new fields corresponding to the added event parameters, as well as a PacketDataHex field of type IRelayerModulePacketData. This update is crucial for correctly parsing and handling RecvPacket events. It's important to verify that the PacketDataHex field is correctly handled in the parsing logic to ensure the structured data is accurately represented.
  • 2086-2092: The RelayerModuleTimeoutPacket struct has been updated similarly to include new fields for the added event parameters. This change ensures that TimeoutPacket events can be correctly parsed and handled. The consistency in struct updates across different event types helps maintain the clarity and usability of the contract bindings.
  • 2405-2410: The RelayerModuleWriteAcknowledgement struct update includes new fields for the added event parameters, ensuring that WriteAcknowledgement events are correctly parsed and handled. This update is aligned with the changes in other event-related structs, maintaining consistency across the contract bindings.
  • 151-155: The method bindRelayerModule now uses RelayerModuleMetaData.GetAbi() to retrieve the ABI for the contract. This change from directly using a hardcoded ABI string to using a metadata-based approach enhances maintainability and reduces the risk of ABI mismatches.

integration_tests/test_ibc_rly.py Show resolved Hide resolved
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: 96 lines in your changes are missing coverage. Please review.

Comparison is base (e4ba498) 15.98% compared to head (b1ef79a) 36.31%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #1318       +/-   ##
===========================================
+ Coverage   15.98%   36.31%   +20.33%     
===========================================
  Files          80      118       +38     
  Lines        6201    10774     +4573     
===========================================
+ Hits          991     3913     +2922     
- Misses       5130     6481     +1351     
- Partials       80      380      +300     
Files Coverage Δ
versiondb/client/verify.go 0.00% <ø> (ø)
x/cronos/events/events.go 27.27% <ø> (ø)
.../events/bindings/cosmos/lib/cosmos_types.abigen.go 0.00% <0.00%> (ø)
...ngs/cosmos/precompile/bank/i_bank_module.abigen.go 0.00% <0.00%> (ø)
...dings/cosmos/precompile/ica/i_ica_module.abigen.go 0.00% <0.00%> (ø)
...os/precompile/icacallback/i_ica_callback.abigen.go 0.00% <0.00%> (ø)
...s/precompile/relayer/i_relayer_functions.abigen.go 0.00% <0.00%> (ø)
...smos/precompile/relayer/i_relayer_module.abigen.go 0.00% <0.00%> (ø)

... and 61 files with indirect coverage changes

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 303f5d8 and fb8d047.
Files selected for processing (1)
  • versiondb/client/verify.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • versiondb/client/verify.go

go.mod Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fb8d047 and b1ef79a.
Files ignored due to path filters (3)
  • go.mod is excluded by: !**/*.mod
  • go.sum is excluded by: !**/*.sum
  • gomod2nix.toml is excluded by: !**/*.toml
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

@mmsqe mmsqe enabled auto-merge February 19, 2024 07:51
@mmsqe mmsqe added this pull request to the merge queue Feb 19, 2024
Merged via the queue into crypto-org-chain:main with commit 08da9cc Feb 19, 2024
43 of 44 checks passed
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