diff --git a/modules/upgrade/depinject.go b/modules/upgrade/depinject.go index 83dd4781..bea9140d 100644 --- a/modules/upgrade/depinject.go +++ b/modules/upgrade/depinject.go @@ -7,7 +7,6 @@ import ( store "github.com/cosmos/cosmos-sdk/store/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" modulev1 "iritamod.bianjie.ai/api/iritamod/upgrade/module/v1" "iritamod.bianjie.ai/modules/upgrade/keeper" ) @@ -29,7 +28,6 @@ func (am AppModule) IsAppModule() {} type UpgradeInputs struct { depinject.In - //upgrade.UpgradeInputs Key *store.KVStoreKey Cdc codec.Codec } @@ -43,10 +41,8 @@ type UpgradeOutputs struct { func ProvideModule(in UpgradeInputs) UpgradeOutputs { skipUpgradeHeights := make(map[int64]bool) authority := authtypes.NewModuleAddress(govtypes.ModuleName) - cosmosupgradekeeper := upgradekeeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, "/", nil, authority.String()) - keeper := keeper.NewKeeper( - cosmosupgradekeeper, - ) + //cosmosupgradekeeper := upgradekeeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, "/", nil, authority.String()) + keeper := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, "/", nil, authority.String()) m := NewAppModule(keeper) return UpgradeOutputs{UpgradeKeeper: keeper, Module: m} } diff --git a/modules/upgrade/keeper/keeper.go b/modules/upgrade/keeper/keeper.go index 93411ba4..25c67247 100644 --- a/modules/upgrade/keeper/keeper.go +++ b/modules/upgrade/keeper/keeper.go @@ -1,8 +1,11 @@ package keeper import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + xp "github.com/cosmos/cosmos-sdk/x/upgrade/exported" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -10,18 +13,18 @@ import ( ) type Keeper struct { - uk *upgradekeeper.Keeper + *upgradekeeper.Keeper } -func NewKeeper(uk *upgradekeeper.Keeper) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter, authority string) Keeper { return Keeper{ - uk: uk, + upgradekeeper.NewKeeper(skipUpgradeHeights, storeKey, cdc, homePath, vs, authority), } } // ScheduleUpgrade schedules an upgrade based on the specified plan. func (k Keeper) ScheduleUpgrade(ctx sdk.Context, msg *types.MsgUpgradeSoftware) error { - p, has := k.uk.GetUpgradePlan(ctx) + p, has := k.GetUpgradePlan(ctx) if has { return sdkerrors.Wrapf( sdkerrors.ErrInvalidRequest, @@ -35,40 +38,40 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, msg *types.MsgUpgradeSoftware) Height: msg.Height, Info: msg.Info, } - return k.uk.ScheduleUpgrade(ctx, plan) + return k.Keeper.ScheduleUpgrade(ctx, plan) } // ClearUpgradePlan clears currently schedule upgrade func (k Keeper) ClearUpgradePlan(ctx sdk.Context) error { - _, has := k.uk.GetUpgradePlan(ctx) + _, has := k.GetUpgradePlan(ctx) if !has { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "there is currently no upgrade plan") } - k.uk.ClearUpgradePlan(ctx) + k.Keeper.ClearUpgradePlan(ctx) return nil } func (k Keeper) UpgradeKeeper() *upgradekeeper.Keeper { - return k.uk + return k.Keeper } // SetUpgradeHandler sets an UpgradeHandler for the upgrade specified by name. This handler will be called when the upgrade // with this name is applied. In order for an upgrade with the given name to proceed, a handler for this upgrade // must be set even if it is a no-op function. -func (k *Keeper) SetUpgradeHandler(name string, upgradeHandler upgradetypes.UpgradeHandler) { - k.uk.SetUpgradeHandler(name, upgradeHandler) -} +//func (k *Keeper) SetUpgradeHandler(name string, upgradeHandler upgradetypes.UpgradeHandler) { +// k.Keeper.SetUpgradeHandler(name, upgradeHandler) +//} // ReadUpgradeInfoFromDisk returns the name and height of the upgrade // which is written to disk by the old binary when panic'ing // if there's an error in reading the info, // it assumes that the upgrade info is not available -func (k Keeper) ReadUpgradeInfoFromDisk() (upgradetypes.Plan, error) { - return k.uk.ReadUpgradeInfoFromDisk() -} +//func (k Keeper) ReadUpgradeInfoFromDisk() (upgradetypes.Plan, error) { +// return k.Keeper.ReadUpgradeInfoFromDisk() +//} // IsSkipHeight checks if the given height is part of skipUpgradeHeights -func (k Keeper) IsSkipHeight(height int64) bool { - return k.uk.IsSkipHeight(height) -} +//func (k Keeper) IsSkipHeight(height int64) bool { +// return k.Keeper.IsSkipHeight(height) +//} diff --git a/modules/upgrade/test/keeper_test.go b/modules/upgrade/test/keeper_test.go index 81d2f350..dae2e788 100644 --- a/modules/upgrade/test/keeper_test.go +++ b/modules/upgrade/test/keeper_test.go @@ -3,6 +3,7 @@ package test import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkupgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/suite" "iritamod.bianjie.ai/modules/upgrade/keeper" uktype "iritamod.bianjie.ai/modules/upgrade/types" @@ -43,6 +44,18 @@ func (suite *KeeperTestSuite) TestUpgrade() { } err := suite.keeper.ScheduleUpgrade(suite.ctx, msg) suite.NoError(err) + plan, has := suite.keeper.GetUpgradePlan(suite.ctx) + suite.True(has) + suite.Equal(msg.Name, plan.Name) + suite.Equal(msg.Height, plan.Height) + plan, err = suite.keeper.ReadUpgradeInfoFromDisk() + suite.NoError(err) + resp, err := suite.keeper.CurrentPlan(suite.ctx, &sdkupgradetypes.QueryCurrentPlanRequest{}) + suite.NoError(err) + suite.NotNil(resp) + suite.Equal(msg.Name, resp.Plan.Name) + suite.Equal(msg.Height, resp.Plan.Height) err = suite.keeper.ClearUpgradePlan(suite.ctx) suite.NoError(err) + }