From e28a3c42e9160eafb97757689a8828990ddfccd8 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 12 Nov 2021 23:43:32 +0100 Subject: [PATCH 1/3] feat: update x/upgrade keeper.DumpUpgradeInfoToDisk to support Plan.Info --- x/upgrade/abci.go | 2 +- x/upgrade/keeper/keeper.go | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index f78f776d3197..b839bfa3f0c5 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -42,7 +42,7 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { if !k.HasHandler(plan.Name) { // Write the upgrade info to disk. The UpgradeStoreLoader uses this info to perform or skip // store migrations. - err := k.DumpUpgradeInfoToDisk(ctx.BlockHeight(), plan.Name) + err := k.DumpUpgradeInfoToDisk(ctx.BlockHeight(), plan.Name, plan.Info) if err != nil { panic(fmt.Errorf("unable to write upgrade info to filesystem: %s", err.Error())) } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 71e5e97dbe18..d22ffe4390ad 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -326,22 +326,28 @@ func (k Keeper) IsSkipHeight(height int64) bool { } // DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. -func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string) error { +// `info` should be provided and contain Plan.Info data in order to support +// auto upgrade functionality by cosmovisor and other tools using upgarde-info.json +// (GetUpgradeInfoPath()) file. +func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string, info ...string) error { upgradeInfoFilePath, err := k.GetUpgradeInfoPath() if err != nil { return err } - upgradeInfo := store.UpgradeInfo{ + upgradeInfo := upgradeInfo{ Name: name, Height: height, } - info, err := json.Marshal(upgradeInfo) + if len(info) != 0 { + upgradeInfo.Info = info[0] + } + bz, err := json.Marshal(upgradeInfo) if err != nil { return err } - return ioutil.WriteFile(upgradeInfoFilePath, info, 0600) + return ioutil.WriteFile(upgradeInfoFilePath, bz, 0600) } // GetUpgradeInfoPath returns the upgrade info file path @@ -388,3 +394,13 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (store.UpgradeInfo, error) { return upgradeInfo, nil } + +// upgradeInfo is stripped types.Plan structure used to dump upgrade plan data. +type upgradeInfo struct { + // Name has types.Plan.Name value + Name string `json:"name,omitempty"` + // Height has types.Plan.Height value + Height int64 `json:"height,omitempty"` + // Height has types.Plan.Height value + Info string `json:"info,omitempty"` +} From 4cde6336a47f12f581d286dc600d55465e3fe8be Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 12 Nov 2021 23:56:37 +0100 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 3 +++ x/upgrade/keeper/keeper.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d44eee903daa..7d21bbed0bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements +* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Update x/upgrade `keeper.DumpUpgradeInfoToDisk` to save `Plan.Info`. + ### Bug Fixes * [\#10414](https://github.com/cosmos/cosmos-sdk/pull/10414) Use `sdk.GetConfig().GetFullBIP44Path()` instead `sdk.FullFundraiserPath` to generate key diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index d22ffe4390ad..ccfb24de22ee 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -327,7 +327,7 @@ func (k Keeper) IsSkipHeight(height int64) bool { // DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. // `info` should be provided and contain Plan.Info data in order to support -// auto upgrade functionality by cosmovisor and other tools using upgarde-info.json +// auto download functionality by cosmovisor and other tools using upgarde-info.json // (GetUpgradeInfoPath()) file. func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string, info ...string) error { upgradeInfoFilePath, err := k.GetUpgradeInfoPath() From 8b0c92592e3beb713192ce3da476e37813817fa9 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 15 Nov 2021 23:22:08 +0100 Subject: [PATCH 3/3] create DumpUpgradeInfoWithInfoToDisk instead of overloading DumpUpgradeInfoToDisk --- CHANGELOG.md | 2 +- x/upgrade/abci.go | 2 +- x/upgrade/keeper/keeper.go | 16 +++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d21bbed0bcb..ac142395ab10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] ### Improvements -* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Update x/upgrade `keeper.DumpUpgradeInfoToDisk` to save `Plan.Info`. +* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Add `keeper.DumpUpgradeInfoWithInfoToDisk` to include `Plan.Info` in the upgrade-info file. ### Bug Fixes diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index b839bfa3f0c5..c2521e09ecc3 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -42,7 +42,7 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { if !k.HasHandler(plan.Name) { // Write the upgrade info to disk. The UpgradeStoreLoader uses this info to perform or skip // store migrations. - err := k.DumpUpgradeInfoToDisk(ctx.BlockHeight(), plan.Name, plan.Info) + err := k.DumpUpgradeInfoWithInfoToDisk(ctx.BlockHeight(), plan.Name, plan.Info) if err != nil { panic(fmt.Errorf("unable to write upgrade info to filesystem: %s", err.Error())) } diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index ccfb24de22ee..7c13ce6f1d24 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -325,11 +325,19 @@ func (k Keeper) IsSkipHeight(height int64) bool { return k.skipUpgradeHeights[height] } -// DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. +// DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. The function +// doesn't save the `Plan.Info` data, hence it won't support auto download functionality +// by cosmvisor. +// NOTE: this function will be update in the next release. +func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string) error { + return k.DumpUpgradeInfoWithInfoToDisk(height, name, "") +} + +// Deprecated: DumpUpgradeInfoWithInfoToDisk writes upgrade information to UpgradeInfoFileName. // `info` should be provided and contain Plan.Info data in order to support // auto download functionality by cosmovisor and other tools using upgarde-info.json // (GetUpgradeInfoPath()) file. -func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string, info ...string) error { +func (k Keeper) DumpUpgradeInfoWithInfoToDisk(height int64, name string, info string) error { upgradeInfoFilePath, err := k.GetUpgradeInfoPath() if err != nil { return err @@ -338,9 +346,7 @@ func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string, info ...string) upgradeInfo := upgradeInfo{ Name: name, Height: height, - } - if len(info) != 0 { - upgradeInfo.Info = info[0] + Info: info, } bz, err := json.Marshal(upgradeInfo) if err != nil {