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/accounts): wire x/accounts to simapp #18253

Merged
merged 43 commits into from
Nov 3, 2023
Merged

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Oct 25, 2023

Description

Closes: #XXXX


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
  • added ! to 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
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • 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 ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Summary by CodeRabbit

New Features:

  • Added a new accounts module to manage user accounts, improving user management capabilities.
  • Introduced new RPC methods to the Query service for querying account schemas and retrieving account types, enhancing data retrieval options.
  • Added a new accountstd package that exports types and functions for implementing smart accounts, expanding the functionality for smart accounts.
  • Introduced a new CLI package for transactions and queries related to a specific module, improving command-line interactions.

Refactor:

  • Updated various modules to use AuthKeeper instead of AccountKeeper, enhancing code consistency.
  • Modified several message structs and field names/types, improving data structure efficiency.
  • Replaced proto.Message with protoiface.MessageV1 in various places, aligning with updated protobuf standards.

Tests:

  • Updated test cases to reflect changes in function signatures and implementations, ensuring code reliability.

Chores:

  • Deprecated several types in the cosmos/store/internal/kv/v1beta1/kv.proto file, preparing for future updates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2023

Walkthrough

The changes primarily revolve around the introduction of a new module called "accounts" and the modification of existing modules to accommodate this new addition. The "accounts" module provides functionality for managing user accounts, including creating and querying accounts. The changes also involve the introduction of new interfaces, types, and functions, as well as modifications to existing ones to improve the overall structure and functionality of the codebase.

Changes

File(s) Summary
api/cosmos/accounts/v1/tx.pulsar.go, proto/cosmos/accounts/v1/tx.proto Added and updated import statements, modified message structs, and introduced new RPC methods related to querying and retrieving account information.
proto/cosmos/accounts/testing/counter/v1/counter.proto Introduced a new protocol buffer file (counter.proto) that defines messages for initializing and increasing a counter, as well as querying the counter value. The file is part of the cosmos.accounts.testing.counter.v1 package.
proto/cosmos/accounts/v1/query.proto Introduced three new RPC methods to the Query service: Schema, AccountType, and their corresponding request and response message types. These methods are used for querying account schemas and retrieving the account type for a given address.
proto/cosmos/accounts/v1/tx.proto Added an import statement for the cosmos/msg/v1/msg.proto file. Added the option (cosmos.msg.v1.service) = true; option to the Msg service, indicating that it is a service for the cosmos.msg.v1 package. Added the option (cosmos.msg.v1.signer) = "sender"; option to the MsgInit and MsgExecute messages, specifying that the sender field should be used as the signer for these messages.
simapp/app.go, simapp/app_test.go, simapp/app_v2.go Added import statements for the accounts package and its dependencies. Replaced references to AccountKeeper with AuthKeeper and AccountsKeeper. Modified various functions to use these new keepers.
x/accounts/account_test.go Added an import statement for the package "cosmossdk.io/x/accounts/accountstd". Modified the NewTestAccount function to take a parameter of type accountstd.Dependencies and return a tuple of *TestAccount and error. Accessed the SchemaBuilder field of the Counter struct from the Dependencies parameter.
x/accounts/accountstd/exports.go Introduced a new package called accountstd that exports types and functions for implementing smart accounts. Added several exported types and functions that are aliases of corresponding types and functions in the implementation package. Added several new functions for registering handlers and executing queries and messages for smart accounts.
x/accounts/cli/cli.go Added a new package called cli that provides commands for transactions and queries related to a specific module.
x/accounts/genesis_test.go Modified the TestGenesis function to replace the proto.Message type with protoiface.MessageV1 in the queryModuleFunc signature. Passed the NewTestAccount function as an argument to implementation.AddAccount when creating a new keeper.
x/accounts/internal/implementation/api_builder.go Removed the decodeRequest and encodeResponse fields in the InitBuilder struct and replaced them with a schema field of type HandlerSchema. Renamed the handlers field in the ExecuteBuilder struct to HandlerSchema and changed its type to map[string]HandlerSchema.
x/accounts/internal/implementation/context.go Introduced changes to the ModuleExecFunc and ModuleQueryFunc types, the contextValue struct, and the ExecModule and QueryModule functions.
x/accounts/internal/implementation/context_test.go Added an import statement for "google.golang.org/protobuf/runtime/protoiface". Modified the function signature of the second callback function in the MakeAccountContext function. Updated the implementation of the second and third callback functions in the MakeAccountContext function.
x/accounts/internal/implementation/implementation.go Refactored the code to import additional packages, define new types and functions, and modify existing ones. Added the AddAccount function to facilitate the creation of smart accounts. Added the MakeAccountsMap function to create a map of smart accounts. Expanded the Implementation struct to include new fields for schemas. Removed the DecodeInitRequest and EncodeInitResponse fields in the Implementation struct.
x/accounts/internal/implementation/implementation_test.go Modified the test cases for the Implementation struct to use the TxEncode and TxDecode methods from the RequestSchema and ResponseSchema fields of the InitHandlerSchema struct to encode and decode request and response messages. Removed the EncodeInitResponse function.
x/accounts/internal/implementation/intermodule.go Added a new package called "implementation". No other changes are made.
x/accounts/internal/implementation/protoaccount.go Added imports for google.golang.org/protobuf/encoding/protojson and google.golang.org/protobuf/runtime/protoiface. Extended the ProtoMsg interface to include the protoiface.MessageV1 interface. Modified the RegisterInitHandler and RegisterExecuteHandler functions. Added the RegisterQueryHandler function. Added the NewProtoMessageSchema function.
x/accounts/keeper.go Added imports for google.golang.org/protobuf/runtime/protoiface, cosmossdk.io/core/event, and cosmossdk.io/x/accounts/accountstd. Added new interfaces QueryRouter, MsgRouter, and SignerProvider. Modified the NewKeeper function signature to include the new interfaces and removed the accounts parameter. Added the event.Service parameter to the NewKeeper function. Modified the Keeper struct to include the eventService field. Modified the getSenderFunc and execModuleFunc function signatures. Modified the queryModuleFunc function signature. Added the getMessageName function.
x/accounts/keeper_test.go Added imports for google.golang.org/protobuf/runtime/protoiface and cosmossdk.io/x/accounts/accountstd. Added the eventService struct and implemented the event.Service interface. Modified the newKeeper function to accept a variadic parameter of AccountCreatorFunc. Modified the TestKeeper_Init function to use the accountstd.AddAccount function to add an account. Modified the m.queryModuleFunc and m.execModuleFunc function signatures. Updated the assertions in the test functions.
x/accounts/module.go Introduced a new module called "accounts" that implements various functions and interfaces related to managing user accounts. Includes functions for registering services, handling genesis state, and exporting/importing state. Registers message and query servers for the module.
x/accounts/msg_server.go Introduced changes to the ListenFinalizeBlockRequest, ListenFinalizeBlockResponse, ListenCommitRequest, and ListenCommitResponse types. These types are marked as deprecated and should not be used.
x/accounts/msg_server_test.go Modified the TestMsgServer function to update the function signature and use protoiface.MessageV1 and proto.Merge for encoding and decoding messages.
x/accounts/query_server.go Added two new methods to the queryServer struct: Schema and AccountType. These methods handle error cases and return appropriate responses.
x/accounts/query_server_test.go Added import statements for "cosmossdk.io/x/accounts/accountstd" and "google.golang.org/protobuf/runtime/protoiface". Modified the TestQueryServer function to update the function signature and use protoiface.MessageV1 and proto.Merge for encoding and decoding messages.
x/accounts/testing/counter/counter.go Added a new package called "counter" with an implementation of the Account struct that represents an account with an owner and a counter value. Added methods to initialize the account, increase the counter, and query the counter value.
x/accounts/v1/schema.go Added a new package v1 that includes functions for creating account schemas and a function for retrieving a gRPC service descriptor.
simapp/app.go, simapp/app_test.go, simapp/app_v2.go Added import statements for the accounts package and its related modules. Replaced references to AccountKeeper with AuthKeeper and AccountsKeeper. Modified various functions to use these new keepers.
simapp/upgrades.go Added the import statement "cosmossdk.io/x/accounts" and included the module name "accounts" in the Added field of the storeUpgrades struct.
x/accounts/cli/cli.go Added a new package cli that contains functions for creating command-line interface (CLI) commands related to transactions and queries for a specific module.

🐇🍂 As autumn leaves fall, we code with joy and glee, 🍂🐇

New accounts module, a sight to see! 🎉🎈

With keepers and handlers, and queries galore, 📚🔍

Our codebase grows, forever more! 🌱🌳

So let's hop along, with a skip and a cheer, 🐇🎉

For the season of coding, is truly here! 🍁🍂


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

@testinginprod
Copy link
Contributor Author

@coderabbitai review

@@ -0,0 +1,34 @@
syntax = "proto3";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a test account protofile, to use for simd testing

@@ -23,3 +27,40 @@ message AccountQueryResponse {
// response defines the query response of the account.
bytes response = 1;
}

// SchemaResponse is the response type for the Query/Schema RPC method.
message SchemaRequest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are approximate schema definitions which represent the init/query/exec messages an account can process.

appCodec.InterfaceRegistry().SigningContext(),
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
accountstd.AddAccount("counter", counter.NewAccount),
Copy link
Contributor Author

@testinginprod testinginprod Oct 25, 2023

Choose a reason for hiding this comment

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

this is what we do to wire an account, we give it a name and pass in an account creator function in this case counter.NewAccount

Copy link
Member

Choose a reason for hiding this comment

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

would it be better to have the creation of the keeper and the adding of accounts as two separate steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would only be needed if say you have keeperA depending on accountsKeeper and then accountA depending on keeperA, this is a pattern that I think we want to remove from the SDK.

var _ accountstd.Interface = (*Account)(nil)

// NewAccount creates a new account.
func NewAccount(d accountstd.Dependencies) (Account, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a test account implementation, used in simapp for some manual testing

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 139a29e and c4282a9.
Files ignored due to filter (7)
  • api/cosmos/accounts/v1/query_grpc.pb.go
  • simapp/go.mod
  • simapp/go.sum
  • x/accounts/go.mod
  • x/accounts/go.sum
  • x/accounts/v1/query.pb.go
  • x/accounts/v1/tx.pb.go
Files selected for processing (26)
  • api/cosmos/accounts/v1/tx.pulsar.go (2 hunks)
  • proto/cosmos/accounts/testing/counter/v1/counter.proto (1 hunks)
  • proto/cosmos/accounts/v1/query.proto (2 hunks)
  • proto/cosmos/accounts/v1/tx.proto (3 hunks)
  • simapp/app.go (11 hunks)
  • simapp/app_test.go (1 hunks)
  • x/accounts/account_test.go (2 hunks)
  • x/accounts/accountstd/exports.go (1 hunks)
  • x/accounts/cli/cli.go (1 hunks)
  • x/accounts/genesis_test.go (1 hunks)
  • x/accounts/internal/implementation/api_builder.go (3 hunks)
  • x/accounts/internal/implementation/context.go (4 hunks)
  • x/accounts/internal/implementation/context_test.go (3 hunks)
  • x/accounts/internal/implementation/implementation.go (4 hunks)
  • x/accounts/internal/implementation/implementation_test.go (2 hunks)
  • x/accounts/internal/implementation/intermodule.go (1 hunks)
  • x/accounts/internal/implementation/protoaccount.go (5 hunks)
  • x/accounts/keeper.go (4 hunks)
  • x/accounts/keeper_test.go (6 hunks)
  • x/accounts/module.go (1 hunks)
  • x/accounts/msg_server.go (4 hunks)
  • x/accounts/msg_server_test.go (1 hunks)
  • x/accounts/query_server.go (2 hunks)
  • x/accounts/query_server_test.go (1 hunks)
  • x/accounts/testing/counter/counter.go (1 hunks)
  • x/accounts/v1/schema.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • api/cosmos/accounts/v1/tx.pulsar.go
  • x/accounts/accountstd/exports.go
  • x/accounts/genesis_test.go
  • x/accounts/internal/implementation/intermodule.go
Additional comments: 75
x/accounts/account_test.go (2)
  • 7-7: The import "cosmossdk.io/x/accounts/accountstd" has been added. Ensure that this package is being used in the code and that it is necessary for the functionality of the program.

  • 19-22: The function signature of NewTestAccount has been changed to include an accountstd.Dependencies parameter and it now returns an error as well. Make sure that all calls to this function throughout the codebase have been updated to match the new signature. Also, ensure that the error returned by this function is being handled properly where this function is called.

- func NewTestAccount(sb *collections.SchemaBuilder) *TestAccount {
+ func NewTestAccount(d accountstd.Dependencies) (*TestAccount, error) {
proto/cosmos/accounts/testing/counter/v1/counter.proto (1)
  • 1-34: The protobuf definitions for the messages and responses look good. They are well-structured and the field names are descriptive. The comments provide a clear understanding of what each message and response does. However, it would be beneficial to add more comments to the MsgInit, MsgIncreaseCounter, and QueryCounterRequest messages to explain what they do and how they are used. This will improve the maintainability of the code by making it easier for other developers to understand the purpose of these messages.

For example, you could add comments like these:

// MsgInit is used to initialize the counter with a specific value.
message MsgInit {
  // initial_value is the initial amount to set the counter to.
  uint64 initial_value = 1;
}

// MsgIncreaseCounter is used to increase the counter by a specific amount.
message MsgIncreaseCounter {
  // amount is the amount to increase the counter by.
  uint64 amount = 1;
}

// QueryCounterRequest is used to request the current value of the counter.
message QueryCounterRequest {}
x/accounts/internal/implementation/api_builder.go (3)
  • 31-32: The decodeRequest and encodeResponse functions have been removed and replaced with a schema field of type HandlerSchema. This change simplifies the code by removing the need to manually encode and decode requests and responses. However, it's important to ensure that the HandlerSchema type and its methods are correctly implemented to handle the encoding and decoding of requests and responses. Also, verify that all places where InitBuilder is used have been updated to reflect this change.

  • 47-48: The ExecuteBuilder struct now includes a HandlerSchema field. This is a map that associates message types with their corresponding schemas. This change allows for more flexible handling of different message types, as each type can have its own schema. However, ensure that the schemas are correctly defined and associated with their corresponding message types.

  • 57-59: The ExecuteBuilder struct now includes a HandlerSchema field. This is a map that associates message types with their corresponding schemas. This change allows for more flexible handling of different message types, as each type can have its own schema. However, ensure that the schemas are correctly defined and associated with their corresponding message types.

proto/cosmos/accounts/v1/tx.proto (2)
  • 7-12: The import statement for "cosmos/msg/v1/msg.proto" and the service option (cosmos.msg.v1.service) = true; have been added. This indicates that the service is now using the Cosmos SDK's service module, which provides a more streamlined way to define gRPC services and handlers. Ensure that the service handlers are properly implemented in the corresponding Go code.

  • 22-23: The option (cosmos.msg.v1.signer) = "sender"; has been added to the MsgInit message. This indicates that the sender field is the signer of the message. This is a part of the Cosmos SDK's service module and is used for authentication. Ensure that the sender field is properly used in the corresponding Go code.

44:
The option (cosmos.msg.v1.signer) = "sender"; has been added to the MsgExecute message. This indicates that the sender field is the signer of the message. This is a part of the Cosmos SDK's service module and is used for authentication. Ensure that the sender field is properly used in the corresponding Go code.

proto/cosmos/accounts/v1/query.proto (5)
  • 11-14: The new RPC methods Schema and AccountType have been added to the Query service. Ensure that these methods are implemented in the server and that they handle errors correctly. Also, verify that the client-side code has been updated to call these new methods as needed.

  • 32-35: The SchemaRequest message has been added. It contains a single field account_type which is used to specify the account type for which the schema is being requested. Ensure that the account type is validated in the server-side implementation of the Schema RPC method.

  • 37-54: The SchemaResponse message has been added. It contains fields for the init schema, execute handlers, and query handlers. Each handler is represented by a Handler message which contains the request and response names. Ensure that these fields are populated correctly in the server-side implementation of the Schema RPC method.

  • 57-60: The AccountTypeRequest message has been added. It contains a single field address which is used to specify the address for which the account type is being requested. Ensure that the address is validated in the server-side implementation of the AccountType RPC method.

  • 63-66: The AccountTypeResponse message has been added. It contains a single field account_type which is used to specify the account type for the requested address. Ensure that this field is populated correctly in the server-side implementation of the AccountType RPC method.

x/accounts/cli/cli.go (3)
  • 151-162: The getSchemaForAccount function is clear and concise. Good job!

  • 204-216: The encodeJSONToProto function is clear and concise. Good job!

  • 218-235: The decodeProtoToJSON function is clear and concise. Good job!

x/accounts/keeper_test.go (7)
  • 7-10: The import "cosmossdk.io/x/accounts/accountstd" has been added. Ensure that this package is being used in the code and that it is necessary for the functionality of the tests.

  • 29-35: The function signature for newKeeper has been changed. It now accepts a variadic parameter of type implementation.AccountCreatorFunc instead of a map of implementation.Account. Ensure that all calls to newKeeper have been updated to match the new function signature.

  • 38-44: The queryModuleFunc now requires two parameters: req and resp. Ensure that this change is reflected in all places where queryModuleFunc is used.

  • 73-74: The queryModuleFunc now requires two parameters: req and resp. Ensure that this change is reflected in all places where queryModuleFunc is used.

  • 93-99: The execModuleFunc now requires two parameters: msg and msgResp. Ensure that this change is reflected in all places where execModuleFunc is used.

  • 114-116: The queryModuleFunc now requires two parameters: req and resp. Ensure that this change is reflected in all places where queryModuleFunc is used.

  • 138-148: The queryModuleFunc now requires two parameters: req and resp. Ensure that this change is reflected in all places where queryModuleFunc is used.

x/accounts/internal/implementation/context_test.go (3)
  • 9-9: The import "google.golang.org/protobuf/runtime/protoiface" is new. Ensure that it is used in the code and is not an unused import.

  • 58-62: The function signature for the module call has been changed. The return type of the function has been changed from (proto.Message, error) to error. The function now modifies the msgResp argument in-place instead of returning a new proto.Message. This change could potentially improve performance by avoiding unnecessary memory allocations, but it also introduces the risk of side effects if msgResp is used elsewhere after this function call. Ensure that this change does not introduce any unintended side effects.

- func(ctx context.Context, msg proto.Message) (proto.Message, error) {
+ func(ctx context.Context, msg, msgResp protoiface.MessageV1) error {
  • 71-74: Similar to the previous comment, the function signature for the query call has been changed. The return type of the function has been changed from (proto.Message, error) to error. The function now modifies the resp argument in-place instead of returning a new proto.Message. This change could potentially improve performance by avoiding unnecessary memory allocations, but it also introduces the risk of side effects if resp is used elsewhere after this function call. Ensure that this change does not introduce any unintended side effects.
- func(ctx context.Context, msg proto.Message) (proto.Message, error) {
+ func(ctx context.Context, req, resp protoiface.MessageV1) error {
simapp/app_test.go (1)
  • 61-61: The AccountKeeper has been replaced with AuthKeeper for getting the module address. Ensure that the AuthKeeper is properly initialized and has the same functionality as the AccountKeeper for getting the module address.
- addr = app.AccountKeeper.GetModuleAddress(acc)
+ addr = app.AuthKeeper.GetModuleAddress(acc)
Committable suggestion (Beta)
		if modAddr, err := sdk.AccAddressFromBech32(acc); err == nil {
			addr = modAddr
		} else {
			addr = app.AuthKeeper.GetModuleAddress(acc)
		}
x/accounts/internal/implementation/implementation.go (6)
  • 11-15: The Dependencies struct is introduced to encapsulate dependencies that are passed to the constructor of a smart account. This is a good practice as it improves code readability and maintainability.

  • 17-33: The AddAccount function is introduced as a helper function to add a smart account to the list of smart accounts. It takes a name and a constructor function as arguments and returns a function that creates an account and its implementation. This is a good use of higher-order functions and improves code modularity.

  • 35-61: The MakeAccountsMap function is introduced to create a map of account names to their implementations. It takes an address codec and a slice of account creator functions as arguments. The function iterates over the account creator functions, creates an account and its implementation for each one, builds the state schema, and adds the account to the map. This function improves code modularity and readability.

  • 92-95: The Implementation struct is updated to include schemas for collections, init handlers, query handlers, and execute handlers. This is a good practice as it improves code readability and maintainability.

  • 112-119: The Implementation struct is updated to include schemas for collections, init handlers, query handlers, and execute handlers. This is a good practice as it improves code readability and maintainability.

  • 134-159: The MessageSchema and HandlerSchema structs are introduced to define the schemas of a message and a handler respectively. This is a good practice as it improves code readability and maintainability.

x/accounts/internal/implementation/implementation_test.go (3)
  • 73-79: The test case "decode init request - ok" has been modified to use the InitHandlerSchema.ResponseSchema.TxEncode and InitHandlerSchema.RequestSchema.TxDecode methods instead of proto.Marshal and impl.DecodeInitRequest. Ensure that these changes are intentional and that the new methods provide the same functionality as the old ones. Also, verify that the InitHandlerSchema and its ResponseSchema and RequestSchema are properly initialized before this test is run.

  • 70-87: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [81-90]

The test case "encode init response - ok" has been modified to use the InitHandlerSchema.ResponseSchema.TxEncode method instead of impl.EncodeInitResponse. Ensure that this change is intentional and that the new method provides the same functionality as the old one. Also, verify that the InitHandlerSchema and its ResponseSchema are properly initialized before this test is run.

  • 93-95: The test case "decode execute request - ok" remains unchanged. However, ensure that the anypb.New function is still appropriate for creating a new anypb.Any message from wantReq, and that wantReq is correctly initialized.
x/accounts/keeper.go (6)
  • 10-13: The new imports cosmossdk.io/x/accounts/accountstd, github.com/cosmos/cosmos-sdk/codec/types, and google.golang.org/protobuf/runtime/protoiface have been added. Ensure that these packages are used in the code and are necessary for the new changes.

  • 30-46: New interfaces QueryRouter, MsgRouter, and SignerProvider have been introduced. These interfaces seem to provide a more modular approach to routing queries and messages, and getting signers from a message. This is a good practice as it allows for better separation of concerns and easier testing.

  • 48-102: The NewKeeper function has been modified to take the new interfaces as parameters and use them in the Keeper struct. This is a significant change and it's important to ensure that all calls to NewKeeper throughout the codebase have been updated to match the new signature. Also, the error handling in this function seems to be appropriate, as it returns errors when they occur and doesn't suppress them.

  • 111-112: The types of execModuleFunc and queryModuleFunc have been changed to implementation.ModuleExecFunc and implementation.ModuleQueryFunc respectively. Ensure that these new types are compatible with the rest of the codebase and that they provide the necessary functionality.

  • 259-264: The queryModuleFunc is now being used in the NewQueryServer function. This seems to be a good change as it allows for more flexibility in handling queries. However, ensure that the queryModuleFunc is properly initialized before it's used in this function.

  • 266-268: The new function getMessageName has been added. This function seems to be used to get the name of a message from its type URL. This could be a useful utility function, but ensure that it's used correctly throughout the codebase.

x/accounts/internal/implementation/context.go (5)
  • 8-9: The import "google.golang.org/protobuf/runtime/protoiface" is new. Ensure that this import is used in the code and is necessary. If it's not used, it should be removed to keep the code clean.

  • 21-33: The function signatures for ModuleExecFunc and ModuleQueryFunc have been changed. The return type of these functions has been changed from (proto.Message, error) to error. This change simplifies the function signatures and makes them easier to use, but it also means that the functions no longer return a proto.Message. Ensure that this change does not break any existing code that relies on the returned proto.Message.

  • 49-50: The function signatures for moduleExec and moduleQuery in MakeAccountContext have been updated to match the new ModuleExecFunc and ModuleQueryFunc types. This is consistent with the changes made to the contextValue struct.

  • 77-84: The ExecModule function has been updated to match the new ModuleExecFunc type. The function now uses the resp variable to store the response from v.moduleExec, and it no longer checks whether resp is of type RespProto. This simplifies the function and makes it easier to use, but it also means that the function no longer checks the type of the response. Ensure that this change does not introduce any type-related errors.

  • 87-96: The QueryModule function has been updated to match the new ModuleQueryFunc type. The function now uses the resp variable to store the response from v.moduleQuery, and it no longer checks whether resp is of type RespProto. This simplifies the function and makes it easier to use, but it also means that the function no longer checks the type of the response. Ensure that this change does not introduce any type-related errors.

x/accounts/msg_server_test.go (2)
  • 20-20: The newKeeper function now takes an accountstd.AddAccount function as an argument instead of a map. This change simplifies the process of adding accounts for testing. However, ensure that the AddAccount function is correctly implemented and that it properly adds the account to the keeper.

  • 21-25: The queryModuleFunc has been modified to use the protoiface.MessageV1 interface for the request and response parameters instead of proto.Message. This change provides more flexibility as protoiface.MessageV1 includes methods for working with protocol buffer messages. However, ensure that the proto.Merge function is used correctly to merge the response message with an instance of bankv1beta1.QueryBalanceResponse. The function should not return any errors if the merge is successful.

x/accounts/msg_server.go (4)
  • 7-7: The line var _ v1.MsgServer = msgServer{} is a compile-time check to ensure that msgServer implements the v1.MsgServer interface. If msgServer does not implement the interface, the code will not compile. This is a good practice to ensure that the necessary methods are implemented.

  • 32-35: The method InitHandlerSchema.RequestSchema.TxDecode(request.Message) is used to decode the request message. This is a change from the previous method impl.DecodeInitRequest(request.Message). Ensure that the new method correctly decodes the request message and that the decoded message is used correctly in the subsequent code.

  • 44-47: The method InitHandlerSchema.ResponseSchema.TxEncode(resp) is used to encode the response. This is a change from the previous method impl.EncodeInitResponse(resp). Ensure that the new method correctly encodes the response and that the encoded response is used correctly in the subsequent code.

  • 55-59: The event account_creation is emitted with the attribute address set to accAddrString. This is a new addition and it's a good practice to emit events for significant actions in the code. However, ensure that the event is handled correctly in the rest of the codebase.

x/accounts/query_server_test.go (2)
  • 19-20: The newKeeper function now takes an accountstd.AddAccount function as an argument instead of a map. This change seems to be in line with the new x/accounts module's design. However, ensure that the AddAccount function is correctly implemented and that it properly initializes the Keeper struct.

  • 20-21: The queryModuleFunc now returns nil instead of a QueryBalanceResponse message. This change might be due to the new design of the x/accounts module. However, ensure that this change does not affect the functionality of the queryModuleFunc and that it still correctly handles queries.

x/accounts/query_server.go (1)
  • 72-84: The AccountType method retrieves the account type for a given address. It converts the address from a string to bytes, retrieves the account type from the AccountsByType storage, and returns it. If any of these operations fail, it returns an error. This method seems to be implemented correctly.
x/accounts/internal/implementation/protoaccount.go (5)
  • 7-11: The import "google.golang.org/protobuf/encoding/protojson" has been added. This package provides functionality for marshalling and unmarshalling protobuf messages to and from JSON. This is likely used for the new NewProtoMessageSchema function which includes JSON encoding and decoding.

  • 23-28: The respName variable has been removed from the RegisterInitHandler function. This variable was previously used to get the full name of the response protobuf message. It seems like the response name is no longer needed in this context.

  • 35-37: The router.decodeRequest and router.encodeResponse functions have been removed and replaced with a router.schema assignment. The router.schema is assigned a HandlerSchema struct which includes a RequestSchema and ResponseSchema. These schemas are created using the new NewProtoMessageSchema function. This change seems to be a part of a larger refactoring to use schemas instead of separate decode and encode functions.

  • 61-64: The router.HandlerSchema map is being updated with a new HandlerSchema for the request name. This is similar to the change in the RegisterInitHandler function where a HandlerSchema is assigned to router.schema. It seems like the HandlerSchema is being used to store the request and response schemas for different types of requests.

  • 75-115: The NewProtoMessageSchema function has been added. This function creates a new MessageSchema for a given protobuf message type. The MessageSchema includes the name of the message and functions for encoding and decoding the message to and from bytes and JSON. The function uses the proto.MarshalOptions and proto.UnmarshalOptions structs from the google.golang.org/protobuf/proto package for byte encoding and decoding, and the protojson.MarshalOptions and protojson.UnmarshalOptions structs from the google.golang.org/protobuf/encoding/protojson package for JSON encoding and decoding. The DiscardUnknown option is set to true for both byte and JSON unmarshalling, which means that unknown fields in the input will be ignored. This might be a potential issue if the input is expected to strictly adhere to the message schema.

78:
The DiscardUnknown option is set to true for byte unmarshalling. This means that unknown fields in the input will be ignored. If the input is expected to strictly adhere to the message schema, this might be a potential issue. The comment on this line suggests that this is a point of uncertainty. It would be good to clarify this point and make a decision based on the requirements of the application.

85:
The DiscardUnknown option is set to true for JSON unmarshalling. This means that unknown fields in the input will be ignored. If the input is expected to strictly adhere to the message schema, this might be a potential issue. It would be good to clarify this point and make a decision based on the requirements of the application.

simapp/app.go (11)
  • 18-20: The new imports cosmossdk.io/x/accounts, cosmossdk.io/x/accounts/accountstd, and cosmossdk.io/x/accounts/testing/counter are added. Ensure that these packages are used in the code and are necessary for the new functionality.

  • 151-152: The AccountKeeper is replaced with AccountsKeeper and AuthKeeper. Make sure that all references to AccountKeeper in the code are updated to use AccountsKeeper or AuthKeeper as appropriate.

  • 262-262: The accounts.StoreKey is added to the list of store keys. Ensure that this key is used in the code and is necessary for the new functionality.

  • 285-299: The AuthKeeper and AccountsKeeper are initialized. The AuthKeeper is initialized with the same parameters as the old AccountKeeper. The AccountsKeeper is initialized with a new accountstd.AddAccount function. Ensure that this function is defined and works as expected.

  • 366-368: The AuthKeeper is used instead of the AccountKeeper to initialize the govKeeper. Ensure that the AuthKeeper provides the same functionality as the AccountKeeper in this context.

  • 379-383: The AuthKeeper is used instead of the AccountKeeper to initialize the evidenceKeeper. Ensure that the AuthKeeper provides the same functionality as the AccountKeeper in this context.

  • 398-419: The accounts.NewAppModule(app.AccountsKeeper) and auth.NewAppModule(appCodec, app.AuthKeeper, authsims.RandomGenesisAccounts) are added to the ModuleManager. Ensure that these modules are necessary and work as expected.

  • 467-468: The accounts.ModuleName and authtypes.ModuleName are added to the genesisModuleOrder. Ensure that these modules are necessary and work as expected.

  • 481-483: The error handling for app.ModuleManager.RegisterServices(app.configurator) is changed. The error is now handled immediately instead of being returned by the function. This change is acceptable if the function does not need to return an error.

  • 506-508: The auth.NewAppModule(app.appCodec, app.AuthKeeper, authsims.RandomGenesisAccounts) is used instead of auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts) to initialize the overrideModules. Ensure that the AuthKeeper provides the same functionality as the AccountKeeper in this context.

  • 563-566: The AuthKeeper is used instead of the AccountKeeper to initialize the anteHandler. Ensure that the AuthKeeper provides the same functionality as the AccountKeeper in this context.

x/accounts/testing/counter/counter.go (3)
  • 37-47: func (a Account) Init(ctx context.Context, msg *counterv1.MsgInit) (*counterv1.MsgInitResponse, error) {
    err := a.Owner.Set(ctx, accountstd.Sender(ctx))
    if err != nil {
  •   return nil, err
    
  •   return nil, fmt.Errorf("failed to set owner: %w", err)
    
    }
    err = a.Counter.Set(ctx, msg.InitialValue)
    if err != nil {
  •   return nil, err
    
  •   return nil, fmt.Errorf("failed to set counter: %w", err)
    
    }
    return &counterv1.MsgInitResponse{}, nil
    }
  • 49-70: func (a Account) IncreaseCounter(ctx context.Context, msg *counterv1.MsgIncreaseCounter) (*counterv1.MsgIncreaseCounterResponse, error) {
    sender := accountstd.Sender(ctx)
    owner, err := a.Owner.Get(ctx)
    if err != nil {
    return nil, err
    }
    if !bytes.Equal(sender, owner) {
    return nil, fmt.Errorf("sender is not the owner of the account")
    }
    counter, err := a.Counter.Get(ctx)
    if err != nil {
    return nil, err
    }
    counter = counter + msg.Amount
    err = a.Counter.Set(ctx, counter)
    if err != nil {
    return nil, fmt.Errorf("failed to increase counter: %w", err)
    }
    return &counterv1.MsgIncreaseCounterResponse{
    NewAmount: counter,
    }, nil
    }

  • 31-35: type Account struct {
    // Owner is the address of the account owner.

  • Owner collections.Item[[]byte]
  • Owners collections.Item[[]byte]
    // Counter is the counter value.
  • Counter collections.Item[uint64]
  • Counters collections.Item[uint64]
    }

<!-- suggestion_start -->
<details>
<summary>Committable suggestion (Beta)</summary>

```suggestion
package counter

import (
	"bytes"
	"context"
	"fmt"

	counterv1 "cosmossdk.io/api/cosmos/accounts/testing/counter/v1"
	"cosmossdk.io/collections"
	"cosmossdk.io/x/accounts/accountstd"
)

var (
	OwnerPrefix   = collections.NewPrefix(0)
	CounterPrefix = collections.NewPrefix(1)
)

var _ accountstd.Interface = (*Account)(nil)

// NewAccount creates a new account.
func NewAccount(d accountstd.Dependencies) (Account, error) {
	return Account{
		Owners:   collections.NewItem(d.SchemaBuilder, OwnerPrefix, "owner", collections.BytesValue),
		Counters: collections.NewItem(d.SchemaBuilder, CounterPrefix, "counter", collections.Uint64Value),
	}, nil
}

// Account implements the Account interface. It is an account
// who can be used to increase a counter.
type Account struct {
	// Owners is the address of the account owner.
	Owners collections.Item[[]byte]
	// Counters is the counter value.
	Counters collections.Item[uint64]
}

func (a Account) Init(ctx context.Context, msg *counterv1.MsgInit) (*counterv1.MsgInitResponse, error) {
	err := a.Owners.Set(ctx, accountstd.Sender(ctx))
	if err != nil {
		return nil, fmt.Errorf("failed to set owner: %w", err)
	}
	err = a.Counters.Set(ctx, msg.InitialValue)
	if err != nil {
		return nil, fmt.Errorf("failed to set counter: %w", err)
	}
	return &counterv1.MsgInitResponse{}, nil
}

func (a Account) IncreaseCounter(ctx context.Context, msg *counterv1.MsgIncreaseCounter) (*counterv1.MsgIncreaseCounterResponse, error) {
	sender := accountstd


</blockquote></details></blockquote></details>



</details>

x/accounts/cli/cli.go Show resolved Hide resolved
x/accounts/cli/cli.go Outdated Show resolved Hide resolved
x/accounts/cli/cli.go Show resolved Hide resolved
x/accounts/cli/cli.go Show resolved Hide resolved
x/accounts/cli/cli.go Outdated Show resolved Hide resolved
x/accounts/cli/cli.go Show resolved Hide resolved
x/accounts/module.go Outdated Show resolved Hide resolved
x/accounts/query_server.go Show resolved Hide resolved
x/accounts/v1/schema.go Outdated Show resolved Hide resolved
x/accounts/testing/counter/counter.go Outdated Show resolved Hide resolved
unknown unknown added 2 commits October 25, 2023 14:34
# Conflicts:
#	simapp/app.go
#	simapp/go.sum
#	x/accounts/go.mod
#	x/accounts/go.sum
simapp/app.go Outdated 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d977173 and 72886e8.
Files ignored due to filter (5)
  • simapp/go.mod
  • tests/go.mod
  • tests/starship/tests/go.mod
  • x/accounts/go.mod
  • x/accounts/go.sum
Files selected for processing (3)
  • x/accounts/keeper.go (3 hunks)
  • x/accounts/keeper_test.go (7 hunks)
  • x/accounts/testing/counter/counter.go (1 hunks)
Additional comments: 25
x/accounts/keeper.go (5)
  • 8-21: The new imports seem to be used correctly in the code. Ensure that the versions of these packages are compatible with the rest of the project.

  • 32-48: The new interfaces QueryRouter, MsgRouter, and SignerProvider are well defined. Make sure that these interfaces are implemented wherever necessary.

  • 50-108: The NewKeeper function has been significantly modified. The new parameters es, signerProvider, execRouter, and queryRouter are used correctly. The accounts parameter has been removed, ensure that this does not break any existing functionality. The Keeper struct has been updated to include the new eventService field and the function signatures of getSenderFunc, execModuleFunc, and queryModuleFunc have been updated to use protoiface.MessageV1 instead of proto.Message. The new function getMessageName is used correctly.

  • 110-120: The Keeper struct has been updated to include the new eventService field and the function signatures of getSenderFunc, execModuleFunc, and queryModuleFunc have been updated to use protoiface.MessageV1 instead of proto.Message.

  • 271-273: The new function getMessageName is used correctly.

x/accounts/testing/counter/counter.go (11)
  • 1-11: The import statements look good and are well organized.

  • 14-16: The global variables OwnerPrefix and CounterPrefix are defined correctly.

  • 18-18: The assertion that Account implements the accountstd.Interface is correct.

  • 20-26: The NewAccount function is well implemented. It creates a new Account struct with Owner and Counter fields.

  • 28-35: The Account struct is well defined with Owner and Counter fields.

  • 37-47: The Init method is correctly implemented. It sets the Owner and Counter fields of the Account struct.

  • 49-70: The IncreaseCounter method is correctly implemented. It increases the Counter field of the Account struct if the sender is the owner of the account.

  • 72-80: The QueryCounter method is correctly implemented. It returns the Counter field of the Account struct.

  • 82-84: The RegisterInitHandler method is correctly implemented. It registers the Init method as the init handler.

  • 86-88: The RegisterExecuteHandlers method is correctly implemented. It registers the IncreaseCounter method as the execute handler.

  • 90-92: The RegisterQueryHandlers method is correctly implemented. It registers the QueryCounter method as the query handler.

x/accounts/keeper_test.go (9)
  • 6-12: The import of google.golang.org/protobuf/runtime/protoiface is new. Ensure that it is used in the code and is necessary.

  • 30-43: The eventService struct and its methods are new. Ensure that they are used correctly and that the methods are implemented according to the event.Service interface.

  • 44-50: The newKeeper function now accepts a variadic parameter of AccountCreatorFunc. Ensure that this change is reflected in all calls to newKeeper.

  • 52-62: The TestKeeper_Init function has been updated to use the accountstd.AddAccount function to add an account. Ensure that this change is reflected in all calls to TestKeeper_Init.

  • 53-60: The m.queryModuleFunc function signature has been updated to accept a response message as a parameter and return an error. Ensure that this change is reflected in all calls to m.queryModuleFunc.

  • 87-92: The TestKeeper_Execute function has been updated to use the accountstd.AddAccount function to add an account. Ensure that this change is reflected in all calls to TestKeeper_Execute.

  • 108-115: The m.execModuleFunc function signature has been updated to accept a response message as a parameter and return an error. Ensure that this change is reflected in all calls to m.execModuleFunc.

  • 128-133: The TestKeeper_Query function has been updated to use the accountstd.AddAccount function to add an account. Ensure that this change is reflected in all calls to TestKeeper_Query.

  • 150-164: The m.queryModuleFunc function signature has been updated to accept a response message as a parameter and return an error. Also, the function now merges the response message with the copied response. Ensure that this change is reflected in all calls to m.queryModuleFunc.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 72886e8 and e2c0ebf.
Files selected for processing (3)
  • simapp/app_test.go (3 hunks)
  • x/accounts/internal/implementation/implementation.go (4 hunks)
  • x/accounts/module.go (1 hunks)
Additional comments: 11
simapp/app_test.go (3)
  • 8-11: The new import "cosmossdk.io/x/accounts" has been added. Ensure that the package exists and is accessible.

  • 59-63: The AccountKeeper has been replaced with AuthKeeper. Ensure that all instances of AccountKeeper have been replaced with AuthKeeper throughout the codebase.

  • 197-203: The accounts module has been added to the module.VersionMap in the TestRunMigrations function. Ensure that the accounts module has a ConsensusVersion method and that it returns the correct version.

x/accounts/module.go (1)
  • 1-100: The AppModule struct and its methods are well defined and follow the Cosmos SDK's module structure. The methods are implemented according to the interfaces they are supposed to satisfy. The NewAppModule function correctly initializes an AppModule instance with a Keeper. The RegisterInterfaces, RegisterServices, DefaultGenesis, InitGenesis, ExportGenesis, Name, GetTxCmd, GetQueryCmd, and ConsensusVersion methods are all correctly implemented. The StoreKey is correctly prefixed to avoid collision with the auth store key. The ConsensusVersion is set to 1, which is the default value for a new module.
x/accounts/internal/implementation/implementation.go (7)
  • 1-9: The new import statements are correctly placed and formatted.

  • 11-15: The Dependencies struct is a good way to encapsulate dependencies for creating a smart account. It includes a SchemaBuilder and AddressCodec.

  • 17-18: The AccountCreatorFunc type is a function type that creates an account. This is a good way to encapsulate the logic for creating an account.

  • 20-35: The AddAccount function is a helper function to add a smart account to the list of smart accounts. It returns a function that given an Account implementer, returns the name of the account and the Implementation instance. This is a good way to encapsulate the logic for adding an account.

  • 93-102: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [67-102]

The NewImplementation function creates a new Implementation instance given an Account implementer. This is a good way to encapsulate the logic for creating an Implementation instance.

  • 113-128: The Implementation struct is updated to include new fields for schema and handler schemas. This is a good way to encapsulate the schema and handler schemas for an Implementation.

  • 157-163: The HandlerSchema struct is a good way to encapsulate the schema of a handler. It includes fields for the request schema and the response schema.

x/accounts/module.go Outdated Show resolved Hide resolved
x/accounts/module.go Show resolved Hide resolved
x/accounts/internal/implementation/implementation.go Outdated Show resolved Hide resolved
x/accounts/internal/implementation/implementation.go Outdated Show resolved Hide resolved
testinginprod and others added 4 commits November 2, 2023 13:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 UI

Commits Files that changed from the base of the PR and between e2c0ebf and 30cf96b.
Files ignored due to filter (7)
  • simapp/go.mod
  • tests/go.mod
  • tests/go.sum
  • tests/starship/tests/go.mod
  • tests/starship/tests/go.sum
  • x/accounts/go.mod
  • x/accounts/go.sum
Files selected for processing (1)
  • simapp/app_test.go (3 hunks)
Additional comments: 3
simapp/app_test.go (3)
  • 16-22: The new import for the "accounts" module is correctly added.

  • 59-65: The change from app.AccountKeeper.GetModuleAddress(acc) to app.AuthKeeper.GetModuleAddress(acc) is correctly implemented. Ensure that the AuthKeeper has the GetModuleAddress method and it behaves as expected.

  • 197-203: The addition of the "accounts" module to the module.VersionMap in the RunMigrations function is correctly implemented. Ensure that the accounts.AppModule{}.ConsensusVersion() returns the correct version number.

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 UI

Commits Files that changed from the base of the PR and between 30cf96b and fc7ecdc.
Files selected for processing (1)
  • x/accounts/internal/implementation/implementation.go (4 hunks)
Additional comments: 6
x/accounts/internal/implementation/implementation.go (6)
  • 1-67: The Dependencies struct, AccountCreatorFunc type, and AddAccount function are well-defined and follow good practices. The AddAccount function is particularly interesting as it uses a type parameter A which is constrained to the Account interface. This is a good use of Go's type parameters feature introduced in Go 1.18.

  • 20-35: The AddAccount function is a higher-order function that returns a function. This is a good use of functional programming principles in Go. However, it's important to note that this could potentially increase the complexity of the code and make it harder to understand for developers who are not familiar with functional programming.

  • 37-64: The MakeAccountsMap function is well-defined and follows good practices. It creates a map of account names to account implementations from a list of account creator functions. This is a good use of Go's map data structure and functional programming principles.

  • 92-101: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [66-101]

The NewImplementation function is well-defined and follows good practices. It creates a new Implementation instance given an Account implementer. However, it's important to note that this function has a high cyclomatic complexity due to the multiple error checks. Consider refactoring this function to reduce its complexity.

  • 112-127: The Implementation struct is well-defined and follows good practices. It wraps an Account implementer in order to provide a concrete and non-generic implementation usable by the x/accounts module. However, the TODO comment on line 124 suggests that the DecodeExecuteRequest and EncodeExecuteResponse fields should be removed and replaced with the schemas. This should be addressed in a future commit.

  • 137-154: The MessageSchema and HandlerSchema structs are well-defined and follow good practices. They define the schema of a message and a handler, respectively. However, the comments "CONSENSUS SAFE" and "CONSENSUS UNSAFE" are not clear. Consider adding more explanation about what these comments mean.

unknown unknown and others added 3 commits November 2, 2023 15:16
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
# Conflicts:
#	tests/starship/tests/go.mod
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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fc7ecdc and 2348ca7.
Files ignored due to filter (6)
  • simapp/go.mod
  • tests/go.mod
  • tests/go.sum
  • tests/starship/tests/go.mod
  • tests/starship/tests/go.sum
  • x/accounts/go.mod
Files selected for processing (2)
  • x/accounts/internal/implementation/implementation.go (4 hunks)
  • x/accounts/module.go (1 hunks)
Additional comments: 15
x/accounts/module.go (11)
  • 1-19: The import section looks clean and organized. All the necessary packages are imported for the module.

  • 21-24: The constants are well defined and follow the naming conventions. The comment on line 23 provides a good explanation for the choice of the StoreKey value.

  • 30-36: The AppModule struct is correctly implementing the required interfaces. This is a good practice to ensure that the struct meets the necessary contract.

  • 38-40: The NewAppModule function is correctly implemented and returns an instance of AppModule.

  • 52-54: The RegisterInterfaces function correctly registers the message service descriptor.

  • 60-63: The RegisterServices function correctly registers the query and message servers.

  • 67-69: The DefaultGenesis function correctly returns the default genesis state.

  • 71-78: The ValidateGenesis function correctly unmarshals the genesis state and validates it. However, the comment on line 76 indicates that additional validation logic should be added. Ensure that this is implemented as necessary.

  • 80-87: The InitGenesis function correctly imports the genesis state. However, it uses panic to handle errors. As discussed in the previous comments, this is acceptable due to the constraints of the genesis API.

  • 89-95: The ExportGenesis function correctly exports the genesis state. It also uses panic to handle errors, which is acceptable in this context.

  • 97-107: The Name, GetTxCmd, GetQueryCmd, and ConsensusVersion functions are correctly implemented.

x/accounts/internal/implementation/implementation.go (4)
  • 1-9: The new import statements are appropriate for the added functionality.

  • 11-15: The Dependencies struct is a good way to encapsulate dependencies for creating an account.

  • 17-19: The AccountCreatorFunc type is a clear way to define a function that creates an account.

  • 112-127: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [112-134]

The Implementation struct is a good way to wrap an Account implementer in order to provide a concrete and non-generic implementation usable by the x/accounts module. However, the TODO comment on line 124 suggests that the DecodeExecuteRequest, EncodeExecuteResponse, DecodeQueryRequest, and EncodeQueryResponse fields may be removed in the future. This could potentially break any code that relies on these fields.

DecodeInitRequest func([]byte) (any, error)
// EncodeInitResponse encodes an init response to be sent back from the message server.
EncodeInitResponse func(any) ([]byte, error)
// TODO: remove these fields and use the schemas instead
Copy link
Member

Choose a reason for hiding this comment

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

should this be addressed?

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.

utACK, i see some left over todos, we should solve or open issues for them

simapp/app.go Outdated Show resolved Hide resolved
simapp/go.mod Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

+1

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 UI

Commits Files that changed from the base of the PR and between 2348ca7 and ac8a779.
Files ignored due to filter (2)
  • x/accounts/go.mod
  • x/accounts/go.sum
Files selected for processing (1)
  • simapp/app.go (14 hunks)
Additional comments: 7
simapp/app.go (7)
  • 20-28: The import statements for the accounts package and its related modules are correct.

  • 149-156: The addition of the AccountsKeeper field and renaming of the AccountKeeper field to AuthKeeper are correct. Ensure that all references to these fields throughout the codebase have been updated accordingly.

  • 260-263: The addition of the accounts.StoreKey to the list of store keys is correct.

  • 286-301: The initialization of the AccountsKeeper with a new instance of accounts.Keeper is done correctly. However, the error handling could be improved. Instead of panicking, consider returning the error to the caller for better error propagation and handling. This was previously discussed and it was decided to keep the panic as the function signature does not allow returning errors.

  • 413-438: The addition of the accounts.NewAppModule to the list of app modules is correct. Ensure that all necessary dependencies for the accounts module are correctly initialized before this point.

  • 521-527: The addition of the accounts.ModuleName to the genesisModuleOrder is correct. Ensure that the order of modules in this list is correct as it can affect the initialization of the application.

  • 578-584: The replacement of app.AccountKeeper with app.AuthKeeper in the NewAnteHandler function call is correct. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

@testinginprod testinginprod added this pull request to the merge queue Nov 3, 2023
Merged via the queue into main with commit f3c55dc Nov 3, 2023
60 of 61 checks passed
@testinginprod testinginprod deleted the tip/accounts/module branch November 3, 2023 16:38
@testinginprod testinginprod mentioned this pull request Dec 19, 2023
44 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants