Skip to content

Commit 6a46c95

Browse files
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
1 parent 2bbec7a commit 6a46c95

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
3737

3838
## [Unreleased]
3939

40+
### Improvements
41+
* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Add `keeper.DumpUpgradeInfoWithInfoToDisk` to include `Plan.Info` in the upgrade-info file.
42+
4043
### Bug Fixes
4144

4245
* [\#10414](https://github.com/cosmos/cosmos-sdk/pull/10414) Use `sdk.GetConfig().GetFullBIP44Path()` instead `sdk.FullFundraiserPath` to generate key

x/upgrade/abci.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) {
4242
if !k.HasHandler(plan.Name) {
4343
// Write the upgrade info to disk. The UpgradeStoreLoader uses this info to perform or skip
4444
// store migrations.
45-
err := k.DumpUpgradeInfoToDisk(ctx.BlockHeight(), plan.Name)
45+
err := k.DumpUpgradeInfoWithInfoToDisk(ctx.BlockHeight(), plan.Name, plan.Info)
4646
if err != nil {
4747
panic(fmt.Errorf("unable to write upgrade info to filesystem: %s", err.Error()))
4848
}

x/upgrade/keeper/keeper.go

+26-4
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,35 @@ func (k Keeper) IsSkipHeight(height int64) bool {
325325
return k.skipUpgradeHeights[height]
326326
}
327327

328-
// DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName.
328+
// DumpUpgradeInfoToDisk writes upgrade information to UpgradeInfoFileName. The function
329+
// doesn't save the `Plan.Info` data, hence it won't support auto download functionality
330+
// by cosmvisor.
331+
// NOTE: this function will be update in the next release.
329332
func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string) error {
333+
return k.DumpUpgradeInfoWithInfoToDisk(height, name, "")
334+
}
335+
336+
// Deprecated: DumpUpgradeInfoWithInfoToDisk writes upgrade information to UpgradeInfoFileName.
337+
// `info` should be provided and contain Plan.Info data in order to support
338+
// auto download functionality by cosmovisor and other tools using upgarde-info.json
339+
// (GetUpgradeInfoPath()) file.
340+
func (k Keeper) DumpUpgradeInfoWithInfoToDisk(height int64, name string, info string) error {
330341
upgradeInfoFilePath, err := k.GetUpgradeInfoPath()
331342
if err != nil {
332343
return err
333344
}
334345

335-
upgradeInfo := store.UpgradeInfo{
346+
upgradeInfo := upgradeInfo{
336347
Name: name,
337348
Height: height,
349+
Info: info,
338350
}
339-
info, err := json.Marshal(upgradeInfo)
351+
bz, err := json.Marshal(upgradeInfo)
340352
if err != nil {
341353
return err
342354
}
343355

344-
return ioutil.WriteFile(upgradeInfoFilePath, info, 0600)
356+
return ioutil.WriteFile(upgradeInfoFilePath, bz, 0600)
345357
}
346358

347359
// GetUpgradeInfoPath returns the upgrade info file path
@@ -388,3 +400,13 @@ func (k Keeper) ReadUpgradeInfoFromDisk() (store.UpgradeInfo, error) {
388400

389401
return upgradeInfo, nil
390402
}
403+
404+
// upgradeInfo is stripped types.Plan structure used to dump upgrade plan data.
405+
type upgradeInfo struct {
406+
// Name has types.Plan.Name value
407+
Name string `json:"name,omitempty"`
408+
// Height has types.Plan.Height value
409+
Height int64 `json:"height,omitempty"`
410+
// Height has types.Plan.Height value
411+
Info string `json:"info,omitempty"`
412+
}

0 commit comments

Comments
 (0)