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

refactor(x/auth/ante): don't use simulate bool in ante handler #19586

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Feb 28, 2024

Description

The simulate bool and exec context are always in sync:

if mode == execModeSimulate {
anteCtx = anteCtx.WithExecMode(sdk.ExecMode(execModeSimulate))
}
newCtx, err := app.anteHandler(anteCtx, tx, mode == execModeSimulate)

But if you don't know that, it reads weird to use the exec mode within the ante handler, and pass to simulate bool through.

ref: #19161.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Refactor
    • Enhanced execution mode detection for transaction processing.
    • Simplified function signatures and improved parameter handling for better functionality.
    • Updated initialization in test files to include simulation mode.

@julienrbrt julienrbrt requested a review from a team as a code owner February 28, 2024 08:29
Copy link
Contributor

coderabbitai bot commented Feb 28, 2024

Walkthrough

Walkthrough

The update involves a significant refactoring of the AnteHandle method and related functions in multiple files. The focus is on enhancing how the execution mode is determined by replacing the simulate parameter with direct checks on ctx.ExecMode() == sdk.ExecModeSimulate. This change simplifies the handling of execution modes, particularly simulation mode, impacting parameter management and control flow across the affected components.

Changes

Files Summary
x/auth/ante/basic.go, .../ext.go, .../fee.go, .../setup.go, .../sigverify.go, .../unordered.go, types/handler.go Updated AnteHandle method and related functions to use ctx.ExecMode() == sdk.ExecModeSimulate for determining execution mode. Adjusted function signatures and usage of simulate argument in various functions. Updated ChainAnteDecorators and ChainPostDecorators functions to align with signature changes.

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.

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.yml

Commits Files that changed from the base of the PR and between a248d05 and e21dbc3.
Files selected for processing (6)
  • x/auth/ante/basic.go (8 hunks)
  • x/auth/ante/ext.go (1 hunks)
  • x/auth/ante/fee.go (2 hunks)
  • x/auth/ante/setup.go (2 hunks)
  • x/auth/ante/sigverify.go (4 hunks)
  • x/auth/ante/unordered.go (2 hunks)
Additional comments: 10
x/auth/ante/ext.go (1)
  • 46-52: The update to use ctx.ExecMode() == sdk.ExecModeSimulate instead of a boolean simulate parameter in the AnteHandle method is consistent with the PR's objective to simplify the codebase. This change should make the code cleaner and less prone to errors related to the misuse of the simulate parameter. Ensure to thoroughly test this change in different execution contexts to confirm that it behaves as expected in both simulation and non-simulation scenarios.
x/auth/ante/unordered.go (1)
  • 37-48: > 📝 NOTE

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

The modification to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode in the AnteHandle method of the UnorderedTxDecorator struct aligns with the PR's goal of simplifying the codebase. This change should enhance code readability and maintainability by relying on the execution context. It's important to conduct comprehensive testing to ensure that unordered transactions are processed correctly in both simulation and non-simulation modes.

x/auth/ante/setup.go (1)
  • 27-33: > 📝 NOTE

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

The update in the AnteHandle method of the SetUpContextDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode is in line with the PR's objective. This approach should simplify the code and reduce potential confusion. Ensure comprehensive testing is conducted, especially focusing on gas metering and transaction processing in different execution contexts.

x/auth/ante/fee.go (1)
  • 39-45: > 📝 NOTE

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

The modification in the AnteHandle method of the DeductFeeDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode aligns with the PR's goal of simplifying the codebase. This change should make the code more readable and less prone to errors. It's critical to thoroughly test fee deduction in both simulation and non-simulation modes to ensure that transactions are processed correctly and fees are deducted as expected.

x/auth/ante/basic.go (4)
  • 24-33: > 📝 NOTE

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

The update in the AnteHandle method of the ValidateBasicDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode is consistent with the PR's objective. This change should simplify the code and reduce potential confusion. Ensure to test this change thoroughly to confirm that basic validation behaves as expected in both simulation and non-simulation modes.

  • 52-58: > 📝 NOTE

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

The modification in the AnteHandle method of the ValidateMemoDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode aligns with the PR's goal. This should enhance code readability and maintainability. Comprehensive testing is important to ensure that memo validation works correctly in different execution contexts.

  • 91-97: > 📝 NOTE

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

The change in the AnteHandle method of the ConsumeTxSizeGasDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode supports the PR's objective. This approach should make the code more readable and less prone to errors. It's crucial to thoroughly test gas consumption for tx size in both simulation and non-simulation modes to ensure accurate gas metering.

  • 193-199: > 📝 NOTE

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

The update in the AnteHandle method of the TxTimeoutHeightDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining simulation mode is in line with the PR's goal. This change should simplify the code and reduce potential confusion. Ensure comprehensive testing is conducted, especially focusing on tx timeout height checks in different execution contexts.

x/auth/ante/sigverify.go (2)
  • 149-155: > 📝 NOTE

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

The modification to use ctx.ExecMode() == sdk.ExecModeSimulate instead of the simulate boolean parameter in the AnteHandle method of SigVerificationDecorator aligns with the PR's objective to simplify the codebase. This change enhances readability and reduces redundancy by relying on the execution context to determine the simulation mode. However, ensure that all calls to this method across the codebase are updated to reflect the removal of the simulate parameter. Additionally, verify that the ExecMode method reliably reflects the intended execution mode in all scenarios where AnteHandle is invoked.

  • 459-465: > 📝 NOTE

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

