From 9360903c2e42f4a36de1b38c913160e2e148d263 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Mon, 15 Nov 2021 22:45:05 +0000 Subject: [PATCH] feat: update x/upgrade keeper.DumpUpgradeInfoToDisk to support Plan.Info (#10532) * feat: update x/upgrade keeper.DumpUpgradeInfoToDisk to support Plan.Info * add changelog * create DumpUpgradeInfoWithInfoToDisk instead of overloading DumpUpgradeInfoToDisk --- CHANGELOG.md | 3 +++ x/upgrade/keeper/keeper.go | 41 ++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae23b568fead..75051823ae45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements +* (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 * [\#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 c154fb64c062..1525c4e1d34e 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -468,24 +468,35 @@ func (k Keeper) IsSkipHeight(height int64) bool { return k.skipUpgradeHeights[height] } -// DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. -func (k Keeper) DumpUpgradeInfoToDisk(height int64, p types.Plan) error { +// 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) DumpUpgradeInfoWithInfoToDisk(height int64, name string, info string) error { upgradeInfoFilePath, err := k.GetUpgradeInfoPath() if err != nil { return err } - upgradeInfo := types.Plan{ - Name: p.Name, + upgradeInfo := upgradeInfo{ + Name: name, Height: height, - Info: p.Info, + Info: info, } - info, err := json.Marshal(upgradeInfo) + bz, err := json.Marshal(upgradeInfo) if err != nil { return err } - return os.WriteFile(upgradeInfoFilePath, info, 0o600) + return ioutil.WriteFile(upgradeInfoFilePath, bz, 0600) } // GetUpgradeInfoPath returns the upgrade info file path @@ -535,12 +546,12 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (types.Plan, error) { return upgradeInfo, nil } -// SetDowngradeVerified updates downgradeVerified. -func (k *Keeper) SetDowngradeVerified(v bool) { - k.downgradeVerified = v -} - -// DowngradeVerified returns downgradeVerified. -func (k Keeper) DowngradeVerified() bool { - return k.downgradeVerified +// 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"` }