From e900fb1d7370fb7532b5b182845216f6d6036b55 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 1 Mar 2021 19:34:07 -0800 Subject: [PATCH 01/23] -added consensus version tracking to x/upgrade --- simapp/app.go | 6 +++- types/module/module.go | 12 ++++++++ x/upgrade/abci.go | 4 +++ x/upgrade/abci_test.go | 6 ++-- x/upgrade/keeper/grpc_query_test.go | 3 +- x/upgrade/keeper/keeper.go | 48 ++++++++++++++++++++++++++++- x/upgrade/keeper/keeper_test.go | 3 +- x/upgrade/module.go | 3 +- x/upgrade/module_test.go | 26 ++++++++++++++++ x/upgrade/types/handler.go | 3 +- x/upgrade/types/keys.go | 13 ++++++++ 11 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 x/upgrade/module_test.go diff --git a/simapp/app.go b/simapp/app.go index 4086585e684c..e43018e09807 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -374,6 +374,10 @@ func NewSimApp( authz.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), transferModule, ) + // give upgrade keeper the module manager + app.UpgradeKeeper.SetModuleManager(app.mm) + // pass the updated keeper to the module manager + app.mm.Modules[upgradetypes.ModuleName] = upgrade.NewAppModule(app.UpgradeKeeper) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the @@ -391,7 +395,7 @@ func NewSimApp( // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. app.mm.SetOrderInitGenesis( - capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, + upgradetypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authztypes.ModuleName, ibctransfertypes.ModuleName, feegranttypes.ModuleName, diff --git a/types/module/module.go b/types/module/module.go index 9123c9af7ec9..f6f597013b46 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -395,3 +395,15 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo Events: ctx.EventManager().ABCIEvents(), } } + +// GetConsensusVersions gets consensus version from all modules +func (m *Manager) GetConsensusVersions() MigrationMap { + migmap := make(map[string]uint64) + for _, v := range m.Modules { + version := v.ConsensusVersion() + name := v.Name() + migmap[name] = version + } + + return migmap +} diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index d346decb023c..e5a6ab2eb28b 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -73,3 +73,7 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { func BuildUpgradeNeededMsg(plan types.Plan) string { return fmt.Sprintf("UPGRADE \"%s\" NEEDED at %s: %s", plan.Name, plan.DueAt(), plan.Info) } + +func InitChainer(k keeper.Keeper, ctx sdk.Context) { + k.SetConsensusVersions(ctx) +} diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index 9eb0fc1a7ab9..e7ba99c0e409 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -128,7 +128,7 @@ func VerifyDoUpgrade(t *testing.T) { }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan) {}) + s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { return nil }) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -144,7 +144,7 @@ func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName strin }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan types.Plan) {}) + s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { return nil }) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -156,7 +156,7 @@ func TestHaltIfTooNew(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify that we don't panic with registered plan not in database at all") var called int - s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan types.Plan) { called++ }) + s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { called++; return nil }) newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now()) req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index d307157402de..a71f015d8721 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -110,7 +111,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan) suite.ctx = suite.ctx.WithBlockHeight(expHeight) - suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan) {}) + suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan) req = &types.QueryAppliedPlanRequest{Name: planName} diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index e366ae09198e..ff910521f558 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -16,6 +16,7 @@ import ( store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -28,6 +29,7 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler + ModuleManager *module.Manager } // NewKeeper constructs an upgrade Keeper @@ -48,6 +50,50 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } +func (k *Keeper) SetModuleManager(mm *module.Manager) *Keeper { + k.ModuleManager = mm + return k +} + +// SetConsensusVersions saves the consensus versions retrieved from module.Manager +func (k Keeper) SetConsensusVersions(ctx sdk.Context) { + modules := k.ModuleManager.GetConsensusVersions() + for modName, ver := range modules { + k.setConsensusVersion(ctx, ver, modName) + } +} + +// SetConsensusVersion sets the given module's consensus version to the given version +func (k Keeper) setConsensusVersion(ctx sdk.Context, version uint64, moduleName string) { + store := k.getConsensusVersionPrefixStore(ctx, moduleName) + versionBytes := make([]byte, 8) + binary.LittleEndian.PutUint64(versionBytes, version) + store.Set(types.MigrationMapKeyModule(moduleName), versionBytes) +} + +// getConsensusVersionStore gets the store of the given module name +func (k Keeper) getConsensusVersionPrefixStore(ctx sdk.Context, moduleName string) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.MigrationMapKeyModule(moduleName)) +} + +// GetConsensusVersions gets a MigrationMap from state +func (k Keeper) GetConsensusVersions(ctx sdk.Context) module.MigrationMap { + store := ctx.KVStore(k.storeKey) + it := sdk.KVStorePrefixIterator(store, []byte{types.MigrationMapByte}) + + migmap := make(map[string]uint64) + + defer it.Close() + for ; it.Valid(); it.Next() { + moduleName := string(it.Key()) + moduleVersion := binary.LittleEndian.Uint64(it.Value()) + migmap[moduleName] = moduleVersion + } + + return migmap +} + // ScheduleUpgrade schedules an upgrade based on the specified plan. // If there is another Plan already scheduled, it will overwrite it // (implicitly cancelling the current plan) @@ -191,7 +237,7 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { panic("ApplyUpgrade should never be called without first checking HasHandler") } - handler(ctx, plan) + handler(ctx, plan, k.GetConsensusVersions(ctx)) // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. // This will prevent resubmission of upgrade msg after upgrade is already completed. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 48f0301d3ff1..3809eb35229d 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" store "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/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -135,7 +136,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ types.Plan) {}) + s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ Name: "all-good", Info: "some text here", diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 23311c22d5f3..be5baec3d496 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -101,7 +101,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { + InitChainer(am.keeper, ctx) return []abci.ValidatorUpdate{} } diff --git a/x/upgrade/module_test.go b/x/upgrade/module_test.go new file mode 100644 index 000000000000..292fb0688b52 --- /dev/null +++ b/x/upgrade/module_test.go @@ -0,0 +1,26 @@ +package upgrade_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + abcitypes "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/simapp" +) + +func TestItSavesConsensusVersionToState(t *testing.T) { + app := simapp.Setup(false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{}) + + app.InitChain( + abcitypes.RequestInitChain{ + AppStateBytes: []byte("{}"), + ChainId: "test-chain-id", + }, + ) + + migmap := app.UpgradeKeeper.GetConsensusVersions(ctx) + require.NotEmpty(t, migmap) +} diff --git a/x/upgrade/types/handler.go b/x/upgrade/types/handler.go index 44e50cff112f..cc1cd78a495e 100644 --- a/x/upgrade/types/handler.go +++ b/x/upgrade/types/handler.go @@ -2,7 +2,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" ) // UpgradeHandler specifies the type of function that is called when an upgrade is applied -type UpgradeHandler func(ctx sdk.Context, plan Plan) +type UpgradeHandler func(ctx sdk.Context, plan Plan, migrationMap module.MigrationMap) error diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index 410f63597c6e..fdffe1ef891a 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -22,6 +22,9 @@ const ( // DoneByte is a prefix for to look up completed upgrade plan by name DoneByte = 0x1 + // MigrationMapByte is a prefix to look up module names (key) and versions (value) + MigrationMapByte = 0x2 + // KeyUpgradedIBCState is the key under which upgraded ibc state is stored in the upgrade store KeyUpgradedIBCState = "upgradedIBCState" @@ -51,3 +54,13 @@ func UpgradedClientKey(height int64) []byte { func UpgradedConsStateKey(height int64) []byte { return []byte(fmt.Sprintf("%s/%d/%s", KeyUpgradedIBCState, height, KeyUpgradedConsState)) } + +func MigrationMapKey() []byte { + return []byte{MigrationMapByte} +} + +func MigrationMapKeyModule(moduleName string) []byte { + nameBytes := []byte(moduleName) + key := append(MigrationMapKey(), nameBytes...) + return key +} From 036db4f5c1ae7c9709ff2373fa57cb1460d9f370 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Wed, 3 Mar 2021 10:31:45 -0800 Subject: [PATCH 02/23] -added interface to module manager -added e2e test for migrations using consensus version store in x/upgrade -cleaned up x/upgrade Keeper -handler in apply upgrade now handles errors and setting consensus versions -cleaned up migration map keys -removed init chainer method -simapp now implements GetConsensusVersions to assist with testing --- simapp/app.go | 7 ++++- types/module/module.go | 6 ++++- x/upgrade/abci.go | 4 --- x/upgrade/keeper/keeper.go | 45 +++++++++++++++------------------ x/upgrade/keeper/keeper_test.go | 31 ++++++++++++++++++++++- x/upgrade/module.go | 1 - x/upgrade/module_test.go | 6 ++--- x/upgrade/types/keys.go | 10 -------- 8 files changed, 63 insertions(+), 47 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index e43018e09807..58b800fee261 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -375,7 +375,7 @@ func NewSimApp( transferModule, ) // give upgrade keeper the module manager - app.UpgradeKeeper.SetModuleManager(app.mm) + app.UpgradeKeeper.SetVersionManager(app.mm) // pass the updated keeper to the module manager app.mm.Modules[upgradetypes.ModuleName] = upgrade.NewAppModule(app.UpgradeKeeper) @@ -631,6 +631,11 @@ func (app *SimApp) RunMigrations(ctx sdk.Context, migrateFromVersions module.Mig return app.mm.RunMigrations(ctx, app.configurator, migrateFromVersions) } +// Returns a map (MigrationMap) of key module name and value module consensus version +func (app *SimApp) GetConsensusVersions() module.MigrationMap { + return app.mm.GetConsensusVersions() +} + // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { statikFS, err := fs.New() diff --git a/types/module/module.go b/types/module/module.go index f6f597013b46..e821723b2677 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -337,6 +337,10 @@ type MigrationHandler func(sdk.Context) error // version from which we should perform the migration for each module. type MigrationMap map[string]uint64 +type VersionManager interface { + GetConsensusVersions() MigrationMap +} + // RunMigrations performs in-place store migrations for all modules. func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, migrateFromVersions MigrationMap) error { c, ok := cfg.(configurator) @@ -398,7 +402,7 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // GetConsensusVersions gets consensus version from all modules func (m *Manager) GetConsensusVersions() MigrationMap { - migmap := make(map[string]uint64) + migmap := make(MigrationMap) for _, v := range m.Modules { version := v.ConsensusVersion() name := v.Name() diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index e5a6ab2eb28b..d346decb023c 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -73,7 +73,3 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { func BuildUpgradeNeededMsg(plan types.Plan) string { return fmt.Sprintf("UPGRADE \"%s\" NEEDED at %s: %s", plan.Name, plan.DueAt(), plan.Info) } - -func InitChainer(k keeper.Keeper, ctx sdk.Context) { - k.SetConsensusVersions(ctx) -} diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index ff910521f558..8916b302f973 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -29,7 +29,7 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - ModuleManager *module.Manager + versionManager module.VersionManager } // NewKeeper constructs an upgrade Keeper @@ -50,45 +50,35 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } -func (k *Keeper) SetModuleManager(mm *module.Manager) *Keeper { - k.ModuleManager = mm - return k +func (k *Keeper) SetVersionManager(vm module.VersionManager) { + k.versionManager = vm } // SetConsensusVersions saves the consensus versions retrieved from module.Manager func (k Keeper) SetConsensusVersions(ctx sdk.Context) { - modules := k.ModuleManager.GetConsensusVersions() + modules := k.versionManager.GetConsensusVersions() + store := ctx.KVStore(k.storeKey) + migrationStore := prefix.NewStore(store, []byte{types.MigrationMapByte}) for modName, ver := range modules { - k.setConsensusVersion(ctx, ver, modName) + nameBytes := []byte(modName) + verBytes := make([]byte, 8) + binary.LittleEndian.PutUint64(verBytes, ver) + migrationStore.Set(nameBytes, verBytes) } } -// SetConsensusVersion sets the given module's consensus version to the given version -func (k Keeper) setConsensusVersion(ctx sdk.Context, version uint64, moduleName string) { - store := k.getConsensusVersionPrefixStore(ctx, moduleName) - versionBytes := make([]byte, 8) - binary.LittleEndian.PutUint64(versionBytes, version) - store.Set(types.MigrationMapKeyModule(moduleName), versionBytes) -} - -// getConsensusVersionStore gets the store of the given module name -func (k Keeper) getConsensusVersionPrefixStore(ctx sdk.Context, moduleName string) prefix.Store { - store := ctx.KVStore(k.storeKey) - return prefix.NewStore(store, types.MigrationMapKeyModule(moduleName)) -} - // GetConsensusVersions gets a MigrationMap from state func (k Keeper) GetConsensusVersions(ctx sdk.Context) module.MigrationMap { store := ctx.KVStore(k.storeKey) it := sdk.KVStorePrefixIterator(store, []byte{types.MigrationMapByte}) - migmap := make(map[string]uint64) - + migmap := make(module.MigrationMap) defer it.Close() for ; it.Valid(); it.Next() { - moduleName := string(it.Key()) + moduleBytes := it.Key() + name := string(moduleBytes[1:]) moduleVersion := binary.LittleEndian.Uint64(it.Value()) - migmap[moduleName] = moduleVersion + migmap[name] = moduleVersion } return migmap @@ -237,7 +227,12 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { panic("ApplyUpgrade should never be called without first checking HasHandler") } - handler(ctx, plan, k.GetConsensusVersions(ctx)) + err := handler(ctx, plan, k.GetConsensusVersions(ctx)) + if err != nil { + panic(err) + } + + k.SetConsensusVersions(ctx) // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. // This will prevent resubmission of upgrade msg after upgrade is already completed. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 3809eb35229d..bb7a080d8343 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( store "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/bank" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -153,7 +154,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { s.Run(tc.name, func() { // reset suite s.SetupTest() - + s.app.UpgradeKeeper.SetVersionManager(s.app) // setup test case tc.setup() @@ -212,6 +213,34 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { } +// Mock version manager for TestMigrations +type MockVersionManager struct{} + +func (m MockVersionManager) GetConsensusVersions() module.MigrationMap { + migmap := make(module.MigrationMap) + migmap["bank"] = 1 + return migmap +} + +// Tests that the underlying state of x/upgrade is set correctly after +// an upgrade. +func (s *KeeperTestSuite) TestMigrations() { + mockVM := MockVersionManager{} + s.app.UpgradeKeeper.SetVersionManager(mockVM) + s.app.UpgradeKeeper.SetConsensusVersions(s.ctx) + s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) + dummyPlan := types.Plan{ + Name: "dummy", + Info: "some text here", + Time: s.ctx.BlockTime().Add(time.Hour), + } + + s.app.UpgradeKeeper.SetVersionManager(s.app) + s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) + migmap := s.app.UpgradeKeeper.GetConsensusVersions(s.ctx) + s.Require().Equal(bank.AppModule{}.ConsensusVersion(), migmap["bank"]) +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index be5baec3d496..154f006784a7 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -102,7 +102,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis is ignored, no sense in serializing future upgrades func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { - InitChainer(am.keeper, ctx) return []abci.ValidatorUpdate{} } diff --git a/x/upgrade/module_test.go b/x/upgrade/module_test.go index 292fb0688b52..491bacc6da95 100644 --- a/x/upgrade/module_test.go +++ b/x/upgrade/module_test.go @@ -5,14 +5,12 @@ import ( "github.com/stretchr/testify/require" abcitypes "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/simapp" ) -func TestItSavesConsensusVersionToState(t *testing.T) { +func TestItGetsModuleVersions(t *testing.T) { app := simapp.Setup(false) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) app.InitChain( abcitypes.RequestInitChain{ @@ -21,6 +19,6 @@ func TestItSavesConsensusVersionToState(t *testing.T) { }, ) - migmap := app.UpgradeKeeper.GetConsensusVersions(ctx) + migmap := app.GetConsensusVersions() require.NotEmpty(t, migmap) } diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index fdffe1ef891a..593c8aeaa892 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -54,13 +54,3 @@ func UpgradedClientKey(height int64) []byte { func UpgradedConsStateKey(height int64) []byte { return []byte(fmt.Sprintf("%s/%d/%s", KeyUpgradedIBCState, height, KeyUpgradedConsState)) } - -func MigrationMapKey() []byte { - return []byte{MigrationMapByte} -} - -func MigrationMapKeyModule(moduleName string) []byte { - nameBytes := []byte(moduleName) - key := append(MigrationMapKey(), nameBytes...) - return key -} From efe28175d0a8b5a9bc7a546375fdb8d416231131 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 4 Mar 2021 08:03:55 -0800 Subject: [PATCH 03/23] protocol version p1 --- x/upgrade/keeper/keeper.go | 20 ++++++++++++++++++++ x/upgrade/types/keys.go | 3 +++ 2 files changed, 23 insertions(+) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 8916b302f973..bb7f1ca9371e 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -54,6 +54,22 @@ func (k *Keeper) SetVersionManager(vm module.VersionManager) { k.versionManager = vm } +func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { + pVersionStore := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.ProtocolVersionByte}) + versionBytes := make([]byte, 8) + binary.LittleEndian.PutUint64(versionBytes, v) + pVersionStore.Set([]byte("protocol"), versionBytes) +} + +// GetAppVersion gets the protocol version +func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { + pVersionStore := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.ProtocolVersionByte}) + pvBytes := pVersionStore.Get([]byte("protocol")) + protocolVersion := binary.LittleEndian.Uint64(pvBytes) + + return protocolVersion +} + // SetConsensusVersions saves the consensus versions retrieved from module.Manager func (k Keeper) SetConsensusVersions(ctx sdk.Context) { modules := k.versionManager.GetConsensusVersions() @@ -234,6 +250,10 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { k.SetConsensusVersions(ctx) + // increment the protocol version in state + currentProtocolVersion := k.GetProtocolVersion(ctx) + k.setProtocolVersion(ctx, currentProtocolVersion+1) + // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. // This will prevent resubmission of upgrade msg after upgrade is already completed. k.ClearIBCState(ctx, plan.Height) diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index 593c8aeaa892..3d88467e25e3 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -25,6 +25,9 @@ const ( // MigrationMapByte is a prefix to look up module names (key) and versions (value) MigrationMapByte = 0x2 + // ProtocolVersionByte is aprefix to look up Protocol Version + ProtocolVersionByte = 0x3 + // KeyUpgradedIBCState is the key under which upgraded ibc state is stored in the upgrade store KeyUpgradedIBCState = "upgradedIBCState" From 32316efa309f1df2b6c04d6d81afc5b2f6d61c46 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Wed, 10 Mar 2021 10:54:42 -0800 Subject: [PATCH 04/23] add protocol version to baseapp --- baseapp/abci.go | 2 ++ baseapp/baseapp.go | 7 +++++++ baseapp/options.go | 8 ++++++++ simapp/app.go | 2 +- x/upgrade/keeper/keeper.go | 23 ++++++++++++++++------- x/upgrade/keeper/keeper_test.go | 27 ++++++++++++++++++++++++++- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 36c36d1e118b..ef4cf9c86b41 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -109,6 +109,8 @@ func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { return abci.ResponseInfo{ Data: app.name, + Version: app.appVersion, + AppVersion: app.protocolVersion, LastBlockHeight: lastCommitID.Version, LastBlockAppHash: lastCommitID.Hash, } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index a79aed801b6f..0d2d0c8254b1 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -119,6 +119,9 @@ type BaseApp struct { // nolint: maligned // application's version string appVersion string + // application's protocol version that increments on every upgrade + protocolVersion uint64 + // recovery handler for app.runTx method runTxRecoveryMiddleware recoveryMiddleware @@ -175,6 +178,10 @@ func (app *BaseApp) AppVersion() string { return app.appVersion } +func (app *BaseApp) ProtocolVersion() uint64 { + return app.protocolVersion +} + // Logger returns the logger of the BaseApp. func (app *BaseApp) Logger() log.Logger { return app.logger diff --git a/baseapp/options.go b/baseapp/options.go index 33de1a3aa6e8..6da8851ba15f 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -104,6 +104,14 @@ func (app *BaseApp) SetAppVersion(v string) { app.appVersion = v } +type ProtocolManager interface { + SetProtocolVersion(uint64) +} + +func (app *BaseApp) SetProtocolVersion(v uint64) { + app.protocolVersion = v +} + func (app *BaseApp) SetDB(db dbm.DB) { if app.sealed { panic("SetDB() on sealed BaseApp") diff --git a/simapp/app.go b/simapp/app.go index 58b800fee261..52e1f6d47474 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -291,7 +291,7 @@ func NewSimApp( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegranttypes.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath) + app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp) // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index bb7f1ca9371e..2d0d731ce6d4 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -11,6 +11,7 @@ import ( "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" store "github.com/cosmos/cosmos-sdk/store/types" @@ -30,16 +31,18 @@ type Keeper struct { cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler versionManager module.VersionManager + protoManager baseapp.ProtocolManager } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm baseapp.ProtocolManager) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, upgradeHandlers: map[string]types.UpgradeHandler{}, + protoManager: pm, } } @@ -55,16 +58,20 @@ func (k *Keeper) SetVersionManager(vm module.VersionManager) { } func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { - pVersionStore := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.ProtocolVersionByte}) + store := ctx.KVStore(k.storeKey) versionBytes := make([]byte, 8) binary.LittleEndian.PutUint64(versionBytes, v) - pVersionStore.Set([]byte("protocol"), versionBytes) + store.Set([]byte{types.ProtocolVersionByte}, versionBytes) } // GetAppVersion gets the protocol version func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { - pVersionStore := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.ProtocolVersionByte}) - pvBytes := pVersionStore.Get([]byte("protocol")) + store := ctx.KVStore(k.storeKey) + ok := store.Has([]byte{types.ProtocolVersionByte}) + if !ok { + return 0 + } + pvBytes := store.Get([]byte{types.ProtocolVersionByte}) protocolVersion := binary.LittleEndian.Uint64(pvBytes) return protocolVersion @@ -250,9 +257,11 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { k.SetConsensusVersions(ctx) + nextProtoVersion := k.GetProtocolVersion(ctx) + 1 // increment the protocol version in state - currentProtocolVersion := k.GetProtocolVersion(ctx) - k.setProtocolVersion(ctx, currentProtocolVersion+1) + k.setProtocolVersion(ctx, nextProtoVersion) + + k.protoManager.SetProtocolVersion(nextProtoVersion) // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. // This will prevent resubmission of upgrade msg after upgrade is already completed. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index bb7a080d8343..882edb26e6db 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -29,7 +29,7 @@ func (s *KeeperTestSuite) SetupTest() { app := simapp.Setup(false) homeDir := filepath.Join(s.T().TempDir(), "x_upgrade_keeper_test") app.UpgradeKeeper = keeper.NewKeeper( // recreate keeper in order to use a custom home path - make(map[int64]bool), app.GetKey(types.StoreKey), app.AppCodec(), homeDir, + make(map[int64]bool), app.GetKey(types.StoreKey), app.AppCodec(), homeDir, app.BaseApp, ) s.T().Log("home dir:", homeDir) s.homeDir = homeDir @@ -241,6 +241,31 @@ func (s *KeeperTestSuite) TestMigrations() { s.Require().Equal(bank.AppModule{}.ConsensusVersion(), migmap["bank"]) } +func (s *KeeperTestSuite) TestProtocolVersion() { + mockVM := MockVersionManager{} + s.app.UpgradeKeeper.SetVersionManager(mockVM) + + pVersion := s.app.UpgradeKeeper.GetProtocolVersion(s.ctx) + s.Require().Equal(uint64(0), pVersion) + + s.app.UpgradeKeeper.SetConsensusVersions(s.ctx) + s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) + dummyPlan := types.Plan{ + Name: "dummy", + Info: "some text here", + Time: s.ctx.BlockTime().Add(time.Hour), + } + + s.app.UpgradeKeeper.SetVersionManager(s.app) + s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) + + nextVersion := s.app.UpgradeKeeper.GetProtocolVersion(s.ctx) + s.Require().Equal(pVersion+1, nextVersion) + + baseappVer := s.app.BaseApp.ProtocolVersion() + s.Require().Equal(nextVersion, baseappVer) +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } From 0fe4051ce787d400f16826419df31dd1ea7f6136 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 11 Mar 2021 13:41:21 -0800 Subject: [PATCH 05/23] rebase against master --- simapp/app.go | 11 +----- types/module/module.go | 16 -------- x/upgrade/abci_test.go | 6 +-- x/upgrade/keeper/grpc_query_test.go | 3 +- x/upgrade/keeper/keeper.go | 44 +-------------------- x/upgrade/keeper/keeper_test.go | 59 +---------------------------- x/upgrade/module.go | 2 +- x/upgrade/module_test.go | 24 ------------ x/upgrade/types/handler.go | 3 +- x/upgrade/types/keys.go | 3 -- 10 files changed, 10 insertions(+), 161 deletions(-) delete mode 100644 x/upgrade/module_test.go diff --git a/simapp/app.go b/simapp/app.go index 41f52f7fe460..133b7bfec524 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -315,10 +315,6 @@ func NewSimApp( params.NewAppModule(app.ParamsKeeper), authz.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ) - // give upgrade keeper the module manager - app.UpgradeKeeper.SetVersionManager(app.mm) - // pass the updated keeper to the module manager - app.mm.Modules[upgradetypes.ModuleName] = upgrade.NewAppModule(app.UpgradeKeeper) // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the @@ -336,7 +332,7 @@ func NewSimApp( // so that other modules that want to create or claim capabilities afterwards in InitChain // can do so safely. app.mm.SetOrderInitGenesis( - upgradetypes.ModuleName, capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, + capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authztypes.ModuleName, feegranttypes.ModuleName, @@ -552,11 +548,6 @@ func (app *SimApp) RunMigrations(ctx sdk.Context, migrateFromVersions module.Mig return app.mm.RunMigrations(ctx, app.configurator, migrateFromVersions) } -// Returns a map (MigrationMap) of key module name and value module consensus version -func (app *SimApp) GetConsensusVersions() module.MigrationMap { - return app.mm.GetConsensusVersions() -} - // RegisterSwaggerAPI registers swagger route with API Server func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) { statikFS, err := fs.New() diff --git a/types/module/module.go b/types/module/module.go index e821723b2677..9123c9af7ec9 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -337,10 +337,6 @@ type MigrationHandler func(sdk.Context) error // version from which we should perform the migration for each module. type MigrationMap map[string]uint64 -type VersionManager interface { - GetConsensusVersions() MigrationMap -} - // RunMigrations performs in-place store migrations for all modules. func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, migrateFromVersions MigrationMap) error { c, ok := cfg.(configurator) @@ -399,15 +395,3 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo Events: ctx.EventManager().ABCIEvents(), } } - -// GetConsensusVersions gets consensus version from all modules -func (m *Manager) GetConsensusVersions() MigrationMap { - migmap := make(MigrationMap) - for _, v := range m.Modules { - version := v.ConsensusVersion() - name := v.Name() - migmap[name] = version - } - - return migmap -} diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index e7ba99c0e409..9eb0fc1a7ab9 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -128,7 +128,7 @@ func VerifyDoUpgrade(t *testing.T) { }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { return nil }) + s.keeper.SetUpgradeHandler("test", func(ctx sdk.Context, plan types.Plan) {}) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -144,7 +144,7 @@ func VerifyDoUpgradeWithCtx(t *testing.T, newCtx sdk.Context, proposalName strin }) t.Log("Verify that the upgrade can be successfully applied with a handler") - s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { return nil }) + s.keeper.SetUpgradeHandler(proposalName, func(ctx sdk.Context, plan types.Plan) {}) require.NotPanics(t, func() { s.module.BeginBlock(newCtx, req) }) @@ -156,7 +156,7 @@ func TestHaltIfTooNew(t *testing.T) { s := setupTest(10, map[int64]bool{}) t.Log("Verify that we don't panic with registered plan not in database at all") var called int - s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan types.Plan, migrationMap module.MigrationMap) error { called++; return nil }) + s.keeper.SetUpgradeHandler("future", func(ctx sdk.Context, plan types.Plan) { called++ }) newCtx := s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1).WithBlockTime(time.Now()) req := abci.RequestBeginBlock{Header: newCtx.BlockHeader()} diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index a71f015d8721..d307157402de 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -111,7 +110,7 @@ func (suite *UpgradeTestSuite) TestAppliedCurrentPlan() { suite.app.UpgradeKeeper.ScheduleUpgrade(suite.ctx, plan) suite.ctx = suite.ctx.WithBlockHeight(expHeight) - suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) + suite.app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan) {}) suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, plan) req = &types.QueryAppliedPlanRequest{Name: planName} diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 2d0d731ce6d4..6a89f7bb1289 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -17,7 +17,6 @@ import ( store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -30,7 +29,6 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - versionManager module.VersionManager protoManager baseapp.ProtocolManager } @@ -53,10 +51,6 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } -func (k *Keeper) SetVersionManager(vm module.VersionManager) { - k.versionManager = vm -} - func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store := ctx.KVStore(k.storeKey) versionBytes := make([]byte, 8) @@ -77,36 +71,6 @@ func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { return protocolVersion } -// SetConsensusVersions saves the consensus versions retrieved from module.Manager -func (k Keeper) SetConsensusVersions(ctx sdk.Context) { - modules := k.versionManager.GetConsensusVersions() - store := ctx.KVStore(k.storeKey) - migrationStore := prefix.NewStore(store, []byte{types.MigrationMapByte}) - for modName, ver := range modules { - nameBytes := []byte(modName) - verBytes := make([]byte, 8) - binary.LittleEndian.PutUint64(verBytes, ver) - migrationStore.Set(nameBytes, verBytes) - } -} - -// GetConsensusVersions gets a MigrationMap from state -func (k Keeper) GetConsensusVersions(ctx sdk.Context) module.MigrationMap { - store := ctx.KVStore(k.storeKey) - it := sdk.KVStorePrefixIterator(store, []byte{types.MigrationMapByte}) - - migmap := make(module.MigrationMap) - defer it.Close() - for ; it.Valid(); it.Next() { - moduleBytes := it.Key() - name := string(moduleBytes[1:]) - moduleVersion := binary.LittleEndian.Uint64(it.Value()) - migmap[name] = moduleVersion - } - - return migmap -} - // ScheduleUpgrade schedules an upgrade based on the specified plan. // If there is another Plan already scheduled, it will overwrite it // (implicitly cancelling the current plan) @@ -250,17 +214,11 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { panic("ApplyUpgrade should never be called without first checking HasHandler") } - err := handler(ctx, plan, k.GetConsensusVersions(ctx)) - if err != nil { - panic(err) - } - - k.SetConsensusVersions(ctx) + handler(ctx, plan) nextProtoVersion := k.GetProtocolVersion(ctx) + 1 // increment the protocol version in state k.setProtocolVersion(ctx, nextProtoVersion) - k.protoManager.SetProtocolVersion(nextProtoVersion) // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 882edb26e6db..fab0e0760038 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -11,8 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" store "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/bank" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -137,7 +135,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { Height: 123450000, }, setup: func() { - s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) + s.app.UpgradeKeeper.SetUpgradeHandler("all-good", func(_ sdk.Context, _ types.Plan) {}) s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, types.Plan{ Name: "all-good", Info: "some text here", @@ -154,7 +152,7 @@ func (s *KeeperTestSuite) TestScheduleUpgrade() { s.Run(tc.name, func() { // reset suite s.SetupTest() - s.app.UpgradeKeeper.SetVersionManager(s.app) + // setup test case tc.setup() @@ -213,59 +211,6 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { } -// Mock version manager for TestMigrations -type MockVersionManager struct{} - -func (m MockVersionManager) GetConsensusVersions() module.MigrationMap { - migmap := make(module.MigrationMap) - migmap["bank"] = 1 - return migmap -} - -// Tests that the underlying state of x/upgrade is set correctly after -// an upgrade. -func (s *KeeperTestSuite) TestMigrations() { - mockVM := MockVersionManager{} - s.app.UpgradeKeeper.SetVersionManager(mockVM) - s.app.UpgradeKeeper.SetConsensusVersions(s.ctx) - s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) - dummyPlan := types.Plan{ - Name: "dummy", - Info: "some text here", - Time: s.ctx.BlockTime().Add(time.Hour), - } - - s.app.UpgradeKeeper.SetVersionManager(s.app) - s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) - migmap := s.app.UpgradeKeeper.GetConsensusVersions(s.ctx) - s.Require().Equal(bank.AppModule{}.ConsensusVersion(), migmap["bank"]) -} - -func (s *KeeperTestSuite) TestProtocolVersion() { - mockVM := MockVersionManager{} - s.app.UpgradeKeeper.SetVersionManager(mockVM) - - pVersion := s.app.UpgradeKeeper.GetProtocolVersion(s.ctx) - s.Require().Equal(uint64(0), pVersion) - - s.app.UpgradeKeeper.SetConsensusVersions(s.ctx) - s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan, _ module.MigrationMap) error { return nil }) - dummyPlan := types.Plan{ - Name: "dummy", - Info: "some text here", - Time: s.ctx.BlockTime().Add(time.Hour), - } - - s.app.UpgradeKeeper.SetVersionManager(s.app) - s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) - - nextVersion := s.app.UpgradeKeeper.GetProtocolVersion(s.ctx) - s.Require().Equal(pVersion+1, nextVersion) - - baseappVer := s.app.BaseApp.ProtocolVersion() - s.Require().Equal(nextVersion, baseappVer) -} - func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 154f006784a7..23311c22d5f3 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -101,7 +101,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } diff --git a/x/upgrade/module_test.go b/x/upgrade/module_test.go deleted file mode 100644 index 491bacc6da95..000000000000 --- a/x/upgrade/module_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package upgrade_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - abcitypes "github.com/tendermint/tendermint/abci/types" - - "github.com/cosmos/cosmos-sdk/simapp" -) - -func TestItGetsModuleVersions(t *testing.T) { - app := simapp.Setup(false) - - app.InitChain( - abcitypes.RequestInitChain{ - AppStateBytes: []byte("{}"), - ChainId: "test-chain-id", - }, - ) - - migmap := app.GetConsensusVersions() - require.NotEmpty(t, migmap) -} diff --git a/x/upgrade/types/handler.go b/x/upgrade/types/handler.go index cc1cd78a495e..44e50cff112f 100644 --- a/x/upgrade/types/handler.go +++ b/x/upgrade/types/handler.go @@ -2,8 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" ) // UpgradeHandler specifies the type of function that is called when an upgrade is applied -type UpgradeHandler func(ctx sdk.Context, plan Plan, migrationMap module.MigrationMap) error +type UpgradeHandler func(ctx sdk.Context, plan Plan) diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index 3d88467e25e3..bad2369f67ed 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -22,9 +22,6 @@ const ( // DoneByte is a prefix for to look up completed upgrade plan by name DoneByte = 0x1 - // MigrationMapByte is a prefix to look up module names (key) and versions (value) - MigrationMapByte = 0x2 - // ProtocolVersionByte is aprefix to look up Protocol Version ProtocolVersionByte = 0x3 From a6eae2a6782664449c14a7dd0ede0dd1cef65e24 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:14:27 -0800 Subject: [PATCH 06/23] add test --- x/upgrade/keeper/keeper_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index fab0e0760038..119646aaf400 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -211,6 +211,20 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { } +func (s *KeeperTestSuite) TestIncrementProtocolVersion() { + currentProtocolVersion := s.app.BaseApp.ProtocolVersion() + s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan) {}) + dummyPlan := types.Plan{ + Name: "dummy", + Info: "some text here", + Time: s.ctx.BlockTime().Add(time.Hour), + } + s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) + upgradedProtocolVersion := s.app.BaseApp.ProtocolVersion() + + s.Require().Equal(currentProtocolVersion+1, upgradedProtocolVersion) +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } From fb696bc51877a369d7735c5a495a5c42199d811a Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 11 Mar 2021 14:54:08 -0800 Subject: [PATCH 07/23] added test case --- baseapp/baseapp_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index b0eace4d3294..a488bd6c2e82 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -498,7 +498,7 @@ func TestInfo(t *testing.T) { assert.Equal(t, t.Name(), res.GetData()) assert.Equal(t, int64(0), res.LastBlockHeight) require.Equal(t, []uint8(nil), res.LastBlockAppHash) - + require.Equal(t, app.ProtocolVersion(), res.AppVersion) // ----- test a proper response ------- // TODO } From 128926d6c986e07db52176b2ac252a90f95c1aad Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 16 Mar 2021 12:43:47 -0700 Subject: [PATCH 08/23] cleanup --- x/upgrade/keeper/keeper.go | 18 ++++++++++-------- x/upgrade/keeper/keeper_test.go | 6 +++--- x/upgrade/types/keys.go | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 7c5ce6913f68..75ea025c5c21 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -51,6 +51,7 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } +// setProtocolVersion sets the protocol version to state func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store := ctx.KVStore(k.storeKey) versionBytes := make([]byte, 8) @@ -58,17 +59,18 @@ func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store.Set([]byte{types.ProtocolVersionByte}, versionBytes) } -// GetAppVersion gets the protocol version +// GetAppVersion gets the protocol version from state func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) ok := store.Has([]byte{types.ProtocolVersionByte}) - if !ok { - return 0 - } - pvBytes := store.Get([]byte{types.ProtocolVersionByte}) - protocolVersion := binary.LittleEndian.Uint64(pvBytes) + if ok { + pvBytes := store.Get([]byte{types.ProtocolVersionByte}) + protocolVersion := binary.LittleEndian.Uint64(pvBytes) - return protocolVersion + return protocolVersion + } + // default value + return 0 } // ScheduleUpgrade schedules an upgrade based on the specified plan. @@ -212,8 +214,8 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { handler(ctx, plan) + // incremement the protocol version and set it in state and baseapp nextProtoVersion := k.GetProtocolVersion(ctx) + 1 - // increment the protocol version in state k.setProtocolVersion(ctx, nextProtoVersion) k.protoManager.SetProtocolVersion(nextProtoVersion) diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index b17763eb87ba..032abbcac814 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -195,9 +195,9 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { currentProtocolVersion := s.app.BaseApp.ProtocolVersion() s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan) {}) dummyPlan := types.Plan{ - Name: "dummy", - Info: "some text here", - Time: s.ctx.BlockTime().Add(time.Hour), + Name: "dummy", + Info: "some text here", + Height: 100, } s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) upgradedProtocolVersion := s.app.BaseApp.ProtocolVersion() diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index bad2369f67ed..2a3623b4582e 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -22,7 +22,7 @@ const ( // DoneByte is a prefix for to look up completed upgrade plan by name DoneByte = 0x1 - // ProtocolVersionByte is aprefix to look up Protocol Version + // ProtocolVersionByte is a prefix to look up Protocol Version ProtocolVersionByte = 0x3 // KeyUpgradedIBCState is the key under which upgraded ibc state is stored in the upgrade store From 35a424e70fe228201f8f061d85644e9912a197e5 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 16 Mar 2021 13:10:55 -0700 Subject: [PATCH 09/23] docs and change to bigendian --- x/upgrade/keeper/keeper.go | 4 ++-- x/upgrade/spec/02_state.md | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 75ea025c5c21..b36be2a3d1f0 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -55,7 +55,7 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store := ctx.KVStore(k.storeKey) versionBytes := make([]byte, 8) - binary.LittleEndian.PutUint64(versionBytes, v) + binary.BigEndian.PutUint64(versionBytes, v) store.Set([]byte{types.ProtocolVersionByte}, versionBytes) } @@ -65,7 +65,7 @@ func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { ok := store.Has([]byte{types.ProtocolVersionByte}) if ok { pvBytes := store.Get([]byte{types.ProtocolVersionByte}) - protocolVersion := binary.LittleEndian.Uint64(pvBytes) + protocolVersion := binary.BigEndian.Uint64(pvBytes) return protocolVersion } diff --git a/x/upgrade/spec/02_state.md b/x/upgrade/spec/02_state.md index f069b4f96797..d4013962784b 100644 --- a/x/upgrade/spec/02_state.md +++ b/x/upgrade/spec/02_state.md @@ -5,7 +5,12 @@ order: 2 # State The internal state of the `x/upgrade` module is relatively minimal and simple. The -state only contains the currently active upgrade `Plan` (if one exists) by key -`0x0` and if a `Plan` is marked as "done" by key `0x1`. +state contains the currently active upgrade `Plan` (if one exists) by key +`0x0` and if a `Plan` is marked as "done" by key `0x1`. The state maintains a +`Protocol Version` which can be accessed by key `0x3`. + +- Plan: `0x0 -> Plan` +- Done: `0x1 | byte(plan name) -> BigEndian(Block Height)` +- ProtocolVersion: `0x3 -> BigEndian(Protocol Version)` The `x/upgrade` module contains no genesis state. From 16b92fb398ac21900f73dc0cbba8ccbf6db454be Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 16 Mar 2021 13:47:57 -0700 Subject: [PATCH 10/23] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae7ce9a177fa..fefe76adb507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added. * (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking * (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error. +* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolManager` which implements setting a protocol version on baseapp. ### State Machine Breaking From 4039b349e45f3834c183a515ab40cdb79b1d21b8 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 19 Mar 2021 08:20:52 -0700 Subject: [PATCH 11/23] cleanup keeper --- x/upgrade/keeper/keeper.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index b36be2a3d1f0..f7e54c239c90 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -11,7 +11,6 @@ import ( "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" store "github.com/cosmos/cosmos-sdk/store/types" @@ -29,11 +28,11 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - protoManager baseapp.ProtocolManager + protoManager ProtocolManager // Implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm baseapp.ProtocolManager) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolManager) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, @@ -51,6 +50,12 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } +// ProtocolManager defines the interface fulfilled by BaseApp +// which allows setting it's protocol version field. +type ProtocolManager interface { + SetProtocolVersion(uint64) +} + // setProtocolVersion sets the protocol version to state func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store := ctx.KVStore(k.storeKey) @@ -217,7 +222,10 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { // incremement the protocol version and set it in state and baseapp nextProtoVersion := k.GetProtocolVersion(ctx) + 1 k.setProtocolVersion(ctx, nextProtoVersion) - k.protoManager.SetProtocolVersion(nextProtoVersion) + if k.protoManager != nil { + // set protocol version field on BaseApp + k.protoManager.SetProtocolVersion(nextProtoVersion) + } // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. // This will prevent resubmission of upgrade msg after upgrade is already completed. From cb4c0f4e18003b18f275aa703a1ba19aa9ffc155 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 19 Mar 2021 23:34:56 -0700 Subject: [PATCH 12/23] swap appVersion and version --- CHANGELOG.md | 3 ++- baseapp/abci.go | 6 +++--- baseapp/baseapp.go | 14 ++++++++------ baseapp/baseapp_test.go | 12 ++++++------ baseapp/options.go | 16 +++++++++------- simapp/app.go | 2 +- x/upgrade/keeper/keeper.go | 22 +++++++++++----------- x/upgrade/keeper/keeper_test.go | 6 +++--- 8 files changed, 43 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fefe76adb507..16753a2aefa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added. * (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking * (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error. -* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolManager` which implements setting a protocol version on baseapp. +* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolVersionManager` which implements setting a protocol version on baseapp. +* (BaseApp) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) BaseApp's fields appVersion and version were swapped to match Tendermint's fields. ### State Machine Breaking diff --git a/baseapp/abci.go b/baseapp/abci.go index ef4cf9c86b41..f7ecb16e6f46 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -109,8 +109,8 @@ func (app *BaseApp) Info(req abci.RequestInfo) abci.ResponseInfo { return abci.ResponseInfo{ Data: app.name, - Version: app.appVersion, - AppVersion: app.protocolVersion, + Version: app.version, + AppVersion: app.appVersion, LastBlockHeight: lastCommitID.Version, LastBlockAppHash: lastCommitID.Hash, } @@ -757,7 +757,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res return abci.ResponseQuery{ Codespace: sdkerrors.RootCodespace, Height: req.Height, - Value: []byte(app.appVersion), + Value: []byte(app.version), } default: diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 0d2d0c8254b1..5ec243ba91b8 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -117,10 +117,11 @@ type BaseApp struct { // nolint: maligned minRetainBlocks uint64 // application's version string - appVersion string + version string // application's protocol version that increments on every upgrade - protocolVersion uint64 + // if BaseApp is passed to the upgrade keeper's NewKeeper method. + appVersion uint64 // recovery handler for app.runTx method runTxRecoveryMiddleware recoveryMiddleware @@ -173,13 +174,14 @@ func (app *BaseApp) Name() string { return app.name } -// AppVersion returns the application's version string. -func (app *BaseApp) AppVersion() string { +// AppVersion returns the application's protocol version. +func (app *BaseApp) AppVersion() uint64 { return app.appVersion } -func (app *BaseApp) ProtocolVersion() uint64 { - return app.protocolVersion +// Version returns the application's version string. +func (app *BaseApp) Version() string { + return app.version } // Logger returns the logger of the BaseApp. diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index a488bd6c2e82..add6b982a3cd 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -340,21 +340,21 @@ func TestSetLoader(t *testing.T) { } } -func TestAppVersionSetterGetter(t *testing.T) { +func TestVersionSetterGetter(t *testing.T) { logger := defaultLogger() pruningOpt := SetPruning(store.PruneDefault) db := dbm.NewMemDB() name := t.Name() app := NewBaseApp(name, logger, db, nil, pruningOpt) - require.Equal(t, "", app.AppVersion()) + require.Equal(t, "", app.Version()) res := app.Query(abci.RequestQuery{Path: "app/version"}) require.True(t, res.IsOK()) require.Equal(t, "", string(res.Value)) versionString := "1.0.0" - app.SetAppVersion(versionString) - require.Equal(t, versionString, app.AppVersion()) + app.SetVersion(versionString) + require.Equal(t, versionString, app.Version()) res = app.Query(abci.RequestQuery{Path: "app/version"}) require.True(t, res.IsOK()) require.Equal(t, versionString, string(res.Value)) @@ -498,7 +498,7 @@ func TestInfo(t *testing.T) { assert.Equal(t, t.Name(), res.GetData()) assert.Equal(t, int64(0), res.LastBlockHeight) require.Equal(t, []uint8(nil), res.LastBlockAppHash) - require.Equal(t, app.ProtocolVersion(), res.AppVersion) + require.Equal(t, app.AppVersion(), res.AppVersion) // ----- test a proper response ------- // TODO } @@ -510,7 +510,7 @@ func TestBaseAppOptionSeal(t *testing.T) { app.SetName("") }) require.Panics(t, func() { - app.SetAppVersion("") + app.SetVersion("") }) require.Panics(t, func() { app.SetDB(nil) diff --git a/baseapp/options.go b/baseapp/options.go index 6da8851ba15f..467bf66e7c9e 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -95,21 +95,23 @@ func (app *BaseApp) SetParamStore(ps ParamStore) { app.paramStore = ps } -// SetAppVersion sets the application's version string. -func (app *BaseApp) SetAppVersion(v string) { +// SetVersion sets the application's version string. +func (app *BaseApp) SetVersion(v string) { if app.sealed { - panic("SetAppVersion() on sealed BaseApp") + panic("SetVersion() on sealed BaseApp") } - - app.appVersion = v + app.version = v } -type ProtocolManager interface { +// ProtocolVersionManager exposes functionality to set +// BaseApp's protocol version. +type ProtocolVersionManager interface { SetProtocolVersion(uint64) } +// SetProtocolVersion sets the application's protocol version func (app *BaseApp) SetProtocolVersion(v uint64) { - app.protocolVersion = v + app.appVersion = v } func (app *BaseApp) SetDB(db dbm.DB) { diff --git a/simapp/app.go b/simapp/app.go index 133b7bfec524..566a523557dc 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -201,7 +201,7 @@ func NewSimApp( bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) - bApp.SetAppVersion(version.Version) + bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) keys := sdk.NewKVStoreKeys( diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index f7e54c239c90..9bece1c08044 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -28,18 +28,18 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - protoManager ProtocolManager // Implements setting the protocol version field on BaseApp + protocolManager ProtocolVersionManager // Implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolManager) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolVersionManager) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, upgradeHandlers: map[string]types.UpgradeHandler{}, - protoManager: pm, + protocolManager: pm, } } @@ -50,9 +50,9 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } -// ProtocolManager defines the interface fulfilled by BaseApp -// which allows setting it's protocol version field. -type ProtocolManager interface { +// ProtocolVersionManager defines the interface fulfilled by BaseApp +// which allows setting it's appVersion field. +type ProtocolVersionManager interface { SetProtocolVersion(uint64) } @@ -65,7 +65,7 @@ func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { } // GetAppVersion gets the protocol version from state -func (k Keeper) GetProtocolVersion(ctx sdk.Context) uint64 { +func (k Keeper) getProtocolVersion(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) ok := store.Has([]byte{types.ProtocolVersionByte}) if ok { @@ -220,11 +220,11 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { handler(ctx, plan) // incremement the protocol version and set it in state and baseapp - nextProtoVersion := k.GetProtocolVersion(ctx) + 1 + nextProtoVersion := k.getProtocolVersion(ctx) + 1 k.setProtocolVersion(ctx, nextProtoVersion) - if k.protoManager != nil { - // set protocol version field on BaseApp - k.protoManager.SetProtocolVersion(nextProtoVersion) + if k.protocolManager != nil { + // set protocol version on BaseApp + k.protocolManager.SetProtocolVersion(nextProtoVersion) } // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 032abbcac814..9ad571a09d3f 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -192,7 +192,7 @@ func (s *KeeperTestSuite) TestSetUpgradedClient() { } func (s *KeeperTestSuite) TestIncrementProtocolVersion() { - currentProtocolVersion := s.app.BaseApp.ProtocolVersion() + oldProtocolVersion := s.app.BaseApp.AppVersion() s.app.UpgradeKeeper.SetUpgradeHandler("dummy", func(_ sdk.Context, _ types.Plan) {}) dummyPlan := types.Plan{ Name: "dummy", @@ -200,9 +200,9 @@ func (s *KeeperTestSuite) TestIncrementProtocolVersion() { Height: 100, } s.app.UpgradeKeeper.ApplyUpgrade(s.ctx, dummyPlan) - upgradedProtocolVersion := s.app.BaseApp.ProtocolVersion() + upgradedProtocolVersion := s.app.BaseApp.AppVersion() - s.Require().Equal(currentProtocolVersion+1, upgradedProtocolVersion) + s.Require().Equal(oldProtocolVersion+1, upgradedProtocolVersion) } func TestKeeperTestSuite(t *testing.T) { From 21af48c3ce5a7d865a3479eb917737ab39af4c58 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Fri, 19 Mar 2021 23:51:54 -0700 Subject: [PATCH 13/23] cleanup --- CHANGELOG.md | 2 +- x/upgrade/keeper/keeper.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de6d467b0ea2..e25ef16b180c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionMap` which helps facilitate in-place migrations. * (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error. * (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolVersionManager` which implements setting a protocol version on baseapp. -* (BaseApp) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) BaseApp's fields appVersion and version were swapped to match Tendermint's fields. +* (baseapp) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) BaseApp's fields appVersion and version were swapped to match Tendermint's fields. ### State Machine Breaking diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 30a88b037908..98a894bfcf77 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -259,11 +259,11 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { k.SetModuleVersionMap(ctx, updatedVM) // incremement the protocol version and set it in state and baseapp - nextProtoVersion := k.getProtocolVersion(ctx) + 1 - k.setProtocolVersion(ctx, nextProtoVersion) + nextProtocolVersion := k.getProtocolVersion(ctx) + 1 + k.setProtocolVersion(ctx, nextProtocolVersion) if k.protocolManager != nil { // set protocol version on BaseApp - k.protocolManager.SetProtocolVersion(nextProtoVersion) + k.protocolManager.SetProtocolVersion(nextProtocolVersion) } // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. From ad4fceb0f1f17f44397eae2a2619a5f3c84f453f Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 22 Mar 2021 13:55:14 -0700 Subject: [PATCH 14/23] change interface id --- CHANGELOG.md | 2 +- baseapp/options.go | 4 ++-- x/upgrade/keeper/keeper.go | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ae29277e3a..6f8f633deade 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking * (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionMap` which helps facilitate in-place migrations. * (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error. -* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolVersionManager` which implements setting a protocol version on baseapp. +* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolVersionSetter` which implements setting a protocol version on baseapp. * (baseapp) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) BaseApp's fields appVersion and version were swapped to match Tendermint's fields. diff --git a/baseapp/options.go b/baseapp/options.go index 467bf66e7c9e..8a86c6d1b412 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -103,9 +103,9 @@ func (app *BaseApp) SetVersion(v string) { app.version = v } -// ProtocolVersionManager exposes functionality to set +// ProtocolVersionSetter exposes functionality to set // BaseApp's protocol version. -type ProtocolVersionManager interface { +type ProtocolVersionSetter interface { SetProtocolVersion(uint64) } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 98a894bfcf77..72a633958f0b 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -29,18 +29,18 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - protocolManager ProtocolVersionManager // Implements setting the protocol version field on BaseApp + protocolSetter ProtocolVersionSetter // Implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolVersionManager) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, upgradeHandlers: map[string]types.UpgradeHandler{}, - protocolManager: pm, + protocolSetter: pm, } } @@ -51,9 +51,9 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } -// ProtocolVersionManager defines the interface fulfilled by BaseApp +// ProtocolVersionSetter defines the interface fulfilled by BaseApp // which allows setting it's appVersion field. -type ProtocolVersionManager interface { +type ProtocolVersionSetter interface { SetProtocolVersion(uint64) } @@ -261,9 +261,9 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { // incremement the protocol version and set it in state and baseapp nextProtocolVersion := k.getProtocolVersion(ctx) + 1 k.setProtocolVersion(ctx, nextProtocolVersion) - if k.protocolManager != nil { + if k.protocolSetter != nil { // set protocol version on BaseApp - k.protocolManager.SetProtocolVersion(nextProtocolVersion) + k.protocolSetter.SetProtocolVersion(nextProtocolVersion) } // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. From 6e3da1c1d30f863faf501a24567fddcef55643d2 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 23 Mar 2021 12:38:08 -0700 Subject: [PATCH 15/23] update keeper field name to versionSetter --- CHANGELOG.md | 2 +- x/upgrade/keeper/keeper.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd1c3871b5ff..6735e1f45381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,7 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking * (x/upgrade) [\#8743](https://github.com/cosmos/cosmos-sdk/pull/8743) `UpgradeHandler` includes a new argument `VersionMap` which helps facilitate in-place migrations. * (x/auth) [\#8129](https://github.com/cosmos/cosmos-sdk/pull/8828) Updated `SigVerifiableTx.GetPubKeys` method signature to return error. -* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `AppVersionSetter` which implements setting a protocol version on baseapp. +* (x/upgrade) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) Upgrade `Keeper` takes new argument `ProtocolVersionSetter` which implements setting a protocol version on baseapp. * (baseapp) [\7487](https://github.com/cosmos/cosmos-sdk/pull/8897) BaseApp's fields appVersion and version were swapped to match Tendermint's fields. * [\#8682](https://github.com/cosmos/cosmos-sdk/pull/8682) `ante.NewAnteHandler` updated to receive all positional params as `ante.HandlerOptions` struct. If required fields aren't set, throws error accordingly. diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 72a633958f0b..5165adfc63dc 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -29,18 +29,18 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - protocolSetter ProtocolVersionSetter // Implements setting the protocol version field on BaseApp + versionSetter ProtocolVersionSetter // Implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, pm ProtocolVersionSetter) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, upgradeHandlers: map[string]types.UpgradeHandler{}, - protocolSetter: pm, + versionSetter: vs, } } @@ -261,9 +261,9 @@ func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { // incremement the protocol version and set it in state and baseapp nextProtocolVersion := k.getProtocolVersion(ctx) + 1 k.setProtocolVersion(ctx, nextProtocolVersion) - if k.protocolSetter != nil { + if k.versionSetter != nil { // set protocol version on BaseApp - k.protocolSetter.SetProtocolVersion(nextProtocolVersion) + k.versionSetter.SetProtocolVersion(nextProtocolVersion) } // Must clear IBC state after upgrade is applied as it is stored separately from the upgrade plan. From 26ac281b08b637f00659f6f6a98d74d624d2f14b Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 23 Mar 2021 12:52:34 -0700 Subject: [PATCH 16/23] reorder keys and docs --- x/upgrade/spec/02_state.md | 8 ++++---- x/upgrade/types/keys.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x/upgrade/spec/02_state.md b/x/upgrade/spec/02_state.md index 698e0d40e0ba..76391fa71316 100644 --- a/x/upgrade/spec/02_state.md +++ b/x/upgrade/spec/02_state.md @@ -6,15 +6,15 @@ order: 2 The internal state of the `x/upgrade` module is relatively minimal and simple. The state contains the currently active upgrade `Plan` (if one exists) by key -`0x0` and if a `Plan` is marked as "done" by key `0x1`. The state maintains a -`Protocol Version` which can be accessed by key `0x3`. Additionally, the state +`0x0` and if a `Plan` is marked as "done" by key `0x1`. The state contains the consensus versions of all app modules in the application. The versions are stored as big endian `uint64`, and can be accessed with prefix `0x2` appended -by the corresponding module name of type `string`. +by the corresponding module name of type `string`. The state maintains a +`Protocol Version` which can be accessed by key `0x3`. - Plan: `0x0 -> Plan` - Done: `0x1 | byte(plan name) -> BigEndian(Block Height)` -- ProtocolVersion: `0x3 -> BigEndian(Protocol Version)` - ConsensusVersion: `0x2 | byte(module name) -> BigEndian(Module Consensus Version)` +- ProtocolVersion: `0x3 -> BigEndian(Protocol Version)` The `x/upgrade` module contains no genesis state. diff --git a/x/upgrade/types/keys.go b/x/upgrade/types/keys.go index 4d8c2456f82e..45128fc70495 100644 --- a/x/upgrade/types/keys.go +++ b/x/upgrade/types/keys.go @@ -22,12 +22,12 @@ const ( // DoneByte is a prefix for to look up completed upgrade plan by name DoneByte = 0x1 - // ProtocolVersionByte is a prefix to look up Protocol Version - ProtocolVersionByte = 0x3 - // VersionMapByte is a prefix to look up module names (key) and versions (value) VersionMapByte = 0x2 + // ProtocolVersionByte is a prefix to look up Protocol Version + ProtocolVersionByte = 0x3 + // KeyUpgradedIBCState is the key under which upgraded ibc state is stored in the upgrade store KeyUpgradedIBCState = "upgradedIBCState" From 71a4dfafcfae7ca34dc94ce2feed266dbe6da009 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 25 Mar 2021 12:04:10 -0700 Subject: [PATCH 17/23] -move interface into exported folder --- baseapp/options.go | 6 ------ x/upgrade/exported/exported.go | 7 +++++++ x/upgrade/keeper/keeper.go | 16 +++++----------- 3 files changed, 12 insertions(+), 17 deletions(-) create mode 100644 x/upgrade/exported/exported.go diff --git a/baseapp/options.go b/baseapp/options.go index 8a86c6d1b412..be9fbdc659a0 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -103,12 +103,6 @@ func (app *BaseApp) SetVersion(v string) { app.version = v } -// ProtocolVersionSetter exposes functionality to set -// BaseApp's protocol version. -type ProtocolVersionSetter interface { - SetProtocolVersion(uint64) -} - // SetProtocolVersion sets the application's protocol version func (app *BaseApp) SetProtocolVersion(v uint64) { app.appVersion = v diff --git a/x/upgrade/exported/exported.go b/x/upgrade/exported/exported.go new file mode 100644 index 000000000000..859f7fe1f011 --- /dev/null +++ b/x/upgrade/exported/exported.go @@ -0,0 +1,7 @@ +package exported + +// ProtocolVersionSetter defines the interface fulfilled by BaseApp +// which allows setting it's appVersion field. +type ProtocolVersionSetter interface { + SetProtocolVersion(uint64) +} diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 5165adfc63dc..252b525a7082 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -8,16 +8,16 @@ import ( "path" "path/filepath" - "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/module" + xp "github.com/cosmos/cosmos-sdk/x/upgrade/exported" "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/tendermint/tendermint/libs/log" + tmos "github.com/tendermint/tendermint/libs/os" ) // UpgradeInfoFileName file to store upgrade information @@ -29,11 +29,11 @@ type Keeper struct { storeKey sdk.StoreKey cdc codec.BinaryMarshaler upgradeHandlers map[string]types.UpgradeHandler - versionSetter ProtocolVersionSetter // Implements setting the protocol version field on BaseApp + versionSetter xp.ProtocolVersionSetter // Implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs ProtocolVersionSetter) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs xp.ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, @@ -51,12 +51,6 @@ func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandl k.upgradeHandlers[name] = upgradeHandler } -// ProtocolVersionSetter defines the interface fulfilled by BaseApp -// which allows setting it's appVersion field. -type ProtocolVersionSetter interface { - SetProtocolVersion(uint64) -} - // setProtocolVersion sets the protocol version to state func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store := ctx.KVStore(k.storeKey) From 31a1f12bf9b026cfc85df0ff54fded76bcaf6221 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 25 Mar 2021 12:10:18 -0700 Subject: [PATCH 18/23] typo --- x/upgrade/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 252b525a7082..bb466d0845b8 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -59,7 +59,7 @@ func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store.Set([]byte{types.ProtocolVersionByte}, versionBytes) } -// GetAppVersion gets the protocol version from state +// getAppVersion gets the protocol version from state func (k Keeper) getProtocolVersion(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) ok := store.Has([]byte{types.ProtocolVersionByte}) From d20bfc10c1bdf4303db0756c886cda45f9665789 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 25 Mar 2021 12:10:46 -0700 Subject: [PATCH 19/23] typo2 --- x/upgrade/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index bb466d0845b8..6b811ee0115b 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -59,7 +59,7 @@ func (k Keeper) setProtocolVersion(ctx sdk.Context, v uint64) { store.Set([]byte{types.ProtocolVersionByte}, versionBytes) } -// getAppVersion gets the protocol version from state +// getProtocolVersion gets the protocol version from state func (k Keeper) getProtocolVersion(ctx sdk.Context) uint64 { store := ctx.KVStore(k.storeKey) ok := store.Has([]byte{types.ProtocolVersionByte}) From 1df5a51989b4cbc17443418ea464f5adc3505f2e Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Mon, 29 Mar 2021 09:40:26 -0700 Subject: [PATCH 20/23] docs on keeper fields --- x/upgrade/keeper/keeper.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 6b811ee0115b..db64fde469a7 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -24,12 +24,12 @@ import ( const UpgradeInfoFileName string = "upgrade-info.json" type Keeper struct { - homePath string - skipUpgradeHeights map[int64]bool - storeKey sdk.StoreKey - cdc codec.BinaryMarshaler - upgradeHandlers map[string]types.UpgradeHandler - versionSetter xp.ProtocolVersionSetter // Implements setting the protocol version field on BaseApp + homePath string // root directory of app config + skipUpgradeHeights map[int64]bool // map of heights to skip for an upgrade + storeKey sdk.StoreKey // key to access x/upgrade store + cdc codec.BinaryMarshaler // App-wide binary codec + upgradeHandlers map[string]types.UpgradeHandler // map of plan name to upgrade handler + versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp } // NewKeeper constructs an upgrade Keeper From 7760ab181dd19b336a4bce48af51a3fc8e17b29f Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 30 Mar 2021 16:07:30 -0700 Subject: [PATCH 21/23] docs for upgrade NewKeeper --- x/upgrade/keeper/keeper.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index db64fde469a7..ea24fe7ebe71 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -32,7 +32,13 @@ type Keeper struct { versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp } -// NewKeeper constructs an upgrade Keeper +// NewKeeper constructs an upgrade Keeper which requires the following arguments: +// skipUpgradeHeights: a map of heights to skip a planned upgrade +// storeKey: a store key with which to access upgrade's state +// cdc: the app wide binary codec +// homePath: root directory of the application's config +// vs: the interface implemented by baseapp which allows setting baseapp's protocol version field. +// Developers should pass the baseApp object as an argument to satisfy the interface requirement. func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs xp.ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, From bebb4feb57678de27907fdb59e4354ee55ed3da1 Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Tue, 30 Mar 2021 16:08:25 -0700 Subject: [PATCH 22/23] cleanup --- x/upgrade/keeper/keeper.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index ea24fe7ebe71..9b76eb752cb1 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -38,7 +38,6 @@ type Keeper struct { // cdc: the app wide binary codec // homePath: root directory of the application's config // vs: the interface implemented by baseapp which allows setting baseapp's protocol version field. -// Developers should pass the baseApp object as an argument to satisfy the interface requirement. func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs xp.ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath, From d86db6f0839f2105698eb6f8a92b11780870c78e Mon Sep 17 00:00:00 2001 From: technicallyty <48813565+tytech3@users.noreply.github.com> Date: Thu, 1 Apr 2021 08:33:37 -0700 Subject: [PATCH 23/23] NewKeeper docs --- x/upgrade/keeper/keeper.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 9b76eb752cb1..3342c26a8c6f 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -33,11 +33,11 @@ type Keeper struct { } // NewKeeper constructs an upgrade Keeper which requires the following arguments: -// skipUpgradeHeights: a map of heights to skip a planned upgrade -// storeKey: a store key with which to access upgrade's state -// cdc: the app wide binary codec -// homePath: root directory of the application's config -// vs: the interface implemented by baseapp which allows setting baseapp's protocol version field. +// skipUpgradeHeights - map of heights to skip an upgrade +// storeKey - a store key with which to access upgrade's store +// cdc - the app-wide binary codec +// homePath - root directory of the application's config +// vs - the interface implemented by baseapp which allows setting baseapp's protocol version field func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.BinaryMarshaler, homePath string, vs xp.ProtocolVersionSetter) Keeper { return Keeper{ homePath: homePath,