The update in the AnteHandle method of ValidateSigCountDecorator to use ctx.ExecMode() == sdk.ExecModeSimulate for determining the execution mode is consistent with the refactor's goal. This change simplifies the method signature by removing the redundant simulate parameter. As with the previous comment, ensure that the execution context accurately represents the simulation mode in all relevant cases and that there are no dependencies on the removed parameter elsewhere in the codebase.

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

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between e21dbc3 and 49bf183.
Files selected for processing (1)
  • types/handler.go (3 hunks)
Additional comments: 2
types/handler.go (2)
  • 49-55: In the ChainAnteDecorators function, the simulate parameter is removed, and the ctx.ExecMode() == ExecModeSimulate check is used instead. This change is consistent with the PR's objective. Ensure that all AnteDecorators in the chain are updated to match this new signature and logic.
  • 77-83: The ChainPostDecorators function mirrors the changes made in ChainAnteDecorators, removing the simulate parameter and using the ctx.ExecMode() == ExecModeSimulate check. Confirm that all PostDecorators in the chain are updated accordingly.

types/handler.go Outdated Show resolved Hide resolved

// PostHandler like AnteHandler but it executes after RunMsgs. Runs on success
// or failure and enables use cases like gas refunding.
type PostHandler func(ctx Context, tx Tx, simulate, success bool) (newCtx Context, err error)
type PostHandler func(ctx Context, tx Tx, _, success bool) (newCtx Context, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

The simulate parameter has also been removed from the PostHandler function signature. Ensure that the documentation is updated to reflect this change and avoid mentioning the removed simulate parameter.

- type PostHandler func(ctx Context, tx Tx, _, success bool) (newCtx Context, err error)
+ type PostHandler func(ctx Context, tx Tx, success bool) (newCtx Context, err error)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
type PostHandler func(ctx Context, tx Tx, _, success bool) (newCtx Context, err error)
type PostHandler func(ctx Context, tx Tx, success bool) (newCtx Context, err error)


// AnteDecorator wraps the next AnteHandler to perform custom pre-processing.
type AnteDecorator interface {
AnteHandle(ctx Context, tx Tx, simulate bool, next AnteHandler) (newCtx Context, err error)
AnteHandle(ctx Context, tx Tx, _ bool, next AnteHandler) (newCtx Context, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

The simulate parameter is removed from the AnteDecorator interface's AnteHandle method. The documentation should be updated to remove references to the simulate parameter.

- 	AnteHandle(ctx Context, tx Tx, _ bool, next AnteHandler) (newCtx Context, err error)
+ 	AnteHandle(ctx Context, tx Tx, next AnteHandler) (newCtx Context, err error)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AnteHandle(ctx Context, tx Tx, _ bool, next AnteHandler) (newCtx Context, err error)
AnteHandle(ctx Context, tx Tx, next AnteHandler) (newCtx Context, err error)

}

// PostDecorator wraps the next PostHandler to perform custom post-processing.
type PostDecorator interface {
PostHandle(ctx Context, tx Tx, simulate, success bool, next PostHandler) (newCtx Context, err error)
PostHandle(ctx Context, tx Tx, _, success bool, next PostHandler) (newCtx Context, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, the simulate parameter is removed from the PostDecorator interface's PostHandle method. Update the documentation to reflect the removal of the simulate parameter.

- 	PostHandle(ctx Context, tx Tx, _, success bool, next PostHandler) (newCtx Context, err error)
+ 	PostHandle(ctx Context, tx Tx, success bool, next PostHandler) (newCtx Context, err error)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
PostHandle(ctx Context, tx Tx, _, success bool, next PostHandler) (newCtx Context, err error)
PostHandle(ctx Context, tx Tx, success bool, next PostHandler) (newCtx Context, err error)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.yml

Commits Files that changed from the base of the PR and between 49bf183 and 63a2633.
Files selected for processing (1)
  • types/handler.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • types/handler.go

@tac0turtle
Copy link
Member

seems there is a test failing for the antedecorators

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.yml

Commits Files that changed from the base of the PR and between 63a2633 and e406426.
Files selected for processing (1)
  • types/handler_test.go (2 hunks)
Additional comments: 2
types/handler_test.go (2)
  • 17-17: The addition of WithExecMode(sdk.ExecModeSimulate) in TestChainAnteDecorators correctly aligns with the PR's objective to use the execution context for determining the execution mode instead of a separate simulate boolean parameter. This change ensures that the test context is explicitly set to simulation mode, which is necessary for testing the behavior of ante decorators under simulation conditions.
  • 42-42: Similarly, the update in TestChainPostDecorators to initialize ctx with WithExecMode(sdk.ExecModeSimulate) is consistent with the refactor's goal. By setting the execution mode in the context, the tests accurately reflect the intended usage of the execution context to control behavior, specifically in simulation mode. This change is crucial for ensuring that post decorators are tested under the correct execution conditions.

@julienrbrt julienrbrt added this pull request to the merge queue Feb 29, 2024
Merged via the queue into main with commit 975ddc1 Feb 29, 2024
61 of 62 checks passed
@julienrbrt julienrbrt deleted the julien/ante branch February 29, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants