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): use transaction service #19967

Merged
merged 6 commits into from
Apr 10, 2024
Merged

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Apr 5, 2024

Description

Follow-up of #19953.
After this, I can continue: #19949


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 new execution mode checks across transaction and authentication processes.
  • Refactor
    • Refactored transaction checking and execution modes to improve efficiency and readability.
    • Updated ante handlers to utilize a centralized transaction service for execution mode retrieval.
    • Enhanced signature verification process for better performance and security.
  • Documentation
    • Added deprecation comments for certain functionalities to guide future development.
  • Bug Fixes
    • Fixed an issue in fee logic API by adjusting conditional statements related to environment usage.
  • Tests
    • Updated and added test cases to reflect changes in transaction and authentication logic.

@julienrbrt julienrbrt requested a review from a team as a code owner April 5, 2024 15:57
Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Walkthrough

Walkthrough

The update focuses on streamlining transaction processing and authentication within the SDK by centralizing execution mode logic using the transaction.Service. Notable changes include enhancements to transaction checking and execution modes, deprecation of certain functionalities, and improvements in signature verification and account management within the x/auth module.

Changes

File(s) Change Summary
simapp/ante.go, x/auth/ante/ante.go Updated NewAnteHandler to include options.AccountKeeper in decorator calls.
x/auth/ante/basic.go Added import "cosmossdk.io/core/transaction"; refactored ValidateBasicDecorator.
x/auth/ante/basic_test.go Modified TestValidateBasic to include suite.accountKeeper in decorator call.
x/auth/ante/unordered.go Updated UnorderedTxDecorator and NewUnorderedTxDecorator to include env appmodule.Environment.
x/auth/ante/unordered_test.go Introduced suite setup and passed suite.accountKeeper to ante.NewUnorderedTxDecorator.

Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2611c90 and e589a20.
Files selected for processing (6)
  • simapp/ante.go (1 hunks)
  • x/auth/ante/ante.go (1 hunks)
  • x/auth/ante/basic.go (7 hunks)
  • x/auth/ante/basic_test.go (1 hunks)
  • x/auth/ante/unordered.go (4 hunks)
  • x/auth/ante/unordered_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (4)
  • simapp/ante.go
  • x/auth/ante/ante.go
  • x/auth/ante/basic_test.go
  • x/auth/ante/unordered_test.go
Additional comments not posted (7)
x/auth/ante/unordered.go (4)

33-33: The addition of the env field in UnorderedTxDecorator aligns with the PR's objective to utilize the transaction.Service for execution mode checks. This change is crucial for centralizing transaction handling logic.


36-40: The updated constructor now correctly initializes the UnorderedTxDecorator with the new env parameter. This ensures that the environment is properly passed and utilized within the decorator.


72-72: Using d.env.TransactionService.ExecMode(ctx) for execution mode checks in AnteHandle method is a significant improvement. It leverages the centralized transaction service, enhancing modularity and maintainability.


77-77: The return statement in AnteHandle method correctly maintains the unchanged behavior of calling the next handler in the chain, ensuring that the decorator pattern is preserved.

x/auth/ante/basic.go (3)

24-25: The addition of the env field in ValidateBasicDecorator is well-aligned with the PR's objectives, ensuring that the environment is accessible for execution mode checks.


27-30: The constructor for ValidateBasicDecorator has been correctly updated to include the env parameter, ensuring that the environment is properly initialized for use in the decorator.


36-36: The use of txService.ExecMode(ctx) in the AnteHandle method for execution mode checks is a key improvement, promoting the use of the centralized transaction service and enhancing code modularity.


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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

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

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

Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5d04deb and 78a4c7a.
Files selected for processing (17)
  • core/transaction/service.go (1 hunks)
  • types/context.go (1 hunks)
  • x/auth/CHANGELOG.md (1 hunks)
  • x/auth/ante/ante.go (1 hunks)
  • x/auth/ante/basic.go (7 hunks)
  • x/auth/ante/basic_test.go (1 hunks)
  • x/auth/ante/expected_keepers.go (1 hunks)
  • x/auth/ante/export_test.go (1 hunks)
  • x/auth/ante/ext.go (1 hunks)
  • x/auth/ante/fee.go (4 hunks)
  • x/auth/ante/setup.go (1 hunks)
  • x/auth/ante/sigverify.go (6 hunks)
  • x/auth/ante/sigverify_internal_test.go (2 hunks)
  • x/auth/ante/unordered.go (4 hunks)
  • x/auth/ante/unordered_test.go (6 hunks)
  • x/auth/ante/validator_tx_fee.go (1 hunks)
  • x/auth/keeper/keeper.go (2 hunks)
Additional Context Used
Path-based Instructions (17)
x/auth/ante/export_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

core/transaction/service.go (1)

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

x/auth/ante/expected_keepers.go (1)

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

x/auth/ante/ext.go (1)

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

x/auth/ante/ante.go (1)

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

x/auth/ante/validator_tx_fee.go (1)

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

x/auth/ante/sigverify_internal_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/ante/unordered.go (1)

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

x/auth/ante/setup.go (1)

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

x/auth/CHANGELOG.md (1)

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

x/auth/ante/fee.go (1)

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

x/auth/ante/unordered_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/ante/basic.go (1)

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

x/auth/ante/basic_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/auth/keeper/keeper.go (1)

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

types/context.go (1)

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

x/auth/ante/sigverify.go (1)

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

Additional comments not posted (24)
x/auth/ante/export_test.go (2)

8-8: Consider renaming SimSecp256k1PubkeyInternal to follow Go's naming conventions for exported variables, which typically do not include the word "Internal".


10-11: Ensure proper error handling in tests when using SetSVDPubKey. It's crucial to check for errors to avoid false positives in test results.

x/auth/ante/expected_keepers.go (2)

13-15: Introducing the HasEnvironment interface is a good practice for decoupling and enhancing modularity. Ensure that all relevant components implement this interface as needed.


25-26: Adding the Environment() method to the AccountKeeper interface aligns with the objective of accessing the new transaction service. Verify that all implementations of AccountKeeper are updated accordingly.

x/auth/ante/ext.go (1)

52-52: Modifying the AnteHandle function to always pass false for the simulation flag may impact the behavior of subsequent decorators. Ensure this change aligns with the intended logic and does not inadvertently affect transaction processing.

x/auth/ante/ante.go (1)

45-45: Including options.AccountKeeper in the NewValidateBasicDecorator call is a significant change that enhances the decorator's functionality. Ensure that the ValidateBasicDecorator is properly updated to utilize the AccountKeeper for its intended purpose.

x/auth/ante/validator_tx_fee.go (1)

27-27: Modifying the conditional statement to use ctx.ExecMode() directly addresses the issue mentioned. However, ensure that this change does not introduce any unintended side effects, especially in contexts where the execution mode might differ from expectations.

x/auth/ante/sigverify_internal_test.go (2)

38-38: Refactoring to use ante.NewSigVerificationDecorator with a mock AccountKeeper is a good practice for isolating test cases. Ensure that all test cases are updated to reflect this new setup.


53-53: Ensure that all new test cases introduced properly handle errors and validate the expected outcomes. This is crucial for maintaining the reliability and accuracy of the test suite.

Also applies to: 60-62, 68-68, 76-76, 84-84

x/auth/ante/unordered.go (2)

32-32: Adding an AccountKeeper field to the UnorderedTxDecorator and including it as a parameter in the NewUnorderedTxDecorator function is a significant change that enhances the decorator's functionality. Ensure that the AccountKeeper is utilized effectively within the AnteHandle method for execution mode checks.

Also applies to: 35-39


71-71: Using the AccountKeeper to determine the execution mode within the AnteHandle method aligns with the PR's objective of centralizing execution mode checks. Verify that this approach is consistently applied across all relevant ante handlers.

x/auth/ante/setup.go (2)

70-70: Ensure the change in logic does not affect non-simulation execution paths.


77-77: Update documentation and changelog to reflect the breaking change in SetGasMeter function usage.

x/auth/CHANGELOG.md (3)

36-36: The changelog entry accurately describes the refactor of ante handlers. Ensure all related documentation is updated accordingly.


36-36: The changelog entry about moving signature verification is clear and concise.


36-36: Ensure the behavior change regarding BaseAccount creation and the requirement to use account number 0 for non-existent accounts is well-documented in relevant sections beyond the changelog.

x/auth/ante/fee.go (2)

7-7: Ensure the new import cosmossdk.io/core/transaction is used appropriately throughout the project.


58-64: > 📝 NOTE

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

Refactoring to use txService for execution mode checks improves modularity. Ensure comprehensive tests cover these changes, especially in different execution modes.

