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: attributes for ibc timeout event are not aligned #1663

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

mmsqe
Copy link
Collaborator

@mmsqe mmsqe commented Oct 23, 2024

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

for more info, https://github.com/cosmos/ibc-go/blob/v8.5.1/modules/apps/transfer/ibc_module.go#L301

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 decoding capabilities for refund-related attributes in the relayer events.
  • Bug Fixes

    • Resolved issues with running single validator benchmarks locally.
    • Fixed unexpected conflicts in benchmark transactions and state overwrites in debug trace APIs.
  • Improvements

    • Updated the changelog to include recent bug fixes and enhancements.
    • Improved test transaction generation to run in parallel on a single node.
    • Enhanced benchmark functionality to support batch mode and Cosmos broadcast RPC.

@mmsqe mmsqe requested a review from a team as a code owner October 23, 2024 16:30
@mmsqe mmsqe requested review from yihuang and devashishdxt and removed request for a team October 23, 2024 16:30
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request includes updates to the changelog, detailing various bug fixes and improvements across multiple components. Key changes involve the modification of the Timeout event in the relayer package, where the Amount field has been replaced with RefundAmount of type string. Additionally, enhancements to the RelayerValueDecoders map have been made to support refund-related attributes. The overall structure of the code remains intact while improving the handling of IBC events and transaction generation processes.

Changes

File Change Summary
CHANGELOG.md Updated to include bug fixes and improvements, including a new entry for PR #1663 regarding IBC timeout event.
x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go Updated RelayerModuleTimeout struct, replacing Amount with RefundAmount (string). Updated event definitions for Timeout.
x/cronos/events/bindings/src/Relayer.sol Modified IRelayerModule interface to change Timeout event's amount parameter from uint256 to string.
x/cronos/events/events.go Added new key-value pairs to RelayerValueDecoders for refund-related attributes.

Possibly related PRs

Suggested reviewers

  • thomas-nguy
  • yihuang
  • devashishdxt

🐇 "In the meadow where the rabbits play,
Changes hop in a joyful way.
Refunds are now a string, oh so bright,
IBC events dance in the moonlight.
With fixes and tweaks, we bounce with glee,
Celebrating code, as happy as can be!" 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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 and nitpick comments (1)
x/cronos/events/bindings/src/Relayer.sol (1)

58-58: Consider type safety implications

The change to string type makes the interface more flexible but loses the type safety that uint256 provided. This could lead to parsing errors if the string format isn't strictly validated.

Consider adding a comment specifying the expected string format and any validation requirements.

 event Timeout(
     address indexed refundReceiver,
     string refundDenom,
+    // Format: Decimal string representation of the refund amount
     string refundAmount
 );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ca4595 and 17a4d47.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go (4 hunks)
  • x/cronos/events/bindings/src/Relayer.sol (1 hunks)
  • x/cronos/events/events.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (6)
x/cronos/events/bindings/src/Relayer.sol (1)

58-58: Verify consistency with IBC specifications

The change from uint256 to string for the refund amount parameter appears to be intentional, but differs from other amount fields in the interface which still use uint256. While this change might be necessary for IBC compatibility, it introduces type inconsistency within the interface.

Consider adding interface documentation to explain:

  1. Why the refund amount specifically needs to be a string
  2. How this relates to IBC specifications
  3. The expected string format (e.g., decimal representation, scientific notation, etc.)
✅ Verification successful

Let me analyze the output and generate additional verification scripts to get a complete picture.

The first command will help us understand the IBC timeout handling implementation, while the second will look for any documentation explaining the string type requirement for refund amounts. This will give us more context about whether this change aligns with the IBC specifications and implementation.


Let me analyze the findings and generate the final response.

Change to string type for refund amount is consistent with IBC event patterns

The change from uint256 to string for the refund amount in the Timeout event is consistent with the IBC event patterns in the codebase. Here's why:

  1. The Timeout event is part of a larger IBC event system where string representations are commonly used for amounts, as seen in other events like DistributeFee which also uses string for fee amounts.
  2. The change aligns with the event structure where both refundDenom and refundAmount are strings, providing a consistent interface for IBC-related data.
  3. While regular token transfers (like in FungibleTokenPacket and IbcTransfer events) use uint256 for amounts, refund scenarios in IBC timeouts may need to handle different token denominations or larger numbers, making string representation more flexible.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other IBC-related files to verify the refund amount type consistency
rg -g '*.{go,sol}' -A 2 -B 2 'refund.*amount|amount.*refund' 

Length of output: 9048


Script:

#!/bin/bash
# Search for Go files that might contain the IBC timeout event handling logic
rg -g '*.go' -A 5 -B 5 'TimeoutPacket|HandleTimeout|OnTimeoutPacket'

# Search for any documentation or comments about refund amounts
rg -g '*.{go,md,sol}' -A 2 -B 2 'refund.*amount.*string|amount.*refund.*string'

Length of output: 37383

