diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index ff48c44a7f..58c29f0012 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -10,8 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" - snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/snapshots" + snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" "github.com/cosmos/cosmos-sdk/testutil" ) diff --git a/pruning/manager.go b/pruning/manager.go index 8b869799de..8e7c61cc9e 100644 --- a/pruning/manager.go +++ b/pruning/manager.go @@ -22,15 +22,15 @@ type Manager struct { snapshotInterval uint64 // Although pruneHeights happen in the same goroutine with the normal execution, // we sync access to them to avoid soundness issues in the future if concurrency pattern changes. - pruneHeightsMx sync.Mutex - pruneHeights []int64 + pruneHeightsMx sync.Mutex + pruneHeights []int64 // Snapshots are taken in a separate goroutine from the regular execution // and can be delivered asynchrounously via HandleHeightSnapshot. - // Therefore, we sync access to pruneSnapshotHeights with this mutex. + // Therefore, we sync access to pruneSnapshotHeights with this mutex. pruneSnapshotHeightsMx sync.Mutex // These are the heights that are multiples of snapshotInterval and kept for state sync snapshots. // The heights are added to this list to be pruned when a snapshot is complete. - pruneSnapshotHeights *list.List + pruneSnapshotHeights *list.List } // NegativeHeightsError is returned when a negative height is provided to the manager. @@ -162,7 +162,7 @@ func (m *Manager) HandleHeightSnapshot(height int64) { m.pruneSnapshotHeightsMx.Lock() defer m.pruneSnapshotHeightsMx.Unlock() - + m.logger.Debug("HandleHeightSnapshot", "height", height) m.pruneSnapshotHeights.PushBack(height) diff --git a/simapp/app.go b/simapp/app.go index 3d5ea67e5c..799a95b605 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -324,6 +324,10 @@ func NewSimApp( ) // set the governance module account as the authority for conducting upgrades app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + + // RegisterUpgradeHandlers is used for registering any on-chain upgrades + app.RegisterUpgradeHandlers() + app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) // create evidence keeper with router @@ -605,7 +609,7 @@ func (app *SimApp) RegisterTendermintService(clientCtx client.Context) { } // RegisterSwaggerAPI registers swagger route with API Server -func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { +func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) { statikFS, err := fs.New() if err != nil { panic(err) diff --git a/simapp/upgrades.go b/simapp/upgrades.go new file mode 100644 index 0000000000..2a62ae5c88 --- /dev/null +++ b/simapp/upgrades.go @@ -0,0 +1,68 @@ +package simapp + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/group" + "github.com/cosmos/cosmos-sdk/x/nft" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" +) + +// UpgradeName defines the on-chain upgrade name for the sample simap upgrade from v045 to v046. +// +// NOTE: This upgrade defines a reference implementation of what an upgrade could look like +// when an application is migrating from Cosmos SDK version v0.45.x to v0.46.x. +const UpgradeName = "v045-to-v046" + +func (app SimApp) RegisterUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler(UpgradeName, + func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + // We set fromVersion to 1 to avoid running InitGenesis for modules for + // in-store migrations. + // + // If you wish to skip any module migrations, i.e. they were already migrated + // in an older version, you can use `modulename.AppModule{}.ConsensusVersion()` + // instead of `1` below. + // + // For example: + // "auth": auth.AppModule{}.ConsensusVersion() + fromVM := map[string]uint64{ + "auth": 1, + "authz": 1, + "bank": 1, + "capability": 1, + "crisis": 1, + "distribution": 1, + "evidence": 1, + "feegrant": 1, + "gov": 1, + "mint": 1, + "params": 1, + "slashing": 1, + "staking": 1, + "upgrade": 1, + "vesting": 1, + "genutil": 1, + } + + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(err) + } + + if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := storetypes.StoreUpgrades{ + Added: []string{ + group.ModuleName, + nft.ModuleName, + }, + } + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } +} diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index d83e30ee00..cccc4ffb25 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -8,9 +8,9 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" - storetypes "github.com/cosmos/cosmos-sdk/store/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 848133cdce..a74dc78c84 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -12,8 +12,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) type msgServer struct { diff --git a/x/gov/migrations/v046/convert.go b/x/gov/migrations/v046/convert.go index edeb839acc..a3f383006b 100644 --- a/x/gov/migrations/v046/convert.go +++ b/x/gov/migrations/v046/convert.go @@ -6,8 +6,8 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) // ConvertToLegacyProposal takes a new proposal and attempts to convert it to the diff --git a/x/gov/types/v1/msgs_test.go b/x/gov/types/v1/msgs_test.go index 21d25bc206..ad53ac5bf4 100644 --- a/x/gov/types/v1/msgs_test.go +++ b/x/gov/types/v1/msgs_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) var ( diff --git a/x/gov/types/v1/proposals_test.go b/x/gov/types/v1/proposals_test.go index ab7ec4057d..1f808bdefb 100644 --- a/x/gov/types/v1/proposals_test.go +++ b/x/gov/types/v1/proposals_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ) func TestProposalStatus_Format(t *testing.T) { diff --git a/x/group/types.go b/x/group/types.go index 96863fede0..0d882cbe62 100644 --- a/x/group/types.go +++ b/x/group/types.go @@ -361,8 +361,8 @@ func (g GroupMember) ValidateBasic() error { // since it cannot be set as part of requests. func MemberToMemberRequest(m *Member) MemberRequest { return MemberRequest{ - Address: m.Address, - Weight: m.Weight, + Address: m.Address, + Weight: m.Weight, Metadata: m.Metadata, } } diff --git a/x/staking/module_test.go b/x/staking/module_test.go index 8784893634..3f1e5d9168 100644 --- a/x/staking/module_test.go +++ b/x/staking/module_test.go @@ -23,7 +23,7 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) require.NoError(t, err) - + app.InitChain( abcitypes.RequestInitChain{ AppStateBytes: stateBytes,