Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
24 changes: 20 additions & 4 deletions x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 download functionality by cosmovisor and other tools using upgarde-info.json
// (GetUpgradeInfoPath()) file.
func (k Keeper) DumpUpgradeInfoToDisk(height int64, name string, info ...string) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trick to make the API backward compatible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just add another overload DumpFullUpgradeInfoToDisk? The varargs feels too hacky.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The master branch already has it as DumpUpgradeInfoToDisk(height int64, p types.Plan) error. This PR is just to get the functionality into v0.44.x.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question was if we should do it by adding new function (and instantly marking it "deprecated") or overloading the existing DumpUpgradeInfoToDisk.
In general overloading smells bad, so Aaron comment makes sense.

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
Expand Down Expand Up @@ -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"`
}