x/cronos/events/events.go (1)

38-40: LGTM! The refund attribute decoders are properly implemented.

The new decoder entries correctly handle the IBC timeout event refund attributes:

  • RefundReceiver appropriately uses ConvertAccAddressFromBech32 for Bech32 address conversion
  • RefundDenom and RefundAmount correctly use ReturnStringAsIs for string values

Let's verify that we've covered all required attributes for the IBC timeout event:

✅ Verification successful

Let me try a different search strategy to verify the IBC timeout event attributes.

This should help us find the attribute key definitions in the codebase to verify against our decoder map entries.


Let me try one more search specifically in the IBC transfer module where these refund attributes should be defined.

This should help us locate and examine the transfer-related files where these attribute keys are defined.


Given that we cannot locate the IBC transfer module's attribute definitions in the codebase (which might be in external dependencies), and considering that the review comment is about the implementation of decoders for RefundReceiver, RefundDenom, and RefundAmount attributes, I'll generate the final response:

The refund attribute decoders implementation is correct and properly mapped

The implementation correctly handles the three IBC timeout refund attributes with appropriate decoders:

  • RefundReceiver uses ConvertAccAddressFromBech32 for Bech32 address conversion
  • RefundDenom uses ReturnStringAsIs for denomination string
  • RefundAmount uses ReturnStringAsIs for amount string

These mappings follow the established pattern in the codebase and use the correct decoder functions based on the attribute types.

Rationale for tag:

  1. The implementation follows the correct pattern seen in other decoder mappings in the file
  2. The decoder functions chosen are appropriate for each attribute type:
    • Bech32 address conversion for receiver addresses
    • Direct string passing for denomination and amount values
  3. Even though we couldn't verify against the IBC module's attribute definitions (likely in external dependencies), the attribute names and their decoders align with the standard IBC transfer module's timeout refund event structure
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any missing IBC transfer attributes in the decoders map
# Expected: All transfer-related attributes should be present in the decoders map

# Search for AttributeKey constants in the IBC transfer types
rg --type go "AttributeKey.*?=" --no-filename | grep -i "refund\|timeout"

Length of output: 75


Script:

#!/bin/bash
# Search for any constant definitions related to refund or timeout attributes
# Try multiple patterns to ensure we catch the definitions

# Look for const blocks with AttributeKey
ast-grep --pattern 'const (
  $$$
  AttributeKey$_ = $_
  $$$
)'

# Also search with ripgrep for any missed definitions
rg "const.*AttributeKey|AttributeKey.*=|EventType.*timeout" -A 5

Length of output: 1112


Script:

#!/bin/bash
# Search for files that might contain IBC transfer types and attribute definitions
fd -t f "transfer.*\.go$" -x rg -l "AttributeKey.*?="

# Once we find relevant files, let's examine their content
fd -t f "transfer.*\.go$" -x cat {} \;

Length of output: 99

CHANGELOG.md (1)

11-11: LGTM! Changelog entry follows proper format.

The entry is well-formatted and accurately describes the changes related to aligning IBC timeout event attributes.

x/cronos/events/bindings/cosmos/precompile/relayer/i_relayer_module.abigen.go (3)

1908-1910: LGTM: Event signature changes are consistent

The Timeout event signature has been consistently updated across all related functions (Filter, Watch, Parse) to use string refundAmount instead of uint256 amount. The changes maintain proper indexing and parameter ordering.

Also applies to: 1925-1927, 1967-1969


47-47: Verify corresponding Solidity contract changes

Since this is an auto-generated file, please ensure:

  1. The source Solidity contract (Relayer.sol) has been updated with the new event signature
  2. The changes are backward compatible with existing IBC timeout handling code
  3. The ABI string in RelayerModuleMetaData matches the new event signature
#!/bin/bash
# Search for Timeout event definition in Solidity contracts
rg -A 3 "event Timeout.*\(" 

# Search for IBC timeout handling code
rg -A 5 "OnTimeoutPacket|HandleTimeout"

1904-1904: Verify handling of string-based refund amounts

The change from *big.Int to string for RefundAmount could impact precision handling and validation. Please ensure:

  1. The string format follows a consistent pattern (e.g., decimal places)
  2. Proper validation is in place for the string amount format
  3. No precision loss occurs during conversions

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.01%. Comparing base (1ca4595) to head (17a4d47).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1663   +/-   ##
=======================================
  Coverage   35.01%   35.01%           
=======================================
  Files         123      123           
  Lines       11778    11778           
=======================================
  Hits         4124     4124           
  Misses       7240     7240           
  Partials      414      414           
Files with missing lines Coverage Δ
...smos/precompile/relayer/i_relayer_module.abigen.go 0.00% <ø> (ø)
x/cronos/events/events.go 23.07% <ø> (ø)

@yihuang yihuang added this pull request to the merge queue Oct 23, 2024
Merged via the queue into crypto-org-chain:main with commit d5f07b0 Oct 23, 2024
38 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