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

fix: stuck escrow fees #194

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

fix: stuck escrow fees #194

wants to merge 7 commits into from

Conversation

freeelancer
Copy link
Contributor

@freeelancer freeelancer commented Oct 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new PostHandler for enhanced transaction processing.
    • Added a new AccountKeeper interface for better account management.
    • Implemented a new constant for event handling related to escrowed fees.
  • Bug Fixes

    • Improved validation for the AccountKeeper in transaction processing.
    • Enhanced logic for handling stuck escrowed fees.
  • Tests

    • Updated test cases to reflect new gas consumption and balance checks.
  • Chores

    • Added a mock implementation for the AccountKeeper to facilitate testing.

Copy link

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces significant modifications to the application, primarily through the implementation of a new PostHandler within the App struct in app/app.go. This involves the addition of methods for setting up the post-handler and integrating a new AccountKeeper interface in the post package. The PostHandlerOptions struct is updated to include the AccountKeeper, and relevant changes are made to the FeeMarketDeductDecorator to accommodate this new structure. Additionally, tests are updated to reflect these changes, enhancing the overall functionality and robustness of the application.

Changes

File Path Change Summary
app/app.go Added setPostHandler and PostHandler methods in App struct.
app/post_handler.go Added AccountKeeper field to PostHandlerOptions and updated NewPostHandler for validation.
x/xfeemarket/post/expected_keepers.go Introduced AccountKeeper interface with GetModuleAccount method.
x/xfeemarket/post/fee.go Updated FeeMarketDeductDecorator with accountKeeper field and modified constructor signature.
x/xfeemarket/post/fee_test.go Updated test cases for BurnCoins, BurnCoinsAndRefund, and Refund functions.
x/xfeemarket/post/mocks/mock_account_keeper.go Added mock implementation for AccountKeeper.
x/xfeemarket/post/suite/suite.go Modified SetupHandlers to include accountkeeper variable for clarity.
x/xfeemarket/types/keys.go Added constant EventTypeBurnStuckEscrowedFee in types package.

Possibly related PRs

  • feat: add default denom resolver #175: The changes in app/app.go regarding the integration of the fee market module and the FeeMarketKeeper are related to the new PostHandler implementation in the main PR, as both involve enhancements to transaction processing and fee management.
  • fix: validate MsgUpsertFeeDenom #176: Modifications to the FeeMarketDeductDecorator in fee.go align with the main PR's focus on post-handling logic, particularly in how fees are managed and refunded after transactions.
  • fix: simulate gas calculations #187: Updates to gas consumption calculations in fee.go and the associated test cases reflect changes in fee handling mechanisms, which are relevant to the new PostHandler functionality introduced in the main PR.

Suggested reviewers

  • mantrachain-support
  • allthatjazzleo

🐇 In the meadow, changes bloom,
A post-handler now finds room.
With keepers gathered, fees align,
In the code, new paths we find.
Hop along, let tests run free,
A brighter future, wait and see! 🌼


🪧 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

@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: 3

🧹 Outside diff range and nitpick comments (7)
x/xfeemarket/types/keys.go (1)

20-21: LGTM! Consider adding a comment for the new constant.

The addition of EventTypeBurnStuckEscrowedFee aligns well with the PR objective of fixing stuck escrow fees. The naming convention is consistent with existing patterns.

Consider adding a brief comment explaining the purpose of the new EventTypeBurnStuckEscrowedFee constant, similar to how other constants in this file are documented. This would improve code readability and maintainability.

app/post_handler.go (1)

12-12: LGTM. Consider updating documentation.

The addition of AccountKeeper to PostHandlerOptions is appropriate. It introduces a new dependency that will be used in fee market operations.

Consider updating the struct's documentation to explain the purpose and requirements of the AccountKeeper field.

x/xfeemarket/post/expected_keepers.go (1)

11-17: LGTM: Well-structured AccountKeeper interface.

The new AccountKeeper interface is well-designed and follows best practices:

  1. It uses context.Context for proper context propagation.
  2. It includes a go:generate directive for easy mock generation.
  3. The interface is well-documented, explaining its purpose and abstraction reason.

Consider adding a brief description of the GetModuleAccount method in the interface documentation. For example:

// AccountKeeper defines the contract needed for AccountKeeper related APIs.
// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators.
//
// GetModuleAccount retrieves a module account by name using the provided context.
//
//go:generate mockery --name AccountKeeper --filename mock_account_keeper.go
type AccountKeeper interface {
    GetModuleAccount(ctx context.Context, name string) sdk.ModuleAccountI
}
x/xfeemarket/post/mocks/mock_account_keeper.go (2)

13-36: LGTM: AccountKeeper mock implementation is well-structured.

The AccountKeeper struct and GetModuleAccount method are implemented correctly following the testify mock patterns. The method properly handles different return value scenarios and includes appropriate panic handling.

Consider adding a comment explaining the purpose of the type assertion in the else block:

 } else {
+    // Attempt to cast the return value to the expected type
     if ret.Get(0) != nil {
         r0 = ret.Get(0).(types.ModuleAccountI)
     }
 }

This would improve code readability and explain the purpose of this block to future maintainers.


38-50: LGTM: NewAccountKeeper function is well-implemented.

The NewAccountKeeper function is correctly implemented as a constructor for the AccountKeeper mock. It properly sets up the mock and registers a cleanup function to assert expectations after the test.

For consistency with Go naming conventions, consider renaming the return variable:

-func NewAccountKeeper(t interface {
+func NewAccountKeeper(testingT interface {
 	mock.TestingT
 	Cleanup(func())
 }) *AccountKeeper {
-	mock := &AccountKeeper{}
-	mock.Mock.Test(t)
+	mock := &AccountKeeper{}
+	mock.Mock.Test(testingT)
 
-	t.Cleanup(func() { mock.AssertExpectations(t) })
+	testingT.Cleanup(func() { mock.AssertExpectations(testingT) })
 
 	return mock
 }

This change makes the parameter name more descriptive and consistent with its purpose.

x/xfeemarket/post/suite/suite.go (1)

137-137: LGTM! Consider applying consistent naming convention.

The introduction of the accountkeeper variable improves code consistency. However, for even better consistency, consider using camelCase for all local variables.

Apply this minor change:

-accountkeeper := s.AccountKeeper
+accountKeeper := s.AccountKeeper

This change would make the naming convention consistent with other local variables like bankKeeper and feeGrantKeeper.

Also applies to: 169-169

x/xfeemarket/post/fee.go (1)

188-193: Add unit tests for new stuck escrow fee logic

The added logic for handling and burning stuck escrowed fees introduces new pathways that should be tested. Please add unit tests to cover:

  • Scenarios where there are stuck escrowed fees in the default fee denomination.
  • Transactions with fees in denominations different from the default.
  • Verification that the correct events are emitted when stuck fees are burned.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8765395 and 8302687.

📒 Files selected for processing (8)
  • app/app.go (1 hunks)
  • app/post_handler.go (2 hunks)
  • x/xfeemarket/post/expected_keepers.go (1 hunks)
  • x/xfeemarket/post/fee.go (2 hunks)
  • x/xfeemarket/post/fee_test.go (7 hunks)
  • x/xfeemarket/post/mocks/mock_account_keeper.go (1 hunks)
  • x/xfeemarket/post/suite/suite.go (2 hunks)
  • x/xfeemarket/types/keys.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (16)
x/xfeemarket/types/keys.go (1)

21-21: Verify the usage of the new event type across the module.

The addition of EventTypeBurnStuckEscrowedFee suggests a new event type for burning stuck escrowed fees. To ensure proper implementation:

  1. Verify that this new event type is emitted in the appropriate location within the module.
  2. Ensure that any event handling or processing logic in the module is updated to handle this new event type.
  3. Update relevant documentation or comments in other files to reflect this new event type.

To help verify the usage of the new event type, you can run the following script:

app/post_handler.go (3)

19-21: LGTM. Proper validation added.

The addition of the AccountKeeper validation check is appropriate and consistent with the existing validation pattern for other keepers. This ensures that all required dependencies are provided before constructing the post handler.


33-33: LGTM. Verify NewFeeMarketDeductDecorator signature.

The addition of AccountKeeper as an argument to NewFeeMarketDeductDecorator is consistent with the changes made to PostHandlerOptions.

Please ensure that the NewFeeMarketDeductDecorator function in the xfeemarket/post package has been updated to accept the AccountKeeper parameter. Run the following script to verify:

#!/bin/bash
# Description: Verify the signature of NewFeeMarketDeductDecorator function

# Test: Search for the NewFeeMarketDeductDecorator function definition
ast-grep --lang go --pattern 'func NewFeeMarketDeductDecorator($_AccountKeeper, $_, $_) $_'

Line range hint 1-40: Overall LGTM. Consider reviewing related files.

The changes in this file consistently introduce the AccountKeeper dependency to the post handler setup. This appears to be part of a larger refactoring to include account-related operations in fee market handling.

To ensure consistency across the codebase, please review:

  1. The implementation of the AccountKeeper interface in the xfeemarket/post package.
  2. Any other files that might need updates due to this new dependency.

Run the following script to identify potentially affected files:

x/xfeemarket/post/expected_keepers.go (1)

4-5: LGTM: Import changes are appropriate.

The addition of the context import is necessary for the new AccountKeeper interface. The empty line improves code readability by separating standard library imports from third-party imports.

x/xfeemarket/post/mocks/mock_account_keeper.go (1)

1-11: LGTM: File header and imports are appropriate.

The file header correctly indicates that this is generated code, which is important for maintaining the mock. The imports are appropriate for the mock implementation, including the necessary packages from the testify framework and cosmos-sdk.

x/xfeemarket/post/fee.go (4)

24-26: Ensure proper usage of the added accountKeeper

You've added accountKeeper to the FeeMarketDeductDecorator struct. Please verify that this addition is consistently utilized throughout the codebase where necessary.


181-186: Ensure events are emitted for all fee denominations

The event feemarkettypes.EventTypeFeePay is emitted only when fee.Denom == defaultFeeDenom. If fees can be paid in multiple denominations, consider whether you should emit this event for fees in other denominations as well to maintain consistent event logging.


167-195: ⚠️ Potential issue

Verify handling of stuck escrowed fees for non-default denominations

Currently, the logic for burning stuck escrowed fees only executes when fee.Denom == defaultFeeDenom. If there are stuck escrowed fees in the default fee denomination but the transaction fee is in a different denomination, these fees may not be burned. Please verify whether it is necessary to burn stuck escrowed fees regardless of the transaction's fee denomination.

Consider modifying the condition to always check and burn any stuck escrowed fees in the default fee denomination, even when the transaction fee is in a different denomination.


29-34: Update all instantiations of NewFeeMarketDeductDecorator

The constructor NewFeeMarketDeductDecorator now includes an AccountKeeper parameter (ak). Ensure that all calls to this constructor across the codebase are updated to include this new parameter to prevent compilation errors.

You can run the following script to identify any outdated constructor calls:

✅ Verification successful

All instantiations of NewFeeMarketDeductDecorator are up to date.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find calls to `NewFeeMarketDeductDecorator` missing the new `AccountKeeper` parameter.

# Test: Search for instances of `NewFeeMarketDeductDecorator` with less than three arguments.
# Expect: No instances found.

rg --type go 'NewFeeMarketDeductDecorator\([^,]*,[^,]*\)' --files-with-matches

Length of output: 80

x/xfeemarket/post/fee_test.go (5)

137-137: Update of Expected Consumed Gas

The expectedConsumedGas value has been updated to 25250, reflecting the new gas consumption after recent changes. This ensures that the test accurately checks against the current gas usage.


142-142: Declaration of zeroInt

The variable zeroInt is declared using math.ZeroInt() for use in mock functions. This provides a clear and consistent representation of zero values in the tests.


212-212: Verify Mocked Balance in Simulation

In the test case "0 gas given should pass - simulate", the GetBalance mock returns a zero balance:

s.MockBankKeeper.On("GetBalance", mock.Anything, mock.Anything, mock.Anything).Return(sdk.NewCoin(baseDenom, zeroInt)).Once()

Please verify that returning a zero balance is appropriate for this test scenario and does not affect the validity of the test, especially since the signer is expected to have enough funds.


435-437: Update of Expected Consumed Gas Constants

The expectedConsumedGas and expectedConsumedGasResolve values have been updated to reflect the new gas consumption metrics:

expectedConsumedGas = 61632
expectedConsumedGasResolve = 27870 // slight difference due to denom resolver

Updating these constants ensures that the tests accurately validate against the current gas usage.


543-543: Update of ExpectConsumedGas in Test Case

In the test case "signer has enough funds, should pass, no tip", the ExpectConsumedGas value has been updated to 37325 to reflect the new gas consumption after recent changes:

ExpectConsumedGas: 37325,

This ensures that the test expectations align with the current behavior.

app/app.go (1)

Line range hint 1039-1045: LGTM

The setPostHandler function correctly initializes PostHandlerOptions and sets the post handler using NewPostHandler. The implementation aligns with the application's initialization pattern.

x/xfeemarket/post/fee_test.go Show resolved Hide resolved
x/xfeemarket/post/fee_test.go Show resolved Hide resolved
x/xfeemarket/post/fee_test.go Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Nov 5, 2024

Copy link

sonarqubecloud bot commented Dec 9, 2024

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.

1 participant