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(x/auth/tx): extend app module + docs #21409

Merged
merged 4 commits into from
Aug 28, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Aug 26, 2024

Description

Allow users to define tx validator in their app.go without creating a module.
This can be done by supplying them to depinject as []TxValidator{}


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, you can find examples of the prefixes below:
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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

    • Enhanced transaction validation module introduced, allowing for flexible registration of custom transaction validators.
    • Improved documentation for the x/auth/tx package, clarifying dependency injection and application module functionalities.
  • Bug Fixes

    • Minor grammatical improvements made to documentation comments for better clarity.

Copy link
Contributor

coderabbitai bot commented Aug 26, 2024

Walkthrough

Walkthrough

The changes involve updates to the Cosmos SDK's x/auth module, focusing on documentation enhancements and structural modifications. Key updates include improved comments for the NewAppModule function, expanded documentation in the README.md regarding dependency injection, and significant refactoring in the depinject.go and module.go files to introduce new transaction validation capabilities. These updates streamline the module architecture and enhance the flexibility of transaction handling.

Changes

File Path Change Summary
x/auth/module.go Updated comment for NewAppModule function for grammatical correctness.
x/auth/tx/README.md Added section on "Depinject & App Module" detailing dependency injection and transaction validators.
x/auth/tx/config/depinject.go Introduced ExtraTxValidators in ModuleInputs; rearranged fields in ModuleOutputs; removed AppModule struct.
x/auth/tx/config/module.go Introduced new transaction validation module with TxValidator method and updated AppModule struct.

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

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.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Aug 26, 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.

Actionable comments posted: 2

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 19e0de5 and 0a0bfc5.

Files selected for processing (4)
  • x/auth/module.go (1 hunks)
  • x/auth/tx/README.md (2 hunks)
  • x/auth/tx/config/depinject.go (4 hunks)
  • x/auth/tx/config/module.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • x/auth/module.go
Additional context used
Path-based instructions (3)
x/auth/tx/config/module.go (1)

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

x/auth/tx/config/depinject.go (1)

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

x/auth/tx/README.md (1)

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

LanguageTool
x/auth/tx/README.md

[misspelling] ~66-~66: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...is there to setup ante/post handlers on an runtime app (via baseapp options) and t...

(EN_A_VS_AN)

Additional comments not posted (9)
x/auth/tx/config/module.go (4)

11-12: LGTM!

The type alias TxValidator is correctly defined.

The code changes are approved.


31-39: LGTM!

The constructor function NewAppModule correctly initializes the AppModule struct with the provided parameters.

The code changes are approved.


42-43: LGTM!

The method IsAppModule is correctly implemented to satisfy the appmodule.AppModule interface requirements.

The code changes are approved.


45-46: LGTM!

The method IsOnePerModuleType is correctly implemented to satisfy the appmodule.AppModule interface requirements.

The code changes are approved.

x/auth/tx/config/depinject.go (4)

59-59: LGTM!

The addition of ExtraTxValidators enhances the flexibility of the module by allowing extra transaction validators.

The code changes are approved.


65-65: LGTM!

The addition of Module improves the organization of the output structure.

The code changes are approved.


153-158: LGTM!

The function ProvideModule correctly initializes the ModuleOutputs struct with the provided parameters.

The code changes are approved.


Line range hint 161-178: LGTM!

The function newAnteHandler correctly initializes the anteHandler with the provided parameters.

The code changes are approved.

x/auth/tx/README.md (1)

Line range hint 71-278: LGTM!

The documentation is clear and comprehensive.

The code changes are approved.

Tools
LanguageTool

[misspelling] ~66-~66: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...is there to setup ante/post handlers on an runtime app (via baseapp options) and t...

(EN_A_VS_AN)

Comment on lines 48 to 56
// TxValidator implements appmodule.HasTxValidator.
func (a AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error {
for _, validator := range a.txValidators {
if err := validator(ctx, tx); err != nil {
return err
}
}

return a.sigVerification.ValidateTx(ctx, tx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a check for the presence of txValidators.

The method correctly iterates over the txValidators slice and validates the transaction. However, adding a check for the presence of txValidators before iterating can improve robustness.

Apply this diff to add the check:

 func (a AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error {
+  if len(a.txValidators) == 0 {
+    return nil
+  }
   for _, validator := range a.txValidators {
     if err := validator(ctx, tx); err != nil {
       return err
     }
   }
   return a.sigVerification.ValidateTx(ctx, tx)
 }
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// TxValidator implements appmodule.HasTxValidator.
func (a AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error {
for _, validator := range a.txValidators {
if err := validator(ctx, tx); err != nil {
return err
}
}
return a.sigVerification.ValidateTx(ctx, tx)
func (a AppModule) TxValidator(ctx context.Context, tx transaction.Tx) error {
if len(a.txValidators) == 0 {
return nil
}
for _, validator := range a.txValidators {
if err := validator(ctx, tx); err != nil {
return err
}
}
return a.sigVerification.ValidateTx(ctx, tx)
}

Comment on lines +65 to +66
The `x/auth/tx/config` contains a depinject module and app module.
The depinject module is there to setup ante/post handlers on an runtime app (via baseapp options) and the tx validator on the runtime/v2 app (via app module). It as well outputs the `TxConfig` and `TxConfigOptions` for the app.
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct grammatical error.

The sentence "is there to setup ante/post handlers on an runtime app" contains a grammatical error. Use "a" instead of "an".

Apply this diff to fix the grammatical error:

 The depinject module is there to setup ante/post handlers on an runtime app (via baseapp options) and the tx validator on the runtime/v2 app (via app module). It as well outputs the `TxConfig` and `TxConfigOptions` for the app.
+The depinject module is there to setup ante/post handlers on a runtime app (via baseapp options) and the tx validator on the runtime/v2 app (via app module). It as well outputs the `TxConfig` and `TxConfigOptions` for the app.

Committable suggestion was skipped due to low confidence.

Tools
LanguageTool

[misspelling] ~66-~66: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...is there to setup ante/post handlers on an runtime app (via baseapp options) and t...

(EN_A_VS_AN)

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 0a0bfc5 and cbe3973.

Files selected for processing (1)
  • x/auth/tx/config/depinject.go (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/auth/tx/config/depinject.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.

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 cbe3973 and 02cce39.

Files selected for processing (2)
  • x/auth/tx/config/depinject.go (4 hunks)
  • x/auth/tx/config/module.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/auth/tx/config/module.go
Additional context used
Path-based instructions (1)
x/auth/tx/config/depinject.go (1)

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

Additional comments not posted (3)
x/auth/tx/config/depinject.go (3)

17-17: LGTM!

The import of appmodule/v2 is necessary for the new modular approach in transaction handling.

The code changes are approved.


54-62: LGTM!

The addition of the ExtraTxValidators field enhances the flexibility of the module by allowing extra transaction validators.

The code changes are approved.


156-161: LGTM!

The change to ModuleOutputs reflects a shift towards a more modular approach in handling transaction validation.

The code changes are approved.

Copy link
Contributor

@hieuvubk hieuvubk left a comment

Choose a reason for hiding this comment

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

LGTM

@julienrbrt julienrbrt added this pull request to the merge queue Aug 28, 2024
Merged via the queue into main with commit 355f4d7 Aug 28, 2024
75 checks passed
@julienrbrt julienrbrt deleted the julien/extend-xauthtxconfig branch August 28, 2024 09:52
mergify bot pushed a commit that referenced this pull request Aug 28, 2024
julienrbrt added a commit that referenced this pull request Aug 28, 2024
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants