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(cosmovisor): add ability to run custom preupgrade script #16550

Merged
merged 9 commits into from
Jun 27, 2023

Conversation

chillyvee
Copy link
Contributor

@chillyvee chillyvee commented Jun 14, 2023

Description

Validators/Infrastructure providers need the ability to execute custom scripts for backup, alerting, and other functions prior to upgrade.

Set environment variable COSMOVISOR_CUSTOM_PREUPGRADE=preupgrade.sh to execute .simapp/cosmovisor/preupgrade.sh during upgrade.

Custom script is run with 2 arguments [ Upgrade Name, Upgrade Height ]

For example:
.simapp/cosmovisor/preupgrade.sh v2 2000 for upgrade v2 at height 2000


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@chillyvee chillyvee requested a review from a team as a code owner June 14, 2023 18:19
@github-prbot github-prbot requested review from a team, JeancarloBarrios and julienrbrt and removed request for a team June 14, 2023 18:20
@github-actions github-actions bot added the C:Cosmovisor Issues and PR related to Cosmovisor label Jun 14, 2023
@chillyvee chillyvee changed the title Cv cosmovisor custom preupgrade feat(tools): cosmovisor custom preupgrade Jun 14, 2023
tools/cosmovisor/README.md Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Could you update the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests updated, waiting for results.

tools/cosmovisor/process.go Outdated Show resolved Hide resolved
tools/cosmovisor/process.go Fixed Show resolved Hide resolved
@julienrbrt julienrbrt changed the title feat(tools): cosmovisor custom preupgrade feat(cosmovisor): add ability to run custom preupgrade script Jun 14, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
@chillyvee
Copy link
Contributor Author

Will take care of tests another day :)

@facundomedica
Copy link
Member

Will take care of tests another day :)

give us a ping whenever you have them 🙌

@chillyvee chillyvee force-pushed the cv_cosmovisor_custom_preupgrade branch from 59367ed to a6bc667 Compare June 24, 2023 08:18
}

// Run preupgradeFile
cmd := exec.Command(preupgradeFile, uInfo.Name, fmt.Sprintf("%d", uInfo.Height))

Check failure

Code scanning / gosec

Subprocess launched with variable

Subprocess launched with variable
@chillyvee chillyvee force-pushed the cv_cosmovisor_custom_preupgrade branch from a6bc667 to 88ef8be Compare June 24, 2023 08:36
@chillyvee
Copy link
Contributor Author

@facundomedica Tests added. Some "less related" github automated test fail, but the directly related tests pass..

If more adjustments necessary, please message back.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Overall lgtm. I am going to test locally that it works.

return err
}

if uInfo.Name == "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could use the validate function on the plan

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed code to use ValidateBasic

Copy link
Contributor Author

@chillyvee chillyvee Jun 25, 2023

Choose a reason for hiding this comment

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

should the test be removed completely since UpgradeBinary already checks upgradeInfo.ValidateFull()?

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Nice and thank you @chillyvee! LGTM to me mostly but there is an assertion that we need to make in the tests for cases where the preUpgrade file doesn't exist to ensure that the error is of type os.IsNotExist. Thank you.

tools/cosmovisor/process_test.go Outdated Show resolved Hide resolved
tools/cosmovisor/process_test.go Outdated Show resolved Hide resolved
tools/cosmovisor/process.go Outdated Show resolved Hide resolved
tools/cosmovisor/process_test.go Outdated Show resolved Hide resolved
tools/cosmovisor/process_test.go Outdated Show resolved Hide resolved
@chillyvee
Copy link
Contributor Author

@odeke-em Appreciate the comments! Running new commits through test.

Copy link
Collaborator

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @chillyvee!

@julienrbrt julienrbrt enabled auto-merge June 27, 2023 19:01
@julienrbrt julienrbrt added this pull request to the merge queue Jun 27, 2023
Merged via the queue into cosmos:main with commit 1fd25ac Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Cosmovisor Issues and PR related to Cosmovisor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants