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

perf: minimize necessary execution on recvpacket checktx #6302

Merged
merged 5 commits into from
May 20, 2024

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented May 13, 2024

Description

implements suggestion started in #6248

ref: #6232

can be backported to any release line as patch release


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Enhanced performance by skipping application callbacks during RecvPacket execution in checkTx within the redundant relay ante handler.
  • Bug Fixes

    • Improved test coverage for OnRecvPacket callbacks and RecvPacket messages to ensure robust handling and stability.

Copy link
Contributor

coderabbitai bot commented May 13, 2024

Walkthrough

Walkthrough

The recent changes in the ante.go and ante_test.go files aim to refine the IBC packet handling logic and enhance unit tests for improved error handling. These updates enhance code robustness and maintainability by introducing a new function for specific IBC logic and updating test cases to include expected errors, contributing to a more reliable codebase.

Changes

Files Changes
.../core/ante/ante.go Added import for errorsmod, modified AnteHandle to conditionally call recvPacketCheckTx, added recvPacketCheckTx function.
.../core/ante/ante_test.go Added import for fmt, introduced new test cases for OnRecvPacket callbacks and RecvPacket messages.

Possibly related issues


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.

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.

@colin-axner colin-axner marked this pull request as ready for review May 13, 2024 14:21
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

Out of diff range and nitpick comments (1)
modules/core/ante/ante.go (1)

4-5: Consider grouping standard library imports separately from third-party imports for better readability according to the Go style guide.

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between de92573 and a94d49e.
Files selected for processing (2)
  • modules/core/ante/ante.go (3 hunks)
  • modules/core/ante/ante_test.go (3 hunks)
Additional Context Used
Path-based Instructions (2)
modules/core/ante/ante.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

modules/core/ante/ante_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (5)
modules/core/ante/ante.go (2)

35-43: The conditional logic inside the AnteHandle function for handling MsgRecvPacket types introduces a new method recvPacketCheckTx for the check transaction context. Ensure that this method is thoroughly tested to handle all edge cases, especially since it bypasses some of the standard processing in RecvPacket.


105-129: The implementation of recvPacketCheckTx is crucial for the performance improvement. It's good to see error wrapping used for better error context. However, ensure that the error messages are clear and provide enough information for debugging. Also, consider adding more detailed comments explaining the rationale behind each step, especially the use of CacheContext which is critical for avoiding state changes during simulations.

modules/core/ante/ante_test.go (3)

4-4: The import of the fmt package is appropriate given its usage in the new test case for simulating an application callback error. This is a good use of the package for generating error messages in test scenarios.


347-359: The new test case "success on app callback error, app callbacks are skipped for performance" is crucial for validating the performance improvements by skipping application callbacks. Ensure that this test case adequately simulates the conditions under which the recvPacketCheckTx would be used in production to verify its effectiveness and robustness.


470-477: The test case "no success on recvPacket checkTx, no capability found" is important for ensuring robust error handling in recvPacketCheckTx. It tests the scenario where no capability is found, which should be a critical error case. This is a good addition to ensure the function behaves correctly under failure scenarios.

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

Very clean! :)

I like the godoc comments and tests, very nice! ❤️

response *channeltypes.MsgRecvPacketResponse
err error
)
if ctx.IsCheckTx() {
Copy link
Member

@damiannolan damiannolan May 13, 2024

Choose a reason for hiding this comment

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

So confusing to have isCheckTx/isReCheckTx and ExecMode() 😅

Just noting for reviewers that here we are in CheckTxMode explicitly because we've checked also !simulate above on L28.

On the v0.50+ line there is union between IsCheckTx=true and ExecMode == execModeSimulate (after cosmos/cosmos-sdk#20346). i.e. when IsCheckTx is true when in execModeSimulate (this is because simulateTx runs on the checkState multistore)

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is where it should be the other way around like you mentioned @colin-axner. When recheckTx=true then checkTx=true... because ¯_(ツ)_/¯

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.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between a94d49e and 16ca629.
Files selected for processing (2)
  • modules/core/ante/ante.go (3 hunks)
  • modules/core/ante/ante_test.go (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • modules/core/ante/ante.go
  • modules/core/ante/ante_test.go

@colin-axner colin-axner requested a review from charleenfei as a code owner May 20, 2024 13:34
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

Out of diff range and nitpick comments (2)
CHANGELOG.md (2)

Line range hint 179-179: Consider using descriptive text for URLs to improve readability and accessibility.

- * [\#6193](https://github.com/cosmos/ibc-go/pull/6193) Bump Cosmos SDK to v0.50.6.
+ * [\#6193](Bump Cosmos SDK to v0.50.6)[https://github.com/cosmos/ibc-go/pull/6193]

Line range hint 194-194: Remove trailing spaces to maintain clean and consistent formatting in the document.

- * (core/ante) [\#6302](https://github.com/cosmos/ibc-go/pull/6302) Performance: Skip app callbacks during RecvPacket execution in checkTx within the redundant relay ante handler. 
+ * (core/ante) [\#6302](https://github.com/cosmos/ibc-go/pull/6302) Performance: Skip app callbacks during RecvPacket execution in checkTx within the redundant relay ante handler.

Also applies to: 244-244

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 16ca629 and 95c955f.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Copy link

Quality Gate Passed Quality Gate passed for 'ibc-go'

Issues
9 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@colin-axner colin-axner merged commit 0993246 into main May 20, 2024
78 checks passed
@colin-axner colin-axner deleted the colin/6232-recvpacket-checktx branch May 20, 2024 13:49
mergify bot pushed a commit that referenced this pull request May 20, 2024
* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go
mergify bot pushed a commit that referenced this pull request May 20, 2024
* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go
mergify bot pushed a commit that referenced this pull request May 20, 2024
* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go
DimitrisJim pushed a commit that referenced this pull request May 20, 2024
) (#6333)

* perf: minimize necessary execution on recvpacket checktx (#6302)

* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go

* fix: merge conflicts

---------

Co-authored-by: colin axnér <[email protected]>
DimitrisJim pushed a commit that referenced this pull request May 20, 2024
) (#6334)

* perf: minimize necessary execution on recvpacket checktx (#6302)

* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go

* fix: merge conflicts

---------

Co-authored-by: colin axnér <[email protected]>
colin-axner added a commit that referenced this pull request May 21, 2024
) (#6335)

* perf: minimize necessary execution on recvpacket checktx (#6302)

* perf: only perform core ibc logic on recvpacket checktx

* try me linter

* fix: reorder if and add comment

* chore: add changelog entry

(cherry picked from commit 0993246)

# Conflicts:
#	CHANGELOG.md
#	modules/core/ante/ante.go
#	modules/core/ante/ante_test.go

* fix: merge conflicts

---------

Co-authored-by: colin axnér <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants