-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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): add event emission to accounts module #19636
Conversation
WalkthroughThe changes revolve around the introduction of Changes
Assessment against linked issues
The code changes directly address the primary objective outlined in the linked issue by introducing event emission capabilities in the accounts module, as evidenced by the addition of event handling and emission functionalities in 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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
@tac0turtle your pull request is missing a changelog! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Files selected for processing (13)
- x/accounts/account_test.go (6 hunks)
- x/accounts/accountstd/exports.go (2 hunks)
- x/accounts/defaults/base/account.go (4 hunks)
- x/accounts/internal/implementation/account_test.go (2 hunks)
- x/accounts/internal/implementation/api_builder.go (7 hunks)
- x/accounts/internal/implementation/api_builder_test.go (2 hunks)
- x/accounts/internal/implementation/context_test.go (2 hunks)
- x/accounts/internal/implementation/implementation.go (2 hunks)
- x/accounts/internal/implementation/implementation_test.go (1 hunks)
- x/accounts/internal/implementation/protoaccount.go (4 hunks)
- x/accounts/keeper.go (3 hunks)
- x/accounts/testing/account_abstraction/minimal.go (2 hunks)
- x/accounts/testing/counter/counter.go (5 hunks)
Additional comments: 40
x/accounts/internal/implementation/api_builder_test.go (2)
- 14-18: The addition of
env appmodule.Environment
as a parameter inRegisterExecuteHandler
functions withinTestRouterDoubleRegistration
aligns with the new requirement for handlers to be aware of the environment context. This change is consistent and correctly implemented.- 36-39: In
TestEmptyQueryExecuteHandler
, the introduction ofenv appmodule.Environment
as a parameter for theqh
andeh
functions is correctly implemented, ensuring that the environment context is passed to query and execute handlers. This is a necessary adjustment to accommodate the new event emission functionality.x/accounts/internal/implementation/account_test.go (3)
- 29-29: Adding
appmodule.Environment
as a parameter inRegisterInitHandler
is correctly implemented, ensuring that initialization handlers can access environmental context. This is crucial for the new event emission functionality.- 35-44: The modifications in
RegisterExecuteHandlers
to includeappmodule.Environment
in the function signatures are correctly implemented. This ensures that execute handlers have access to the environment, which is essential for the intended functionality.- 50-53: The changes in
RegisterQueryHandlers
to includeappmodule.Environment
in the function signatures are correctly implemented. This adjustment allows query handlers to utilize environmental context, aligning with the new requirements.x/accounts/internal/implementation/implementation_test.go (1)
- 19-19: The creation of
env appmodule.Environment
and its inclusion in method calls withinTestImplementation
is correctly implemented. This ensures that the tests accurately reflect the new requirement for environment context inExecute
,Init
, andQuery
functions.x/accounts/internal/implementation/protoaccount.go (3)
- 14-23: The addition of
appmodule.Environment
to theRegisterInitHandler
function signature is correctly implemented. This change ensures that initialization handlers for smart accounts using protobuf can interact with the environment context.- 41-52: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [35-49]
The update to
RegisterExecuteHandler
to includeappmodule.Environment
in the function signature is correctly implemented. This adjustment allows execution handlers for smart accounts using protobuf to utilize environmental context, which is essential for the new functionality.
- 61-61: The inclusion of
appmodule.Environment
in theRegisterQueryHandler
function signature is correctly implemented. This ensures that query handlers for smart accounts using protobuf can access the environment, aligning with the new requirements.x/accounts/testing/account_abstraction/minimal.go (3)
- 39-39: The inclusion of
appmodule.Environment
in theInit
method signature forMinimalAbstractedAccount
is correctly implemented, ensuring that initialization can access environmental context.- 48-54: The update to the
Authenticate
method to includeappmodule.Environment
and to emit an event upon authentication is correctly implemented. This enhances the method's functionality by integrating event emission and ensuring error handling is in place.- 59-59: The addition of
appmodule.Environment
to theQueryAuthenticateMethods
method signature is correctly implemented, aligning with the new requirement for methods to access the environment context.x/accounts/internal/implementation/context_test.go (1)
- 35-36: The creation of
env appmodule.Environment
and its inclusion in theimpl.Execute
function call withinTestMakeAccountContext
is correctly implemented. This ensures that the test accurately reflects the new requirement for environment context in execution.x/accounts/account_test.go (3)
- 30-30: Adding
appmodule.Environment
as a parameter inRegisterInitHandler
is correctly implemented, ensuring that initialization handlers can access environmental context. This is crucial for the new event emission functionality.- 38-48: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [41-77]
The modifications in
RegisterExecuteHandlers
to includeappmodule.Environment
in the function signatures are correctly implemented. This ensures that execute handlers have access to the environment, which is essential for the intended functionality.
- 74-96: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [83-111]
The changes in
RegisterQueryHandlers
to includeappmodule.Environment
in the function signatures are correctly implemented. This adjustment allows query handlers to utilize environmental context, aligning with the new requirements.x/accounts/internal/implementation/api_builder.go (3)
- 27-27: The addition of
appmodule.Environment
to thehandler
function signature inInitBuilder
is correctly implemented. This change ensures that initialization handlers can interact with the environment context.- 54-54: Updating the
handlers
map inExecuteBuilder
to includeappmodule.Environment
in function signatures is correctly implemented. This allows execution handlers to utilize environmental context, which is essential for the new functionality.- 101-101: The use of
appmodule.Environment
in theQueryBuilder
through theExecuteBuilder
instance is a clever design choice, ensuring that query handlers also have access to the environment. This maintains consistency across the implementation.x/accounts/testing/counter/counter.go (5)
- 10-10: The addition of
"cosmossdk.io/core/appmodule"
import is necessary for utilizing theappmodule.Environment
parameter in function signatures. This change aligns with the PR's objective to integrate event emission functionality by leveraging the environment context.- 55-55: Adding the
env appmodule.Environment
parameter to theInit
function signature is a crucial change for incorporating the environment context into the account initialization process. This allows the function to interact with the broader application environment, which is essential for the new event emission feature. However, it's important to ensure that all calls to this function are updated to include the new parameter.- 68-68: The modification to include
env appmodule.Environment
in theIncreaseCounter
function signature is appropriate for the feature being implemented. It ensures that event emission can be contextually aware of the environment. Similar to theInit
function, verify that all invocations ofIncreaseCounter
have been updated accordingly.- 91-91: Incorporating the
env appmodule.Environment
parameter into theQueryCounter
function is consistent with the overall goal of enhancing the module's interactivity and monitoring capabilities. This change allows the function to leverage the application's environment for event emission or other environment-specific logic.- 101-101: The addition of
env appmodule.Environment
to theTestDependencies
function signature is a good practice for testing the module's interaction with the application environment. This ensures that the testing framework can simulate different environmental contexts, which is valuable for thorough testing of the event emission functionality.x/accounts/internal/implementation/implementation.go (4)
- 11-11: The addition of
"cosmossdk.io/core/appmodule"
import is necessary for utilizing theappmodule.Environment
parameter in function signatures within theImplementation
struct. This change is consistent with the PR's objective to enhance the module's capabilities by integrating the environment context.- 115-115: Adding the
env appmodule.Environment
parameter to theInit
function within theImplementation
struct is a significant change that aligns with the PR's goal of integrating the environment context into the module's operations. This modification allows theInit
function to access and interact with the broader application environment, which is crucial for the new event emission functionality.- 117-117: The inclusion of
env appmodule.Environment
in theExecute
function signature is appropriate and necessary for the feature being implemented. It ensures that the execution process can be contextually aware of the environment, which is essential for event emission and other environment-specific logic.- 119-119: Incorporating the
env appmodule.Environment
parameter into theQuery
function is consistent with the overall goal of enhancing the module's interactivity and monitoring capabilities. This change allows the function to leverage the application's environment for event emission or other environment-specific logic.x/accounts/accountstd/exports.go (4)
- 9-9: The import statement for
cosmossdk.io/core/appmodule
is correctly added and follows Go conventions.- 38-38: The addition of
env appmodule.Environment
to the function signature ofRegisterExecuteHandler
aligns with the PR's objectives. Ensure all calls to this function are updated accordingly.- 46-46: The addition of
env appmodule.Environment
to the function signature ofRegisterQueryHandler
is appropriate. Verify that all invocations of this function have been updated to include the new parameter.- 54-54: Including
env appmodule.Environment
in the function signature ofRegisterInitHandler
is consistent with the PR's goal. Confirm that all calls to this function are adjusted to pass the new parameter.x/accounts/defaults/base/account.go (5)
- 16-16: The import statement for
cosmossdk.io/core/appmodule
is correctly added, following Go conventions.- 58-58: The inclusion of
_ appmodule.Environment
in theInit
function signature aligns with the PR's objectives. If the environment parameter is intended for future use, consider documenting its purpose or implementing its usage now.- 62-62: Including
_ appmodule.Environment
in theSwapPubKey
function signature is consistent with the PR's goals. As withInit
, if the environment parameter is planned for future use, its intended purpose should be documented or implemented.- 79-79: The addition of
_ appmodule.Environment
to theAuthenticate
function signature is appropriate. Again, if the environment parameter is to be used in the future, consider documenting its intended use or implementing it now.- 199-199: The inclusion of
_ appmodule.Environment
in theQuerySequence
function signature aligns with the PR's objectives. As with other functions, if the environment parameter is intended for future use, its purpose should be documented or implemented.x/accounts/keeper.go (3)
- 176-176: The inclusion of
k.environment
in the call toimpl.Init
within theinit
function correctly aligns with the PR's objectives. Ensure that theimpl.Init
function properly utilizes the environment parameter.- 237-237: Passing
k.environment
toimpl.Execute
in theExecute
function is correctly implemented. Verify that theimpl.Execute
function makes appropriate use of the environment parameter.- 262-262: Including
k.environment
in the call toimpl.Query
within theQuery
function aligns with the PR's objectives. Ensure that theimpl.Query
function properly utilizes the environment parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Commits
Files that changed from the base of the PR and between 150c8a8 and e0579f5811bde2be3fa5b11a46d524896e662260.Files selected for processing (1)
- x/accounts/keeper.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- x/accounts/keeper.go
question why dont we just pass the the event service into the |
hmm this seems to put it on the app dev to set it. i think its cleaner like the current approach |
seem like accounts Keeper struct already have appmodule Enviroment field, you just need to pass event service to the |
seems i have to go this way, i will amend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Files selected for processing (6)
- go.work.example (1 hunks)
- x/accounts/defaults/base/account.go (5 hunks)
- x/accounts/internal/implementation/context.go (2 hunks)
- x/accounts/internal/implementation/implementation.go (5 hunks)
- x/accounts/keeper.go (4 hunks)
- x/accounts/testing/counter/counter.go (6 hunks)
Files skipped from review as they are similar to previous changes (4)
- x/accounts/defaults/base/account.go
- x/accounts/internal/implementation/implementation.go
- x/accounts/keeper.go
- x/accounts/testing/counter/counter.go
Additional comments: 9
go.work.example (1)
- 3-3: The update of the Go toolchain version from
go1.22.0
togo1.22
is correct and aligns with Go versioning practices.x/accounts/internal/implementation/context.go (8)
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [11-13]
The definition of
AccountStatePrefix
usingcollections.NewPrefix(255)
is correct and follows best practices for defining a unique prefix for account state storage. This ensures that account data is properly namespaced within the module's storage.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [15-22]
The type definitions for
ModuleExecUntypedFunc
,ModuleExecFunc
, andModuleQueryFunc
are clear and well-defined. They provide a strong typing for module execution and query functions, which enhances code readability and maintainability.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [24-39]
The
contextValue
struct is well-structured and encapsulates all necessary information for account execution context. However, ensure that sensitive information, such assender
andwhoami
addresses, is handled securely throughout the codebase to prevent any potential security issues.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [41-48]
The functions
addCtx
andgetCtx
for adding and retrievingcontextValue
from acontext.Context
are correctly implemented. They follow best practices for context management in Go by usingcontext.WithValue
and type assertion.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [50-69]
The
MakeAccountContext
function is crucial for creating a new account execution context. It correctly initializes acontextValue
struct with all necessary fields and adds it to the provided context. Ensure that thestoreSvc
parameter is validated before use to prevent any potential issues with uninitialized or invalid store services.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [71-76]
The
makeAccountStore
function correctly creates a prefixed store for the account using the account number. This approach ensures that each account's state is isolated and easily accessible. The use ofbinary.BigEndian.PutUint64
for prefix generation is appropriate for ensuring a consistent byte representation across different platforms.
- 5-10: > 📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [78-109]
The functions
ExecModuleUntyped
,ExecModule
, andQueryModule
provide mechanisms for executing and querying module messages. They are well-implemented, leveraging thecontextValue
struct to access necessary context information. Ensure that error handling is robust and that any errors returned bymoduleExecUntyped
,moduleExec
, andmoduleQuery
are appropriately handled and logged.Verification successful
The review comment concerning the functions
ExecModuleUntyped
,ExecModule
, andQueryModule
and their error handling has been verified. The implementation of these functions incontext.go
demonstrates that errors from lower-level calls are appropriately returned to the caller, adhering to Go's error handling conventions. This approach allows callers to handle errors flexibly, including logging them if necessary. Test cases incontext_test.go
andaccount_test.go
further illustrate how these errors can be handled in practice. Based on the provided script output and analysis, the error handling mechanism for these functions appears to be robust and well-implemented.* 5-10: > 📝 **NOTE** > This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [111-122]Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for error handling patterns in the usage of `ExecModuleUntyped`, `ExecModule`, and `QueryModule`. rg --type go 'ExecModuleUntyped|ExecModule|QueryModule'Length of output: 90494
Utility functions like
openKVStore
,Sender
,Whoami
, andFunds
provide convenient access to the account execution context's fields. These functions are correctly implemented and follow best practices for encapsulation and data access within the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Files selected for processing (6)
- x/accounts/defaults/base/account.go (1 hunks)
- x/accounts/internal/implementation/api_builder_test.go (1 hunks)
- x/accounts/internal/implementation/implementation.go (4 hunks)
- x/accounts/keeper.go (1 hunks)
- x/accounts/testing/account_abstraction/minimal.go (4 hunks)
- x/accounts/testing/counter/counter.go (1 hunks)
Files skipped from review as they are similar to previous changes (6)
- x/accounts/defaults/base/account.go
- x/accounts/internal/implementation/api_builder_test.go
- x/accounts/internal/implementation/implementation.go
- x/accounts/keeper.go
- x/accounts/testing/account_abstraction/minimal.go
- x/accounts/testing/counter/counter.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Files selected for processing (3)
- x/accounts/internal/implementation/context.go (2 hunks)
- x/accounts/internal/implementation/implementation.go (4 hunks)
- x/accounts/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- x/accounts/internal/implementation/context.go
- x/accounts/internal/implementation/implementation.go
- x/accounts/keeper.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: .coderabbit.yml
Files selected for processing (1)
- x/accounts/keeper.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- x/accounts/keeper.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
Closes: #17687
add event emission to accounts module
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...
Summary by CodeRabbit
Refactor
New Features
Chores
appmodule
andevent
, facilitating new features and refactors.