-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade: cosmos to 0.47, evmos to v19 (#203)
- Loading branch information
Showing
16 changed files
with
167 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
package v1 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" | ||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
) | ||
|
||
const ( | ||
// UpgradeName is the shared upgrade plan name for mainnet | ||
UpgradeName = "v2.0.0" | ||
) | ||
|
||
var StoreUpgrades = store.StoreUpgrades{ | ||
Added: []string{ | ||
consensustypes.ModuleName, | ||
crisistypes.ModuleName, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,114 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" | ||
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" | ||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" | ||
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations" | ||
evmtypes "github.com/evmos/evmos/v19/x/evm/types" | ||
feemarkettypes "github.com/evmos/evmos/v19/x/feemarket/types" | ||
) | ||
|
||
// CreateUpgradeHandler creates an SDK upgrade handler for v2 | ||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
ak authkeeper.AccountKeeper, | ||
ck consensuskeeper.Keeper, | ||
clientKeeper ibctmmigrations.ClientKeeper, | ||
pk paramskeeper.Keeper, | ||
cdc codec.BinaryCodec, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
// Leave modules as-is to avoid running InitGenesis. | ||
logger := ctx.Logger().With("upgrade", UpgradeName) | ||
|
||
// Set param key table for params module migration | ||
for _, subspace := range pk.GetSubspaces() { | ||
var keyTable paramstypes.KeyTable | ||
switch subspace.Name() { | ||
case authtypes.ModuleName: | ||
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck | ||
case banktypes.ModuleName: | ||
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck,nolintlint | ||
case stakingtypes.ModuleName: | ||
keyTable = stakingtypes.ParamKeyTable() | ||
case minttypes.ModuleName: | ||
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck | ||
case distrtypes.ModuleName: | ||
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck,nolintlint | ||
case slashingtypes.ModuleName: | ||
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck | ||
case govtypes.ModuleName: | ||
keyTable = govv1.ParamKeyTable() //nolint:staticcheck | ||
case crisistypes.ModuleName: | ||
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck | ||
case ibctransfertypes.ModuleName: | ||
keyTable = ibctransfertypes.ParamKeyTable() | ||
case evmtypes.ModuleName: | ||
keyTable = evmtypes.ParamKeyTable() //nolint:staticcheck | ||
case feemarkettypes.ModuleName: | ||
keyTable = feemarkettypes.ParamKeyTable() | ||
default: | ||
continue | ||
} | ||
if !subspace.HasKeyTable() { | ||
subspace.WithKeyTable(keyTable) | ||
} | ||
} | ||
|
||
baseAppLegacySS := pk.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) | ||
|
||
baseapp.MigrateParams(ctx, baseAppLegacySS, &ck) | ||
|
||
// Include this when migrating to ibc-go v7 (optional) | ||
// source: https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md | ||
// prune expired tendermint consensus states to save storage space | ||
if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, cdc, clientKeeper); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := MigrateFeeCollector(ak, ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
logger.Debug("running module migrations ...") | ||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} | ||
|
||
func MigrateFeeCollector(ak authkeeper.AccountKeeper, ctx sdk.Context) error { | ||
feeCollectorModuleAccount := ak.GetModuleAccount(ctx, authtypes.FeeCollectorName) | ||
if feeCollectorModuleAccount == nil { | ||
return fmt.Errorf("fee collector module account not found") | ||
} | ||
|
||
modAcc, ok := feeCollectorModuleAccount.(*authtypes.ModuleAccount) | ||
if !ok { | ||
return fmt.Errorf("fee collector module account is not a module account") | ||
} | ||
|
||
// Create a new FeeCollector module account with the same address and balance as the old one. | ||
newFeeCollectorModuleAccount := authtypes.NewModuleAccount(modAcc.BaseAccount, authtypes.FeeCollectorName, authtypes.Burner) | ||
|
||
// Override the FeeCollector module account in the auth keeper. | ||
ak.SetModuleAccount(ctx, newFeeCollectorModuleAccount) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters