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

Make binaries have protection against accidental downgrades #10318

Closed
4 tasks
ValarDragon opened this issue Oct 7, 2021 · 19 comments · Fixed by #10407
Closed
4 tasks

Make binaries have protection against accidental downgrades #10318

ValarDragon opened this issue Oct 7, 2021 · 19 comments · Fixed by #10407
Assignees

Comments

@ValarDragon
Copy link
Contributor

Summary

A common issue node operators have is accidentally starting with their default installed binary, after cosmovisor has done an automatic upgrade. If their binary is on the wrong version, they compute the wrong app hash, and their node gets stuck. (And since we can't rollback, #10281 #10198 you have to redownload your entire state)

We should add protection against this as well.

Proposal

On node start, we should look at the state to see all the upgrades plans executed, and what upgrade plans are registered. If there is a plan that has been executed, that has not been registered, it should halt saying that this binary is a downgrade.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez
Copy link
Contributor

Yes! This actually happened to me on Osmosis due to an invalid setup of cosmovisor.

I think the proposal makes sense. If there is support from @AmauryM or @robert-zaremba, I can tackle it.

@robert-zaremba
Copy link
Collaborator

robert-zaremba commented Oct 7, 2021

ACK - we can use info from upgrade module.

@robert-zaremba
Copy link
Collaborator

@alexanderbez - if you have time you can go with it. We could do a short call. Otherwise during the standup we were talking about this task and @aleem1314 could handle it.

@alexanderbez
Copy link
Contributor

@aleem1314 go for it! Happy to review :)

@anilcse
Copy link
Collaborator

anilcse commented Oct 11, 2021

@robert-zaremba I am not sure if we can access upgrade info from store before starting the app, I believe we cannot. That is the reason we are using upgrade-info.json file for the upgrade information.
cc @aleem1314

@ValarDragon
Copy link
Contributor Author

ValarDragon commented Oct 15, 2021

Can we add something in BeginBlock that checks this then, or make a new hook in the server's main command for this safety check?

This would help a lot with v0.42.x node upgrades as well.

@alexanderbez
Copy link
Contributor

Yeah we should really strive to do something here to prevent this execution path. ACK @ValarDragon's idea.

@aleem1314
Copy link
Contributor

Can we add something in BeginBlock that checks this then, or make a new hook in the server's main command for this safety check?

Yes, we can add this check in the BeginBlock. But we don't have enough info in the upgrade module to check the binary version.
In the upgrade module, we are storing executed plans and registered upgrades if any. That is not enough to check the binary version.

@ValarDragon
Copy link
Contributor Author

Yes, we can add this check in the BeginBlock. But we don't have enough info in the upgrade module to check the binary version.

Why do you need to look at the binary version? We should look at the state to see all the upgrades plans executed, and what upgrade plans are registered. If there is a plan that has been executed, but has not been registered, then we know we are on an old version

@anilcse
Copy link
Collaborator

anilcse commented Oct 19, 2021

Yes, we can add this check in the BeginBlock. But we don't have enough info in the upgrade module to check the binary version.

Why do you need to look at the binary version? We should look at the state to see all the upgrades plans executed, and what upgrade plans are registered. If there is a plan that has been executed, but has not been registered, then we know we are on an old version

I believe we are pruning the plans once they are executed.

@ValarDragon
Copy link
Contributor Author

ValarDragon commented Oct 19, 2021

How does osmosisd q upgrade applied v4 work then? It returns the header of the block the upgrade was applied at.

It calls this function internally:

// GetDoneHeight returns the height at which the given upgrade was executed
func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 {
store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.DoneByte})
bz := store.Get([]byte(name))
if len(bz) == 0 {
return 0
}
return int64(binary.BigEndian.Uint64(bz))
}

So presumably all the upgrades can be obtained by iterating over the store.

@robert-zaremba
Copy link
Collaborator

robert-zaremba commented Oct 20, 2021

We only prune skipped upgrades.

@robert-zaremba
Copy link
Collaborator

(sorry wrong button)

@robert-zaremba
Copy link
Collaborator

I think we can use InitChainer rather than BeginBlocker.

@ethanfrey
Copy link
Contributor

I'm a bit confused.

I wrote this code and tested it in the original upgrade handler in 2019. I thought this was still there.

The old binary would die if it started too late. New binary would die if it started too soon.
Or is this a different issue?

@ethanfrey
Copy link
Contributor

I think we can use InitChainer rather than BeginBlocker.

InitChainer is only called once at genesis, not when restarting

@robert-zaremba
Copy link
Collaborator

The old binary would die if it started too late. New binary would die if it started too soon.

Currently, the first case holds, the latter doesn't. I don't know what changed. @ethanfrey what was your original solution?

@anilcse
Copy link
Collaborator

anilcse commented Nov 19, 2021

@robert-zaremba I think it's vice-versa. It always fails if we start new binary early. If we start old-binary at the time of upgrade also it fails. But after the upgrade if we start old binary, as there's no active plan, it tries to produce blocks and thus creating consensus failures iiuc

@ethanfrey
Copy link
Contributor

You can read https://medium.com/regen-network/amazonas-upgrade-guide-b31e9e18e0be

When running this in testnets 2 years ago, I had to handle both cases, to avoid operator error.

If you find the binary used for that upgrade and the regen/cosmos-sdk code used at that time, you can find my solution (which was 0.37/0.38 compatible)

@mergify mergify bot closed this as completed in #10407 Jan 25, 2022
mergify bot pushed a commit that referenced this issue Jan 25, 2022
## Description

Closes: #10318 



---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)
mergify bot pushed a commit that referenced this issue Jan 25, 2022
## Description

Closes: #10318

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)

(cherry picked from commit 5622115)

# Conflicts:
#	CHANGELOG.md
#	x/upgrade/keeper/keeper.go
robert-zaremba pushed a commit that referenced this issue Jan 27, 2022
…#11026)

* feat!: add protection against accidental downgrades (#10407)

## Description

Closes: #10318

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)

(cherry picked from commit 5622115)

# Conflicts:
#	CHANGELOG.md
#	x/upgrade/keeper/keeper.go

* chore: resolve conflicts

Co-authored-by: MD Aleem <[email protected]>
Co-authored-by: aleem1314 <[email protected]>
JimLarson pushed a commit to agoric-labs/cosmos-sdk that referenced this issue Jul 7, 2022
…10407) (cosmos#11026)

* feat!: add protection against accidental downgrades (cosmos#10407)

## Description

Closes: cosmos#10318

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)

(cherry picked from commit 5622115)

# Conflicts:
#	CHANGELOG.md
#	x/upgrade/keeper/keeper.go

* chore: resolve conflicts

Co-authored-by: MD Aleem <[email protected]>
Co-authored-by: aleem1314 <[email protected]>
JeancarloBarrios pushed a commit to agoric-labs/cosmos-sdk that referenced this issue Sep 28, 2024
…10407) (cosmos#11026)

* feat!: add protection against accidental downgrades (cosmos#10407)

## Description

Closes: cosmos#10318

---

### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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)

(cherry picked from commit 5622115)

# Conflicts:
#	CHANGELOG.md
#	x/upgrade/keeper/keeper.go

* chore: resolve conflicts

Co-authored-by: MD Aleem <[email protected]>
Co-authored-by: aleem1314 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants