fix(simapp/v2): add MigrateAccountNumberUnsafe for v050-to-v2 (#23335)

This commit is contained in:
mmsqe 2025-01-13 15:42:42 +08:00 committed by GitHub
parent 921e1b2867
commit 0dafc77620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 5 deletions

View File

@ -19,7 +19,7 @@ import (
//
// NOTE: This upgrade defines a reference implementation of what an upgrade
// could look like when an application is migrating from Cosmos SDK version
// v0.59.x to v0.52.x.
// v0.50.x to v0.52.x.
const UpgradeName = "v050-to-v052"
func (app SimApp) RegisterUpgradeHandlers() {

View File

@ -27,6 +27,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
_ "github.com/cosmos/cosmos-sdk/x/genutil"
)
@ -45,6 +46,7 @@ type SimApp[T transaction.Tx] struct {
// others keepers are all in the app
UpgradeKeeper *upgradekeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
AuthKeeper authkeeper.AccountKeeper
}
// AppConfig returns the default app config.
@ -151,7 +153,9 @@ func NewSimApp[T transaction.Tx](
&app.txConfig,
&app.interfaceRegistry,
&app.UpgradeKeeper,
&app.StakingKeeper)
&app.StakingKeeper,
&app.AuthKeeper,
)
if err := depinject.Inject(appConfig, outputs...); err != nil {
return nil, err

View File

@ -258,7 +258,10 @@ require (
// replace (
// <temporary replace>
// )
replace cosmossdk.io/server/v2/cometbft => ../../server/v2/cometbft
replace (
cosmossdk.io/server/v2/cometbft => ../../server/v2/cometbft
cosmossdk.io/x/staking => cosmossdk.io/x/staking v0.2.0-rc.1.0.20250109101855-4c6e34be28c1
)
// Below are the long-lived replace of the SimApp
replace (

View File

@ -268,8 +268,8 @@ cosmossdk.io/x/protocolpool v0.2.0-rc.1 h1:BNtRCp/TStXYSW0uc5KJTtJoTVOCaF7/P6Smx
cosmossdk.io/x/protocolpool v0.2.0-rc.1/go.mod h1:asoCc7jX1kMqaJ9sI1U67P2evXjVKXSngTgGinAXTZo=
cosmossdk.io/x/slashing v0.2.0-rc.1 h1:RNAV5JN7nIuyDtGclPoN1iFl92Edu71ERl/OtFSS06I=
cosmossdk.io/x/slashing v0.2.0-rc.1/go.mod h1:uICi76DI/iwfgPbETb8sVio6dEA4Q4sv4Vqj9cxn2zI=
cosmossdk.io/x/staking v0.2.0-rc.1 h1:AZRGddRuuTaLxxpBvC7/TR7Dmt0pjziXWk13dC1beIo=
cosmossdk.io/x/staking v0.2.0-rc.1/go.mod h1:7K4hgQ6tn0XLFb2BJ9oe8nEc4RkfQ4qHqgQy2b0kVNc=
cosmossdk.io/x/staking v0.2.0-rc.1.0.20250109101855-4c6e34be28c1 h1:/IEkm90NCAatqdKITvVumjsbnMRldOimcslNiQ0gJlg=
cosmossdk.io/x/staking v0.2.0-rc.1.0.20250109101855-4c6e34be28c1/go.mod h1:eb4WWz3WB8lryUutt5pPuevwgqMSGsh0iPgr0VZr2kc=
cosmossdk.io/x/tx v1.0.0 h1:pUUKRvHiMUZC/MnO8v747k1lUEA1DfAq0j0y0Mqrz/o=
cosmossdk.io/x/tx v1.0.0/go.mod h1:AXYJ47btzkcWuT1OtA3M44dv1iiYbKomtopHEbQGgH4=
cosmossdk.io/x/upgrade v0.2.0-rc.1 h1:YO865mCFIsFyjzl1fOsOr7Hw2iVGJhTGwecUC3u0YBY=

View File

@ -10,6 +10,8 @@ import (
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
)
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
@ -24,6 +26,9 @@ func (app *SimApp[T]) RegisterUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
UpgradeName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
if err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper); err != nil {
return nil, err
}
return app.ModuleManager().RunMigrations(ctx, fromVM)
},
)