-
Notifications
You must be signed in to change notification settings - Fork 115
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
initialize megavault module account in 7.0.0 upgrade handler #2394
Conversation
WalkthroughThe changes introduce modifications to the upgrade handling process within the protocol. The Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
protocol/app/upgrades/v7.0.0/upgrade.go (1)
83-84
: Update Reference in Comment for MaintainabilityThe comment references a specific commit in a forked repository, which may become outdated or inaccessible.
Consider updating the comment to refer to a stable reference or include the relevant code snippet directly for clarity.
// Implementation taken from - // https://github.com/dydxprotocol/cosmos-sdk/blob/bdf96fdd/x/auth/keeper/keeper.go#L213 + // Based on the AccountKeeper's NewAccount method in the Cosmos SDK.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- protocol/app/upgrades.go (1 hunks)
- protocol/app/upgrades/v7.0.0/upgrade.go (3 hunks)
🔇 Additional comments (5)
protocol/app/upgrades.go (1)
33-35
: LGTM. Verify v7.0.0 upgrade handler and update documentation.The addition of
app.AccountKeeper
to theCreateUpgradeHandler
function call aligns with the PR objective of initializing the megavault module account in the 7.0.0 upgrade handler. This change allows the upgrade handler to interact with account-related functionalities during the upgrade process.To ensure consistency, please verify that the
CreateUpgradeHandler
function in the v7.0.0 package has been updated to accept this newAccountKeeper
parameter. Run the following script to check the function signature:Additionally, please update any relevant documentation or comments related to this upgrade handler to reflect the addition of the AccountKeeper parameter.
✅ Verification successful
Further Verification Needed: Search for the
CreateUpgradeHandler
function definition across the entire codebase.Please run the following script to locate the
CreateUpgradeHandler
function:
Further Verification Needed: Confirm the
CreateUpgradeHandler
function signature in v7.0.0.Please run the following script to retrieve the function signature:
<!-- [monologue] [task review_file_1/1 verification_attempt_3/3] The `CreateUpgradeHandler` function in `v7.0.0` now includes the `accountKeeper` parameter as required. [observations] - The function signature in `protocol/app/upgrades/v7.0.0/upgrade.go` includes `accountKeeper authkeeper.AccountKeeper`. - This matches the code snippet provided in the review comment. - No discrepancies found between the review comment and the actual code. [analysis] - The addition of `app.AccountKeeper` aligns with the PR objectives. - The function signature is correctly updated, ensuring that the upgrade handler can interact with account-related functionalities. - No further verification is necessary unless documentation updates are pending. [actions] - Conclude the verification process as successful. - No additional shell scripts are needed. -->Verification Successful:
CreateUpgradeHandler
in v7.0.0 correctly includesapp.AccountKeeper
.The
CreateUpgradeHandler
function inprotocol/app/upgrades/v7.0.0/upgrade.go
now includes theaccountKeeper authkeeper.AccountKeeper
parameter as intended. This change aligns with the PR objective of initializing the megavault module account in the 7.0.0 upgrade handler.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the CreateUpgradeHandler function signature in the v7.0.0 package # Test: Search for the CreateUpgradeHandler function definition rg --type go -A 5 'func CreateUpgradeHandler' | grep -A 5 'v7_0_0'Length of output: 66
Script:
# Description: Locate the CreateUpgradeHandler function definition across the codebase rg --type go 'func CreateUpgradeHandler'Length of output: 511
Script:
#!/bin/bash # Description: Retrieve the CreateUpgradeHandler function signature in the v7.0.0 package rg --type go 'func CreateUpgradeHandler' -A 5 protocol/app/upgrades/v7.0.0/upgrade.goLength of output: 284
protocol/app/upgrades/v7.0.0/upgrade.go (4)
11-12
: Appropriate Import StatementsThe imports for
authkeeper
andauthtypes
are correctly added and necessary for the account initialization logic.
25-29
: Initialization of Module Accounts ListThe
ModuleAccsToInitialize
variable is properly defined and includes the required module account names.
31-92
: Review ofinitializeModuleAccs
FunctionThe
initializeModuleAccs
function effectively initializes module accounts or converts existing accounts to module accounts as needed. The logic is sound and follows best practices.
200-210
: Update ofCreateUpgradeHandler
Function SignatureThe addition of the
accountKeeper
parameter toCreateUpgradeHandler
and its use in initializing module accounts is appropriate and necessary for the upgrade process.
if !ok { | ||
panic(fmt.Sprintf( | ||
"cannot cast %v into a BaseAccount, acc = %+v", | ||
modAccName, | ||
acc, | ||
)) | ||
} |
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.
Ensure Safe Type Assertion to *authtypes.BaseAccount
The type assertion baseAccount, ok := acc.(*authtypes.BaseAccount)
may fail if acc
is not of type *authtypes.BaseAccount
, leading to a panic. Verify that this conversion is always safe in your context, or handle the case where it might fail more gracefully.
Consider adding error handling or logging to manage unexpected account types without panicking, if appropriate.
panic(fmt.Sprintf( | ||
"Did not find %v in `ak.GetModuleAddressAndPermissions`. This is not expected. Skipping.", | ||
modAccName, | ||
)) | ||
} |
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.
Clarify Panic Message for Missing Module Account
The panic message suggests that the module account will be skipped, but since the code is panicking, execution will halt. This could be misleading.
Consider rephrasing the panic message to accurately convey the severity of the error:
panic(fmt.Sprintf(
- "Did not find %v in `ak.GetModuleAddressAndPermissions`. This is not expected. Skipping.",
+ "Did not find %v in `ak.GetModuleAddressAndPermissions`. This is unexpected and will halt the upgrade.",
modAccName,
))
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
panic(fmt.Sprintf( | |
"Did not find %v in `ak.GetModuleAddressAndPermissions`. This is not expected. Skipping.", | |
modAccName, | |
)) | |
} | |
panic(fmt.Sprintf( | |
"Did not find %v in `ak.GetModuleAddressAndPermissions`. This is unexpected and will halt the upgrade.", | |
modAccName, | |
)) | |
} |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- protocol/app/upgrades/v7.0.0/upgrade_container_test.go (3 hunks)
🔇 Additional comments (2)
protocol/app/upgrades/v7.0.0/upgrade_container_test.go (2)
11-11
: Import statement added appropriatelyThe import of
authtypes
is necessary for querying module accounts.
57-57
: Invocation ofpostUpgradeMegavaultModuleAccCheck
is correctThe function
postUpgradeMegavaultModuleAccCheck
is correctly added to the post-upgrade checks.
func postUpgradeMegavaultModuleAccCheck(node *containertest.Node, t *testing.T) { | ||
resp, err := containertest.Query( | ||
node, | ||
authtypes.NewQueryClient, | ||
authtypes.QueryClient.ModuleAccountByName, | ||
&authtypes.QueryModuleAccountByNameRequest{ | ||
Name: vaulttypes.MegavaultAccountName, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, resp) | ||
|
||
moduleAccResp := authtypes.QueryModuleAccountByNameResponse{} | ||
err = proto.UnmarshalText(resp.String(), &moduleAccResp) | ||
require.NoError(t, err) | ||
} |
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.
🛠️ Refactor suggestion
Enhance verification of the module account's properties
After querying and unmarshalling the module account, it's important to verify that the account has the expected attributes. This ensures the module account is not only initialized but also correctly configured.
Consider adding assertions like:
require.NotNil(t, moduleAccResp.Account)
require.Equal(t, vaulttypes.MegavaultAccountName, moduleAccResp.Account.Name)
// Add additional checks as necessary
Simplify response handling by directly using the response object
Instead of unmarshalling the response from text, you can directly use the response object returned by the query. This simplifies the code and avoids unnecessary parsing.
Apply this diff to simplify the code:
-moduleAccResp := authtypes.QueryModuleAccountByNameResponse{}
-err = proto.UnmarshalText(resp.String(), &moduleAccResp)
-require.NoError(t, err)
+moduleAccResp := resp.(*authtypes.QueryModuleAccountByNameResponse)
Co-authored-by: Vincent Chau <[email protected]> (cherry picked from commit 98486d9)
…#2394) (#2400) Co-authored-by: Tian <[email protected]>
Co-authored-by: Vincent Chau <[email protected]>
Changelist
[Describe or list the changes made in this PR]
Test Plan
[Describe how this PR was tested (if applicable)]
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit