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(bank, feegrant, authz): avoid creating baseaccount #19188

Merged
merged 47 commits into from
Feb 13, 2024
Merged

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Jan 23, 2024

Description

Closes: #19092

avoid creating baseaccount if it does not exist, preventing front running of accounts


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

  • New Features
    • Introduced a new message type, MsgBurn, for burning coins.
    • The x/feegrant module is now a standalone module with enhanced functionality.
  • Bug Fixes
    • Improved error handling in transaction preparation and account retrieval processes.
    • Enhanced account authentication logic to support newly created accounts.
  • Documentation
    • Updated architecture documentation to clarify the account creation process for new transactions.
  • Refactor
    • Simplified account creation logic in various modules.
  • Chores
    • Updated error messages for better clarity in test helpers.
  • Breaking Changes
    • Removed automatic BaseAccount creation for non-existent accounts in transactions, impacting several modules.

x/bank/keeper/keeper.go Outdated Show resolved Hide resolved
x/bank/keeper/keeper.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Looks good so far

Copy link
Contributor

coderabbitai bot commented Jan 31, 2024

Warning

Rate Limit Exceeded

@tac0turtle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 48 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between e4568b7 and 2b53269.

Walkthrough

The significant changes revolve around enhancing account creation and initialization processes within a blockchain system, particularly focusing on managing accounts without existing blockchain presence. These updates aim to prevent the automatic initialization of BaseAccount for non-existent accounts when transactions are directed towards them. The modifications empower accounts to self-initialize through transactions, while also refining error handling and account verification procedures to support these new functionalities.

Changes

Files Change Summary
client/tx/factory.go Modified error handling to return nil in specific cases.
x/auth/ante/sigverify.go Added newlyCreated flag, updated account creation and pubkey setting logic.
x/authz/keeper/msg_server.go Removed account creation in Grant, added print statement in Exec.
docs/architecture/adr-020-... Introduced account creation step specifying account number must be 0 for first transactions.
x/authz/CHANGELOG.md
x/bank/CHANGELOG.md
x/feegrant/CHANGELOG.md
Noted breaking changes regarding BaseAccount creation removal, module updates, and new features.
client/test_helpers.go Updated error messages for better identification.
x/auth/types/account_retriever.go Updated error handling to return nil for non-existing accounts.

Assessment against linked issues

Objective Addressed Explanation
Prevent the bank from initializing a BaseAccount for non-existent accounts. (#19092)
Remove code triggering BaseAccount initialization for non-existent accounts. (#19092)
Adjust SetPubKeyDecorator logic for account creation without associated pubkeys. (#19092)
Allow bank balance existence without a corresponding account. (#19092)
Ensure the bank no longer initializes accounts automatically. (#19092)
Enable accounts to initialize themselves via transaction with pubkey, paying transaction fees. (#19092)
Maintain ability for accounts to pay fees for transactions, even if the account does not have a pubkey initially. (#19092)

The changes align with the objectives outlined in the linked issue, addressing the need to prevent automatic BaseAccount creation for non-existent accounts and allowing for a more intentional account initialization process.

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.

@tac0turtle tac0turtle changed the title refactor(bank): avoid creating baseaccount refactor(bank & feegrant): avoid creating baseaccount Feb 1, 2024
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 9822b43 and c26ee9c.
Files selected for processing (1)
  • client/tx/factory.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/tx/factory.go

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

After the updates, this looks good to me know (pending addressing @julienrbrt's comment)

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 c26ee9c and a5e4320.
Files selected for processing (2)
  • client/test_helpers.go (3 hunks)
  • x/auth/types/account_retriever.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • client/test_helpers.go
  • x/auth/types/account_retriever.go

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! one nit about bringing back the error check in client factory, now we return no error when the account doesn't exist in the account retriever.

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 a5e4320 and 4125905.
Files selected for processing (1)
  • client/tx/factory.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client/tx/factory.go

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 4125905 and 1a81a74.
Files selected for processing (7)
  • tests/integration/gov/abci_test.go (3 hunks)
  • tests/integration/gov/keeper/tally_test.go (1 hunks)
  • x/auth/ante/ante_test.go (2 hunks)
  • x/auth/ante/feegrant_test.go (2 hunks)
  • x/auth/types/account_retriever.go (2 hunks)
  • x/authz/keeper/msg_server.go (1 hunks)
  • x/feegrant/keeper/keeper.go (1 hunks)
Additional comments: 9
x/auth/types/account_retriever.go (1)
  • 78-80: LGTM. The addition of handling for codes.NotFound improves clarity and error handling for non-existent accounts.
x/auth/ante/feegrant_test.go (3)
  • 59-59: LGTM. Adjusting the valid flag to true for cases without an existing account aligns with the PR's objectives.
  • 63-66: LGTM. Using authtypes.NewBaseAccountWithAddress for creating test accounts without automatic BaseAccount creation aligns with the PR's objectives.
  • 81-81: LGTM. The adjustment for the "no fee with no account" case aligns with the PR's objectives to handle non-existent accounts more gracefully.
tests/integration/gov/keeper/tally_test.go (1)
  • 356-361: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [1-1]

The file focuses on integration tests for the governance module's tallying functionality. Ensure that the tests cover all relevant scenarios for vote tallying, including edge cases.

tests/integration/gov/abci_test.go (3)
  • 363-364: Account creation logic added without checking if the account already exists. This issue was previously flagged and a solution was provided. Ensure the fix is applied to prevent redundant account creation.
  • 426-428: Account creation logic added without checking if the account already exists. This issue was previously flagged and a solution was provided. Ensure the fix is applied to prevent redundant account creation.
  • 507-508: Account creation logic added without checking if the account already exists. This issue was previously flagged and a solution was provided. Ensure the fix is applied to prevent redundant account creation.
x/auth/ante/ante_test.go (1)
  • 164-171: > 📝 NOTE

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

The change in expected behavior for SendCoinsFromAccountToModule to return nil instead of an error in the TestAnteHandlerSigErrors function aligns with the PR's objective to modify account creation logic. Ensure this change is consistent with the intended logic across the SDK and does not affect other dependent tests or functionalities.

@tac0turtle tac0turtle enabled auto-merge February 13, 2024 12:43
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 1a81a74 and e4568b7.
Files selected for processing (1)
  • x/auth/ante/ante_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/auth/ante/ante_test.go

@tac0turtle tac0turtle added this pull request to the merge queue Feb 13, 2024
Merged via the queue into main with commit 869c96c Feb 13, 2024
65 of 67 checks passed
@tac0turtle tac0turtle deleted the marko/19092 branch February 13, 2024 12:54
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

🐎🐎🐎🐎

if !genesis {
accNum = acc.GetAccountNumber()
}

// if the account number is 0 and the account is signing, the sign doc will not have an account number
if acc.GetSequence() == 0 && newlyCreated {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the acc.GetSequence() == 0 obsolete here because whenever newlyCreated is true, the sequence is 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but it doesn't hurt in the grand scheme of things.

@tac0turtle
Copy link
Member Author

reminder: add changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants