From b18e03e93472d5d688ed3176b3ee701c36484956 Mon Sep 17 00:00:00 2001 From: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Date: Tue, 24 Oct 2023 10:23:18 +0200 Subject: [PATCH 1/2] chore(x/upgrade): Use ValidateBasic for Plan in ReadUpgradeInfoFromDisk (#18210) (cherry picked from commit 458dd044b9caf6c57eae101b1ca7b5695f496fe7) # Conflicts: # x/upgrade/keeper/msg_server.go --- x/upgrade/keeper/keeper.go | 4 ++++ x/upgrade/keeper/keeper_test.go | 6 ++++++ x/upgrade/keeper/msg_server.go | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 3f9929a7277b..4e53b9137952 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -444,6 +444,10 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (types.Plan, error) { return upgradeInfo, err } + if err := upgradeInfo.ValidateBasic(); err != nil { + return upgradeInfo, err + } + return upgradeInfo, nil } diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index 84dfdee0e85a..9b123f22add7 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -84,6 +84,12 @@ func (s *KeeperTestSuite) TestReadUpgradeInfoFromDisk() { s.Require().NoError(err) expected.Height = 101 s.Require().Equal(expected, ui) + + // create invalid upgrade plan (with empty name) + expected.Name = "" + s.Require().NoError(s.upgradeKeeper.DumpUpgradeInfoToDisk(101, expected)) + _, err = s.upgradeKeeper.ReadUpgradeInfoFromDisk() + s.Require().ErrorContains(err, "name cannot be empty: invalid request") } func (s *KeeperTestSuite) TestScheduleUpgrade() { diff --git a/x/upgrade/keeper/msg_server.go b/x/upgrade/keeper/msg_server.go index 3e4a7f1fc008..ff4d1257fb9a 100644 --- a/x/upgrade/keeper/msg_server.go +++ b/x/upgrade/keeper/msg_server.go @@ -29,8 +29,12 @@ func (k msgServer) SoftwareUpgrade(goCtx context.Context, req *types.MsgSoftware return nil, errors.Wrapf(gov.ErrInvalidSigner, "expected %s got %s", k.authority, req.Authority) } +<<<<<<< HEAD ctx := sdk.UnwrapSDKContext(goCtx) err := k.ScheduleUpgrade(ctx, req.Plan) +======= + err := k.ScheduleUpgrade(ctx, msg.Plan) +>>>>>>> 458dd044b (chore(x/upgrade): Use ValidateBasic for Plan in ReadUpgradeInfoFromDisk (#18210)) if err != nil { return nil, err } From 6b70961dbaea2f6f52bfebc3f759c02efe4b017f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Oct 2023 10:42:15 +0200 Subject: [PATCH 2/2] fix conflicts --- x/upgrade/keeper/msg_server.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x/upgrade/keeper/msg_server.go b/x/upgrade/keeper/msg_server.go index ff4d1257fb9a..3e4a7f1fc008 100644 --- a/x/upgrade/keeper/msg_server.go +++ b/x/upgrade/keeper/msg_server.go @@ -29,12 +29,8 @@ func (k msgServer) SoftwareUpgrade(goCtx context.Context, req *types.MsgSoftware return nil, errors.Wrapf(gov.ErrInvalidSigner, "expected %s got %s", k.authority, req.Authority) } -<<<<<<< HEAD ctx := sdk.UnwrapSDKContext(goCtx) err := k.ScheduleUpgrade(ctx, req.Plan) -======= - err := k.ScheduleUpgrade(ctx, msg.Plan) ->>>>>>> 458dd044b (chore(x/upgrade): Use ValidateBasic for Plan in ReadUpgradeInfoFromDisk (#18210)) if err != nil { return nil, err }