Would you like assistance in creating additional tests for the new logic introduced in this refactor?

x/auth/ante/unordered_test.go (1)

26-28: The addition of suite setup before creating a chain in test functions enhances the test environment setup. Review the entire test suite to ensure consistency in test setup across all tests.

x/auth/ante/basic.go (2)

4-4: Ensure the new import cosmossdk.io/core/transaction is used appropriately throughout the project.


19-38: > 📝 NOTE

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

Refactoring to include ak AccountKeeper in ValidateBasicDecorator and using txService.ExecMode(ctx) for execution mode checks improves modularity. Ensure comprehensive tests cover these changes, especially in different execution modes.

Would you like assistance in creating additional tests for the new logic introduced in this refactor?

x/auth/ante/basic_test.go (1)

39-39: The update to NewValidateBasicDecorator in the test function aligns with the changes in the implementation. Review the entire test suite to ensure consistency in handling new dependencies.

x/auth/keeper/keeper.go (1)

56-58: Adding the Environment() method to the AccountKeeperI interface and its implementation improves modularity. Review the module to ensure this new method is used consistently where access to the environment is needed.

x/auth/ante/sigverify.go (1)

314-314: Ensure that the check for ExecModeSimulate is consistent across the codebase.

-	if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigverifyTx() {
+	if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate || ctx.IsReCheckTx() || !ctx.IsSigVerifyTx() {

This change corrects a potential inconsistency in method naming (IsSigverifyTx vs. IsSigVerifyTx). Please verify the correct method name as per the Cosmos SDK's naming conventions and ensure consistency across the codebase.

types/context.go Show resolved Hide resolved
types/context.go Show resolved Hide resolved
types/context.go Show resolved Hide resolved
@@ -10,6 +10,7 @@ import (
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
"google.golang.org/protobuf/types/known/anypb"

"cosmossdk.io/core/transaction"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider grouping the Cosmos SDK imports together for better readability.

	import (
		"context"
		"encoding/base64"
		"encoding/hex"
		"errors"
		"fmt"

		secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
		"google.golang.org/protobuf/types/known/anypb"

+		"cosmossdk.io/core/transaction"
		errorsmod "cosmossdk.io/errors"
		storetypes "cosmossdk.io/store/types"
		aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1"
		authsigning "cosmossdk.io/x/auth/signing"
		"cosmossdk.io/x/auth/types"
		txsigning "cosmossdk.io/x/tx/signing"

		codectypes "github.com/cosmos/cosmos-sdk/codec/types"
		"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
		kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
		"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
		"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
		cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
		"github.com/cosmos/cosmos-sdk/types/tx"
		"github.com/cosmos/cosmos-sdk/types/tx/signing"
		sdk "github.com/cosmos/cosmos-sdk/types"
		sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
	)

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
"cosmossdk.io/core/transaction"
import (
"context"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
secp256k1dcrd "github.com/decred/dcrd/dcrec/secp256k1/v4"
"google.golang.org/protobuf/types/known/anypb"
"cosmossdk.io/core/transaction"
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1"
authsigning "cosmossdk.io/x/auth/signing"
"cosmossdk.io/x/auth/types"
txsigning "cosmossdk.io/x/tx/signing"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256r1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

@@ -280,7 +281,7 @@
pubKey cryptotypes.PubKey,
signature signing.SignatureV2,
) error {
if ctx.ExecMode() == sdk.ExecModeSimulate && pubKey == nil {
if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && pubKey == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace the direct comparison of pubKey with nil with a more idiomatic check for nil interfaces in Go.

-	if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && pubKey == nil {
+	if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && !reflect.ValueOf(pubKey).IsValid() {

This change ensures that the check for a nil pubKey correctly handles cases where pubKey is a nil interface, which is a common source of subtle bugs in Go code.


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
if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && pubKey == nil {
if svd.ak.Environment().TransactionService.ExecMode(ctx) == transaction.ExecModeSimulate && !reflect.ValueOf(pubKey).IsValid() {

@@ -384,7 +385,7 @@
if txPubKey == nil {
// if we're not in simulation mode, and we do not have a valid pubkey
// for this signer, then we simply error.
if ctx.ExecMode() != sdk.ExecModeSimulate {
if svd.ak.Environment().TransactionService.ExecMode(ctx) != transaction.ExecModeSimulate {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the error case when the execution mode is not ExecModeSimulate more gracefully.

-		if svd.ak.Environment().TransactionService.ExecMode(ctx) != transaction.ExecModeSimulate {
+		if execMode := svd.ak.Environment().TransactionService.ExecMode(ctx); execMode != transaction.ExecModeSimulate {
+			return fmt.Errorf("the account %s is without a pubkey and did not provide a pubkey in the tx to set it; execution mode: %s", acc.GetAddress().String(), execMode)
+		}

Including the execution mode in the error message provides more context for debugging and understanding why the operation failed, especially in environments where the execution mode might vary.


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
if svd.ak.Environment().TransactionService.ExecMode(ctx) != transaction.ExecModeSimulate {
if execMode := svd.ak.Environment().TransactionService.ExecMode(ctx); execMode != transaction.ExecModeSimulate {
return fmt.Errorf("the account %s is without a pubkey and did not provide a pubkey in the tx to set it; execution mode: %s", acc.GetAddress().String(), execMode)
}

@@ -9,7 +9,7 @@ type ExecMode uint8
// For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package.
const (
ExecModeCheck ExecMode = iota
_
ExecModeReCheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process has identified that ExecModeReCheck is not referenced in the codebase outside of its definition. This suggests that the integration of the new execution mode might not be complete, as there are no instances where it is being checked or set in the context of execution modes. It's advisable to review the implementation to ensure that ExecModeReCheck is properly utilized where applicable.

Analysis chain

Adding ExecModeReCheck enhances execution mode handling. Ensure that all references to execution modes are updated to include this new mode where applicable.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for missing references to ExecModeReCheck in the codebase.
rg 'ExecMode' --type go | rg -v 'ExecModeReCheck'

Length of output: 5035

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

Actionable comments outside the diff hunks (3)
x/auth/CHANGELOG.md (3)

Line range hint 43-43: Replace "take" with "takes" to match the subject-verb agreement.

- `appd tx vesting create-vesting-account` take an amount of coin as last argument instead of second.
+ `appd tx vesting create-vesting-account` takes an amount of coin as last argument instead of second.

Line range hint 47-47: Clarify the sentence by avoiding abbreviations and improving readability.

- Address and validator address codecs are now arguments of `NewTxConfig`.
+ Address codecs and validator address codecs are now arguments of the `NewTxConfig` function.

Line range hint 52-52: Consider adding an apostrophe to "accounts module" to indicate possession.

- The accounts module is required for creating vesting accounts on a running chain.
+ The account's module is required for creating vesting accounts on a running chain.
Review Status

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 78a4c7a and 93f0734.
Files selected for processing (1)
  • x/auth/CHANGELOG.md (1 hunks)
Additional Context Used
Path-based Instructions (1)
x/auth/CHANGELOG.md (1)

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

x/auth/CHANGELOG.md Show resolved Hide resolved
x/auth/CHANGELOG.md Show resolved Hide resolved
x/auth/CHANGELOG.md Show resolved Hide resolved
x/auth/CHANGELOG.md Show resolved Hide resolved
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: 1

Comment on lines +296 to +328
// set custom ante handlers
app.setCustomAnteHandler()

if err := app.Load(loadLatest); err != nil {
panic(err)
}

return app
}

// overwritte default ante handlers with custom ante handlers
// set SkipAnteHandler to true in app config and set custom ante handler on baseapp
func (app *SimApp) setCustomAnteHandler() {
anteHandler, err := NewAnteHandler(
HandlerOptions{
ante.HandlerOptions{
AccountKeeper: app.AuthKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitBreakerKeeper,
app.UnorderedTxManager,
},
)
if err != nil {
panic(err)
}

// Set the AnteHandler for the app
app.SetAnteHandler(anteHandler)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the implementation of setCustomAnteHandler for error handling and modularity.

The setCustomAnteHandler function directly panics if an error occurs while setting up the custom ante handler. Consider a more graceful error handling strategy that allows the application to recover or at least provide more context about the error. Additionally, this function could be made more modular by separating the creation of the HandlerOptions struct and the actual setting of the ante handler into distinct steps or functions.

func (app *SimApp) setCustomAnteHandler() error {
-	anteHandler, err := NewAnteHandler(
+	options := HandlerOptions{
+		ante.HandlerOptions{
+			AccountKeeper:   app.AuthKeeper,
+			BankKeeper:      app.BankKeeper,
+			SignModeHandler: app.txConfig.SignModeHandler(),
+			FeegrantKeeper:  app.FeeGrantKeeper,
+			SigGasConsumer:  ante.DefaultSigVerificationGasConsumer,
+		},
+		&app.CircuitBreakerKeeper,
+		app.UnorderedTxManager,
+	}
+	anteHandler, err := NewAnteHandler(options)
	if err != nil {
-		panic(err)
+		return fmt.Errorf("failed to set custom ante handler: %w", err)
	}
	app.SetAnteHandler(anteHandler)
+	return nil
}

-	app.setCustomAnteHandler()
+	if err := app.setCustomAnteHandler(); err != nil {
+		panic(err)
+	}

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
// set custom ante handlers
app.setCustomAnteHandler()
if err := app.Load(loadLatest); err != nil {
panic(err)
}
return app
}
// overwritte default ante handlers with custom ante handlers
// set SkipAnteHandler to true in app config and set custom ante handler on baseapp
func (app *SimApp) setCustomAnteHandler() {
anteHandler, err := NewAnteHandler(
HandlerOptions{
ante.HandlerOptions{
AccountKeeper: app.AuthKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitBreakerKeeper,
app.UnorderedTxManager,
},
)
if err != nil {
panic(err)
}
// Set the AnteHandler for the app
app.SetAnteHandler(anteHandler)
}
// set custom ante handlers
if err := app.setCustomAnteHandler(); err != nil {
panic(err)
}
if err := app.Load(loadLatest); err != nil {
panic(err)
}
return app
}
// overwritte default ante handlers with custom ante handlers
// set SkipAnteHandler to true in app config and set custom ante handler on baseapp
func (app *SimApp) setCustomAnteHandler() error {
options := HandlerOptions{
ante.HandlerOptions{
AccountKeeper: app.AuthKeeper,
BankKeeper: app.BankKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
FeegrantKeeper: app.FeeGrantKeeper,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
&app.CircuitBreakerKeeper,
app.UnorderedTxManager,
}
anteHandler, err := NewAnteHandler(options)
if err != nil {
return fmt.Errorf("failed to set custom ante handler: %w", err)
}
app.SetAnteHandler(anteHandler)
return nil
}

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

left a question on the account keeper, it looks like we can pass in env instead of a module?

x/auth/ante/basic.go Outdated Show resolved Hide resolved
Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

@julienrbrt julienrbrt added this pull request to the merge queue Apr 10, 2024
Merged via the queue into main with commit 17bb4c7 Apr 10, 2024
61 of 62 checks passed
@julienrbrt julienrbrt deleted the julien/use-txservice branch April 10, 2024 18:56
alpe added a commit to alpe/cosmos-sdk that referenced this pull request Apr 15, 2024
* main: (25 commits)
  fix: Implement gogoproto customtype to secp256r1 keys (cosmos#20027)
  fix(x/epochs): avoid invalid epoch duration in simulation (cosmos#20030)
  fix(x/bank): align query with multi denoms for send-enabled (cosmos#20028)
  refactor(x/slashing)!: remove Accounts String (cosmos#20026)
  refactor(x/evidence)!: remove Address.String() (cosmos#20016)
  chore: make telemetry consistent (cosmos#20025)
  chore: prepare x/tx changelog (cosmos#20015)
  build(deps): Bump actions/add-to-project from 1.0.0 to 1.0.1 (cosmos#20018)
  feat(x/bank): support depinject for send restrictions (cosmos#20014)
  feat: Conditionally emit metrics based on enablement (cosmos#19903)
  fix(store): fix the typo (cosmos#20011)
  docs(x/feegrant): fix allowance typo (cosmos#20000)
  chore(confix): update latest config value (cosmos#20012)
  refactor(x/auth): auth module can recognize x/accounts account (cosmos#20002)
  fix(mempool): use no-op mempool as default (cosmos#19970)
  fix(simapp): add epoch store to upgrade (cosmos#20007)
  test(kv): add unit tests for the helpers functions kv.AssertKeyAtLeas… (cosmos#19965)
  feat(x/tx): Rename custom Amino JSON encoder to "inline_json" (cosmos#19919)
  refactor(x/auth): use transaction service (cosmos#19967)
  fix(client/v2): add encoder for `cosmos.base.v1beta1.DecCoin` (cosmos#19976)
  ...
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