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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
Expand Down Expand Up @@ -511,8 +513,6 @@ func New(
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:
Comment on lines 513 to 518
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.

Expand Down Expand Up @@ -1621,9 +1621,14 @@ func initParamsKeeper(
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint:staticcheck
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)

// register the key tables for legacy param subspaces
keyTable := ibcclient.ParamKeyTable()
keyTable.RegisterParamSet(&ibcconnectiontypes.Params{})
paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable)
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/app/msgs/normal_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ var (
"/ibc.core.client.v1.MsgRecoverClientResponse": nil,
"/ibc.core.client.v1.MsgSubmitMisbehaviour": &ibcclient.MsgSubmitMisbehaviour{}, //nolint:staticcheck
"/ibc.core.client.v1.MsgSubmitMisbehaviourResponse": nil,
// TODO(CORE-538): Move MsgUpdateClient and MsgUpgradeClient to unsupported_msgs once upgrade has been added
// and verified to function.
// TODO(CORE-851): Move MsgUpdateClient and MsgUpgradeClient to unsupported_msgs once v4.0.0 upgrade has
// been completed and Cosmos 0.50 performs well.
"/ibc.core.client.v1.MsgUpdateClient": &ibcclient.MsgUpdateClient{},
"/ibc.core.client.v1.MsgUpdateClientResponse": nil,
"/ibc.core.client.v1.MsgUpgradeClient": &ibcclient.MsgUpgradeClient{},
Expand Down
13 changes: 6 additions & 7 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
v3_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v3.0.0"
v4_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v4.0.0"
)

var (
// `Upgrades` defines the upgrade handlers and store loaders for the application.
// New upgrades should be added to this slice after they are implemented.
Upgrades = []upgrades.Upgrade{
v3_0_0.Upgrade,
v4_0_0.Upgrade,
}
Forks = []upgrades.Fork{}
)

// setupUpgradeHandlers registers the upgrade handlers to perform custom upgrade
// logic and state migrations for software upgrades.
func (app *App) setupUpgradeHandlers() {
if app.UpgradeKeeper.HasHandler(v3_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v3_0_0.UpgradeName))
if app.UpgradeKeeper.HasHandler(v4_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v4_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v3_0_0.UpgradeName,
v3_0_0.CreateUpgradeHandler(
v4_0_0.UpgradeName,
v4_0_0.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
app.AccountKeeper,
),
)
}
Expand Down
28 changes: 28 additions & 0 deletions protocol/app/upgrades/v4.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v_4_0_0

import (
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
)

const (
UpgradeName = "v4.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
// Add circuittypes as per 0.47 to 0.50 upgrade handler
// https://github.com/cosmos/cosmos-sdk/blob/b7d9d4c8a9b6b8b61716d2023982d29bdc9839a6/simapp/upgrades.go#L21
circuittypes.ModuleName,

// Add new ICA stores that are needed by ICA host types as of v8.
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
},
},
}
24 changes: 24 additions & 0 deletions protocol/app/upgrades/v4.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v_4_0_0

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName))

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

return mm.RunMigrations(ctx, configurator, vm)
}
}
1 change: 1 addition & 0 deletions protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
cosmossdk.io/log v1.2.1
cosmossdk.io/store v1.0.0
cosmossdk.io/tools/confix v0.1.0
cosmossdk.io/x/circuit v0.1.0
cosmossdk.io/x/evidence v0.1.0
cosmossdk.io/x/feegrant v0.1.0
cosmossdk.io/x/tx v0.12.0
Expand Down
1 change: 1 addition & 0 deletions protocol/testing/containertest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM dydxprotocol-base

COPY ./testing/containertest/dydxprotocold_preupgrade* /bin/
COPY ./testing/containertest/containertest.sh /dydxprotocol/containertest.sh
COPY ./testing/containertest/preupgrade_entrypoint.sh /dydxprotocol/preupgrade_entrypoint.sh
COPY ./testing/containertest/preupgrade_genesis.json /dydxprotocol/preupgrade_genesis.json
Expand Down
18 changes: 6 additions & 12 deletions protocol/testing/containertest/containertest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ set -eo pipefail
source "./genesis.sh"

CHAIN_ID="localdydxprotocol"
PREUPGRADE_VERSION="v2.0.0"

# Define mnemonics for all validators.
MNEMONICS=(
Expand Down Expand Up @@ -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.

arch="$(apk --print-arch)"
url_arch=""
file_arch=""
case "$arch" in
'x86_64')
url_arch='amd64'
file_arch='amd64'
;;
'aarch64')
url_arch='arm64'
file_arch='arm64'
;;
*)
echo >&2 "unexpected architecture '$arch'"
exit 1
;;
esac
tar_url="https://github.com/dydxprotocol/v4-chain/releases/download/protocol%2F$PREUPGRADE_VERSION/dydxprotocold-$PREUPGRADE_VERSION-linux-$url_arch.tar.gz"
tar_path='/tmp/dydxprotocold/dydxprotocold.tar.gz'
mkdir -p /tmp/dydxprotocold
curl -vL $tar_url -o $tar_path
dydxprotocold_path=$(tar -xvf $tar_path --directory /tmp/dydxprotocold)
cp /tmp/dydxprotocold/$dydxprotocold_path /bin/dydxprotocold_preupgrade
cp /bin/dydxprotocold_preupgrade_${file_arch} /bin/dydxprotocold_preupgrade
}

# TODO(DEC-1894): remove this function once we migrate off of persistent peers.
Expand All @@ -193,5 +187,5 @@ edit_config() {

install_prerequisites
setup_cosmovisor
download_preupgrade_binary
copy_preupgrade_binary_arch
create_validators
Binary file not shown.
Binary file not shown.