Skip to content

Commit

Permalink
feat: update x/upgrade keeper.DumpUpgradeInfoToDisk to support Plan.I…
Browse files Browse the repository at this point in the history
…nfo (cosmos#10532)

* feat: update x/upgrade keeper.DumpUpgradeInfoToDisk to support Plan.Info

* add changelog

* create DumpUpgradeInfoWithInfoToDisk instead of overloading DumpUpgradeInfoToDisk
  • Loading branch information
robert-zaremba authored and nnkken committed Jan 16, 2022
1 parent 01fac64 commit 5e8ea50
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion x/upgrade/abci.go
Expand Up @@ -58,7 +58,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.DumpUpgradeInfoWithInfoToDisk(ctx.BlockHeight(), plan.Name, plan.Info)
if err != nil {
panic(fmt.Errorf("unable to write upgrade info to filesystem: %s", err.Error()))
}
Expand Down
30 changes: 26 additions & 4 deletions x/upgrade/keeper/keeper.go
Expand Up @@ -235,23 +235,35 @@ 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) DumpUpgradeInfoWithInfoToDisk(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: info,
}
info, err := json.Marshal(upgradeInfo)
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
Expand Down Expand Up @@ -298,3 +310,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"`
}

0 comments on commit 5e8ea50

Please sign in to comment.