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(ante): separate Cosmos from EVM fee ante handlers #30

Open
wants to merge 1 commit into
base: main-dym
Choose a base branch
from

Conversation

zale144
Copy link

@zale144 zale144 commented Jun 6, 2024

Description


Closes #29

Summary by CodeRabbit

  • Refactor

    • Improved fee calculation logic for transactions by simplifying the DeductFeeDecorator and related functions.
    • Streamlined the HandlerOptions struct by removing the TxFeeChecker field and associated validations.
    • Updated various test cases to align with the new fee calculation logic.
  • Bug Fixes

    • Enhanced fee calculation to prevent potential integer overflow issues.
  • Chores

    • Reorganized import statements for better code readability and maintainability.

@zale144 zale144 self-assigned this Jun 6, 2024
Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

The changes primarily involve refactoring the fee calculation logic in fees.go by removing the txFeeChecker field from the DeductFeeDecorator struct and directly calling the checkTxFeeWithValidatorMinGasPrices function. This separation ensures that EVM and Cosmos transactions have distinct fee calculations, aligning with the objective to segregate these fees.

Changes

Files Change Summary
app/ante/cosmos/fees.go Refactored DeductFeeDecorator, removed txFeeChecker, updated fee calculation logic.
app/ante/cosmos/fees_test.go Modified NewDeductFeeDecorator call in tests to reflect changes in parameters.
app/ante/cosmos/setup_test.go Removed TxFeeChecker initialization in SetupTest.
app/ante/handler_options.go Removed TxFeeChecker from HandlerOptions, updated related function parameters and validations.
app/ante/handler_options_test.go Removed test case for empty transaction fee checker in TestValidateHandlerOptions.
app/app.go Adjusted imports and removed TxFeeChecker initialization in setAnteHandler.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant CosmosTx
    participant EvmTx
    participant FeeHandler

    User->>CosmosTx: Submit transaction
    CosmosTx->>FeeHandler: Calculate fee
    FeeHandler->>CosmosTx: Return fee based on validator gas prices

    User->>EvmTx: Submit transaction
    EvmTx->>FeeHandler: Calculate fee
    FeeHandler->>EvmTx: Return fee based on EVM fee market parameters
Loading

Assessment against linked issues

Objective Addressed Explanation
Separate ante handlers for Cosmos and EVM fees (#29)

Poem

In code's vast and intricate maze,
We've split the fees in brand new ways.
Cosmos and EVM, now apart,
Each with their unique fee chart.
With logic clear and flows refined,
Transactions now are well-aligned.
In the world of bytes and keys,
We celebrate these changes with ease!


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.
    • @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 as 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.

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

@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 (2)
app/ante/cosmos/fees.go (2)

Line range hint 41-41: Undefined BankKeeper type.

- BankKeeper
+ evmtypes.BankKeeper

Also applies to: 50-50


183-183: Integer overflow warnings are noted but deemed irrelevant here due to the context.

Consider adding a comment explaining why the overflow is not relevant in this context to avoid confusion for future maintainers.

Also applies to: 199-199

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2dcb567 and 19448fb.

Files selected for processing (6)
  • app/ante/cosmos/fees.go (6 hunks)
  • app/ante/cosmos/fees_test.go (2 hunks)
  • app/ante/cosmos/setup_test.go (2 hunks)
  • app/ante/handler_options.go (5 hunks)
  • app/ante/handler_options_test.go (3 hunks)
  • app/app.go (4 hunks)
Additional context used
golangci-lint
app/ante/cosmos/fees.go

41-41: undefined: BankKeeper (typecheck)


50-50: undefined: BankKeeper (typecheck)

Additional comments not posted (8)
app/ante/handler_options_test.go (1)

6-7: Imports are updated to reflect the changes in the codebase.

app/ante/cosmos/setup_test.go (1)

Line range hint 6-7: Imports are updated to reflect the changes in the codebase.

app/ante/cosmos/fees.go (1)

83-83: Ensure that the checkTxFeeWithValidatorMinGasPrices function is correctly calculating fees based on the new logic.

Verification successful

The function checkTxFeeWithValidatorMinGasPrices appears to correctly calculate fees based on the new logic. It retrieves the fee and gas values, checks the fee against the minimum gas prices during CheckTx, and calculates the transaction priority.

  • feeCoins := feeTx.GetFee()
  • gas := feeTx.GetGas()
  • Checks fee against minimum gas prices if ctx.IsCheckTx()
  • Calculates priority using getTxPriority(feeCoins, int64(gas))

No issues were found in the implementation.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correctness of fee calculation logic in `checkTxFeeWithValidatorMinGasPrices`.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type python $'checkTxFeeWithValidatorMinGasPrices'

Length of output: 85



Script:

#!/bin/bash
# Description: Verify the correctness of fee calculation logic in `checkTxFeeWithValidatorMinGasPrices`.

# Search for the function definition in Go files.
rg --type go 'func checkTxFeeWithValidatorMinGasPrices'

# Search for all usages of the function in Go files.
rg --type go 'checkTxFeeWithValidatorMinGasPrices'

Length of output: 582



Script:

#!/bin/bash
# Description: Extract the implementation of the `checkTxFeeWithValidatorMinGasPrices` function for review.

# Extract the function implementation from the file.
sed -n '/func checkTxFeeWithValidatorMinGasPrices/,/^}/p' app/ante/cosmos/fees.go

Length of output: 711

app/ante/handler_options.go (2)

33-33: Updated imports to include anteutils.


126-126: The NewDeductFeeDecorator function is correctly updated to reflect the removal of the TxFeeChecker.

Also applies to: 151-151

app/ante/cosmos/fees_test.go (1)

272-272: LGTM! The update to NewDeductFeeDecorator initialization aligns with the PR's objective to separate fee handling.

app/app.go (2)

169-169: Ensure the updated import statements align with the new architectural changes.


1135-1135: Verify that the updated paramsKeeper.Subspace calls are correctly configured for the new module parameters.

Verification successful

The ParamKeyTable methods are defined for various modules, including evmtypes, feemarkettypes, and others. This confirms that the paramsKeeper.Subspace calls are correctly configured with the appropriate WithKeyTable methods for the new module parameters.

  • x/evm/types/params_legacy.go:func ParamKeyTable() paramtypes.KeyTable
  • x/feemarket/types/params.go:func ParamKeyTable() paramtypes.KeyTable

These definitions ensure that the paramsKeeper.Subspace calls are correctly paired with the necessary key tables.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct configuration of paramsKeeper.Subspace calls.

# Test: Search for the paramsKeeper.Subspace usage in the entire codebase. Expect: Correct configuration as per new module parameters.
rg --type go $'paramsKeeper.Subspace'

Length of output: 1232



Script:

#!/bin/bash
# Description: Verify the definitions of ParamKeyTable methods for modules using WithKeyTable.

# Search for the definition of ParamKeyTable methods in the codebase.
rg --type go 'func ParamKeyTable' 

Length of output: 767

@omritoptix omritoptix changed the title feat(ante): Separate Cosmos from EVM fee ante handlers feat(ante): separate Cosmos from EVM fee ante handlers Jun 6, 2024
@danwt danwt self-requested a review June 7, 2024 12:02
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.

Separate ante handlers for Cosmos and EVM fees
1 participant