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

[CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade handler. #918

Merged
merged 3 commits into from Jan 6, 2024

Conversation

lcwik
Copy link
Contributor

@lcwik lcwik commented Jan 2, 2024

Changelist

[CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade handler.

This adds the 3.0.0-dev0 binaries statically and fixes the IBC parameter space to map the old parameters to the new ones allowing for the IBC upgrade as per the upgrade guide and this sample.

It turns out that the upgrade handlers are already routable and the existing logic could be removed safely without requiring a replacement.

Decided to allow for using the existing upgrade messages to allow the maximum flexibility when doing the release and punted deprecation till once users are on Cosmos 0.50 for some time.

Finally, delete the 3.0.0 upgrade handler.

Test Plan

Re-enabled TestUpgrade

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link

coderabbitai bot commented Jan 2, 2024

Warning

Rate Limit Exceeded

@lcwik has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 54 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 2d52be9 and 2192e87.

Walkthrough

The changes involve a protocol application upgrade from version 3.0.0 to 4.0.0. This upgrade includes adding new imports for IBC client and connection types, cleaning up code, updating upgrade handlers and constants, and adjusting testing scripts and containers to accommodate the new version. There is also a focus on migrating messages related to client updates and upgrades, as well as registering key tables for legacy parameter subspaces.

Changes

File(s) Summary of Changes
protocol/app/app.go Added ibcclient and ibcconnectiontypes imports; removed old upgrade code; adjusted initParamsKeeper for legacy param subspaces.
protocol/app/msgs/normal_msgs.go Updated TODOs for moving certain messages to unsupported_msgs after upgrade verification.
protocol/app/upgrades.go
protocol/app/upgrades/v4.0.0/upgrade.go
Updated import paths and upgrade slice for v4.0.0; changed upgrade conditions and panic messages; added new upgrade handling package and function.
protocol/app/upgrades/v4.0.0/constants.go Introduced Upgrade constant with upgrade name and new store upgrades.
protocol/testing/containertest/Dockerfile Added new dydxprotocold_preupgrade* binary to the /bin/ directory.
protocol/testing/containertest/containertest.sh Renamed preupgrade binary function; replaced download logic with copy logic; adjusted config editing function.
protocol/testing/containertest/testnet.go
protocol/testing/containertest/testnet_test.go
Updated UpgradeToVersion constant to "v4.0.0"; modified test function to align with new version and updated testing logic.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit's AI:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@lcwik lcwik changed the title Lukecore538.3 [CORE-538] Add 4.0.0 upgrade handler for cosmos 0.50 upgrade Jan 2, 2024
Copy link

linear bot commented Jan 2, 2024

@github-actions github-actions bot removed the proto label Jan 4, 2024
@lcwik lcwik changed the title [CORE-538] Add 4.0.0 upgrade handler for cosmos 0.50 upgrade [CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade handler. Jan 4, 2024
@lcwik lcwik marked this pull request as ready for review January 4, 2024 22:54
@lcwik lcwik changed the title [CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade handler. [CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade. Jan 4, 2024
@coderabbitai coderabbitai bot changed the title [CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade. [CORE-538] Add 4.0.0 upgrade handler for Cosmos 0.47 -> 0.50 upgrade handler. Jan 4, 2024
Copy link

@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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 925b3b3 and 44ffded.
Files ignored due to filter (2)
  • protocol/go.mod
  • protocol/testing/containertest/preupgrade_genesis.json
Files selected for processing (9)
  • protocol/app/app.go (3 hunks)
  • protocol/app/msgs/normal_msgs.go (1 hunks)
  • protocol/app/upgrades.go (1 hunks)
  • protocol/app/upgrades/v4.0.0/constants.go (1 hunks)
  • protocol/app/upgrades/v4.0.0/upgrade.go (1 hunks)
  • protocol/testing/containertest/Dockerfile (1 hunks)
  • protocol/testing/containertest/containertest.sh (3 hunks)
  • protocol/testing/containertest/testnet.go (1 hunks)
  • protocol/testing/containertest/testnet_test.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • protocol/app/msgs/normal_msgs.go
  • protocol/testing/containertest/Dockerfile
  • protocol/testing/containertest/testnet_test.go
Additional comments: 9
protocol/app/upgrades/v4.0.0/upgrade.go (1)
  • 12-22: The CreateUpgradeHandler function correctly sets up an upgrade handler that logs the upgrade name and runs migrations. Ensure that the logging format and migration process are consistent with the project's standards.
protocol/app/upgrades/v4.0.0/constants.go (1)
  • 11-28: The Upgrade variable is correctly defined with the new UpgradeName and StoreUpgrades. Verify that the added module names in StoreUpgrades match the expected modules for the 0.47 to 0.50 upgrade.
protocol/app/upgrades.go (1)
  • 9-34: The Upgrades slice and setupUpgradeHandlers function have been correctly updated to include and handle the v4_0_0 upgrade. Ensure that there are no duplicate handlers for the same upgrade name.
protocol/testing/containertest/testnet.go (1)
  • 28-28: The UpgradeToVersion constant has been correctly updated to "v4.0.0". Confirm that this version is used consistently in the testnet setup and matches the upgrade version being tested.
protocol/testing/containertest/containertest.sh (2)
  • 156-171: The copy_preupgrade_binary_arch function has been updated to copy the preupgrade binary based on the system architecture. Verify that the correct binaries are being copied for each architecture.

  • 190-190: The script now calls copy_preupgrade_binary_arch to handle the preupgrade binary. Ensure that this change is reflected in the CI/CD pipeline and that the correct binary is used during testing.

protocol/app/app.go (3)
  • 182-183: The imports for ibcclient and ibcconnectiontypes have been added. Ensure that these new dependencies are used appropriately within the application and that their introduction does not introduce any compatibility issues with existing code.
Verification successful

The executed scripts aimed to verify the usage of the newly added imports ibcclient and ibcconnectiontypes in the app.go file. However, the scripts did not produce any output, which suggests that these specific imports might not be used in the codebase, or there might be an issue with the script execution.

To further investigate, I will generate a new script to search for the usage of the types or functions from these imported packages throughout the entire codebase, not just in the app.go file.


The new script output confirms that the imports ibcclient and ibcconnectiontypes are indeed used within the codebase. The ibcclient package is referenced in various files, such as internal_msg.go, normal_msgs.go, internal_msgs.go, and within app.go itself. Similarly, the ibcconnectiontypes package is used in app.go to register a parameter set.

This indicates that the new dependencies are utilized appropriately and are not just added without being referenced, which addresses the initial concern of the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the newly added imports are used in the codebase.
ast-grep --lang go --pattern $'import $$$; ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"'
ast-grep --lang go --pattern $'import $$$; ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"'

Length of output: 240



Script:

#!/bin/bash
# Search for usage of types or functions from the ibcclient package
rg "ibcclient\."

# Search for usage of types or functions from the ibcconnectiontypes package
rg "ibcconnectiontypes\."

Length of output: 1119

* 1624-1631: The `initParamsKeeper` function has been adjusted to register key tables for legacy param subspaces, specifically for IBC-related modules. Confirm that these changes are in line with the intended upgrade path and that the key tables are correctly configured.
Verification successful

The full contents of the initParamsKeeper function have been successfully retrieved, showing the registration of key tables for legacy param subspaces, particularly for IBC-related modules. This confirms that the changes are in line with the PR objectives and the review comment is consistent with the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the key tables for legacy param subspaces are correctly registered in the codebase.
ast-grep --lang go --pattern $'func initParamsKeeper($$$) $$$ { $$$ keyTable := ibcclient.ParamKeyTable(); $$$ }'

Length of output: 114



Script:

#!/bin/bash
# Search for the initParamsKeeper function to verify the registration of key tables for legacy param subspaces.
ast-grep --lang go --pattern $'func initParamsKeeper($$$) { $$$ }'

Length of output: 67



Script:

#!/bin/bash
# Search for the initParamsKeeper function across the codebase to verify its existence and contents.
rg "func initParamsKeeper"

Length of output: 71



Script:

#!/bin/bash
# Display the contents of the initParamsKeeper function from the protocol/app/app.go file.
cat protocol/app/app.go | sed -n -e '/func initParamsKeeper/,/}/p'

Length of output: 818



Script:

#!/bin/bash
# Display the full contents of the initParamsKeeper function from the protocol/app/app.go file to verify the registration of key tables for legacy param subspaces.
cat protocol/app/app.go | sed -n -e '/func initParamsKeeper/,/}/p'

Length of output: 818



Script:

#!/bin/bash
# Display the full contents of the initParamsKeeper function from the protocol/app/app.go file to verify the registration of key tables for legacy param subspaces.
# Using a range pattern that extends to the end of the function block.
cat protocol/app/app.go | sed -n '/func initParamsKeeper(/,/^}/p'

Length of output: 1210

* 1626-1631: The registration of IBC-related subspaces within the `initParamsKeeper` function includes the creation of a key table and the registration of parameter sets. Ensure that the parameter sets are complete and that the key table is properly utilized within the application.
Verification successful

The search results confirm the registration of IBC-related subspaces and their key tables within the initParamsKeeper function in the app.go file. The key table is created using ibcclient.ParamKeyTable() and is used to register the parameter set for ibcconnectiontypes.Params. Subsequently, the paramsKeeper.Subspace method is called with the appropriate module names and their respective key tables.

Based on the provided output, the parameter sets appear to be complete, and the key table is properly utilized within the application. Therefore, the review comment has been verified and no issues were found with the registration of these subspaces and their key tables.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the parameter sets are complete and that the key table is properly utilized.
ast-grep --lang go --pattern $'func initParamsKeeper($$$) $$$ { $$$ keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}); $$$ }'

Length of output: 132



Script:

#!/bin/bash
# Verify the registration of the IBC-related subspaces and their key tables in the `initParamsKeeper` function.
ast-grep --lang go --pattern $'func initParamsKeeper($$$) {
  $$$
  keyTable := ibcclient.ParamKeyTable()
  keyTable.RegisterParamSet(&$_)
  paramsKeeper.Subspace($_).WithKeyTable(keyTable)
  $$$
}'

Length of output: 199



Script:

#!/bin/bash
# Adjust the pattern to be less specific and try to match any usage of `keyTable.RegisterParamSet` and `paramsKeeper.Subspace` within the `initParamsKeeper` function.
ast-grep --lang go --pattern $'func initParamsKeeper($$$) {
  $$$
  $_.RegisterParamSet(&$_)
  paramsKeeper.Subspace($_).WithKeyTable($_)
  $$$
}'

Length of output: 147



Script:

#!/bin/bash
# Use ripgrep to search for the relevant lines in the `app.go` file directly.
rg "keyTable := ibcclient.ParamKeyTable\(\)" -A 5 protocol/app/app.go

Length of output: 536

…handler.

This adds the 3.0.0-dev0 binaries statically and fixes the IBC parameter space to map the old parameters to the new ones allowing for the IBC upgrade as per the upgrade guide
(https://github.com/cosmos/ibc-go/blob/e3e8f343d05d3f7dfd958877562bca3aff89b758/docs/docs/05-migrations/11-v7-to-v8.md#params-migration) and this sample
(https://github.com/cosmos/ibc-go/blob/v8.0.0/testing/simapp/app.go#L1007-L1012).

It turns out that the upgrade handlers are already routable and the existing logic could be removed safely without requiring a replacement.

Decided to allow for using the existing upgrade messages to allow the maximum flexibility when doing the release and punted deprecation till once users are on Cosmos 0.50 for some time.

Finally, delete the 3.0.0 upgrade handler.
Copy link

@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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7e793b6 and 2d52be9.
Files ignored due to filter (2)
  • protocol/go.mod
  • protocol/testing/containertest/preupgrade_genesis.json
Files selected for processing (9)
  • protocol/app/app.go (3 hunks)
  • protocol/app/msgs/normal_msgs.go (1 hunks)
  • protocol/app/upgrades.go (1 hunks)
  • protocol/app/upgrades/v4.0.0/constants.go (1 hunks)
  • protocol/app/upgrades/v4.0.0/upgrade.go (1 hunks)
  • protocol/testing/containertest/Dockerfile (1 hunks)
  • protocol/testing/containertest/containertest.sh (3 hunks)
  • protocol/testing/containertest/testnet.go (1 hunks)
  • protocol/testing/containertest/testnet_test.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • protocol/app/msgs/normal_msgs.go
  • protocol/testing/containertest/Dockerfile
Additional comments: 8
protocol/app/upgrades/v4.0.0/upgrade.go (1)
  • 12-22: The CreateUpgradeHandler function correctly creates an upgrade handler that logs the upgrade name and runs migrations. The use of fmt.Sprintf within the logger is appropriate for dynamic messages.
protocol/app/upgrades/v4.0.0/constants.go (1)
  • 11-28: The UpgradeName constant and Upgrade variable are correctly defined. The added module names in the StoreUpgrades reflect the necessary changes for the Cosmos SDK upgrade from 0.47 to 0.50.
protocol/app/upgrades.go (2)
  • 13-17: The Upgrades slice has been correctly updated to include the v4_0_0.Upgrade, which is necessary for the upgrade process.

  • 21-34: The setupUpgradeHandlers function properly checks for duplicate handlers and sets up the new upgrade handler for v4_0_0. The panic on duplicate handlers is a good safeguard.

protocol/testing/containertest/testnet.go (1)
  • 28-28: The UpgradeToVersion constant has been correctly updated to "v4.0.0" to reflect the new upgrade version.
protocol/testing/containertest/containertest.sh (2)
  • 156-171: The copy_preupgrade_binary_arch function has been introduced to handle the copying of the preupgrade binary based on the system architecture. This change simplifies the process and removes the need to download the binary.

  • 190-190: The copy_preupgrade_binary_arch function is correctly called within the script to ensure the preupgrade binary is available for the correct architecture.

protocol/app/app.go (1)
  • 1621-1631: The changes in the initParamsKeeper function include the registration of key tables for legacy param subspaces. Ensure that the subspace names and key tables are correctly associated with their respective modules. This is crucial for the correct functioning of the parameter store.

@@ -179,6 +179,8 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclient "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // nolint:staticcheck
Copy link

Choose a reason for hiding this comment

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

The import of ibcclient is marked with nolint:staticcheck. Please ensure that ignoring lint warnings is justified and documented as to why it's necessary in this case. If the import is unused, consider removing it to keep the code clean.

Comment on lines 513 to 518
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))
/** TODO(CORE-538): Migrate software upgrade type to Cosmos 0.50.
.AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)) */
govConfig := govtypes.DefaultConfig()
/*
Example of setting gov params:
Copy link

Choose a reason for hiding this comment

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

The commented code in lines 513-518 appears to be an example configuration for governance parameters. If this is intended as documentation, it should be clearly marked as such or moved to official documentation. If it's not needed, it should be removed to avoid confusion.

Comment on lines 287 to 292
func TestUpgrade(t *testing.T) {
t.Skip("TODO(CORE-538): Update upgrade handler for Cosmos 0.50 upgrade")

// TODO(CORE-538): Swap to using official 3.0.0 binaries, if they are the same as 3.0.0-dev0 then remove this
// line as that is what is currently being used.
testnet, err := NewTestnetWithPreupgradeGenesis()
require.NoError(t, err, "failed to create testnet - is docker daemon running?")
err = testnet.Start()
Copy link

Choose a reason for hiding this comment

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

The TestUpgrade function has been updated with a TODO comment regarding the use of official binaries. This comment should be addressed to ensure that the correct binaries are used for testing the upgrade process.

sdkCtx.Logger().Info("Running %s Upgrade...", UpgradeName)
InitializeModuleAccs(sdkCtx, ak)

// TODO(CORE-824): Initialize ratelimit module params to desired state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this TODO to v4.0.0 handler? ratelimit module is not implemented fully yet, but it will have genesis params and those need to be initialized properly.

@@ -154,27 +153,22 @@ setup_cosmovisor() {
done
}

download_preupgrade_binary() {
copy_preupgrade_binary_arch() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can start using v3.0.0-rc0 binaries (building right now and will be published soon for testnet).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we just swap them for the 3.0.0 binaries once they are qualified. I don't suspect that this swap will cause many issues and then we will only need to do it the one time.

@@ -1,169 +0,0 @@
package v_3_0_0
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we keep this old upgrade handler around? If I understand correctly it doesn't cost anything.

If we want to cherry-pick something that needs to modify the upgrade handler, it will be nice to have still.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can keep but I suspect the merge pain of developing here and then porting it to 0.47 would be annoying when cherry-picking on to 3.0.0 release branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh good point. Then I don't care either way.

@lcwik lcwik merged commit d552a3d into main Jan 6, 2024
17 checks passed
@lcwik lcwik deleted the lukecore538.3 branch January 6, 2024 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants