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

Turn staking power reduction into an on-chain param #8505

Merged
merged 30 commits into from
Apr 10, 2021

Conversation

sunnya97
Copy link
Member

@sunnya97 sunnya97 commented Feb 3, 2021

closes: #8365

Copied description from issue:

Currently, the power reduction variable in the staking module is defaulted to 10^6. While it is possible to change this in the app.go in the codebase, we would like to remove the reliance on global variables throughout the codebase. Instead, the power reduction should be an on-chain param.

Along with better code hygiene, by making PowerReduction an on-chain param instead of code variable, we would be able to update it on a running chain. This could be useful for things like asset redenominations, but also more advanced voting power distributions.

For example, you can use a dynamic PowerReduction to create a "less granular" voting power (i.e. if Validator A has a stake 54 tokens, and validator B has stake 103 tokens, the chain can dynamically set the power reduction to be 50, so validator A has voting power 1, and validator B has voting power 2.). This is useful for things like threshold cryptography and sharding.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Feb 3, 2021

Codecov Report

Merging #8505 (4b778ab) into master (04ab271) will decrease coverage by 0.18%.
The diff coverage is 37.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8505      +/-   ##
==========================================
- Coverage   59.00%   58.82%   -0.19%     
==========================================
  Files         577      580       +3     
  Lines       32481    32643     +162     
==========================================
+ Hits        19167    19203      +36     
- Misses      11052    11174     +122     
- Partials     2262     2266       +4     
Impacted Files Coverage Δ
x/gov/types/params.go 4.54% <ø> (ø)
x/staking/client/cli/tx.go 61.11% <ø> (ø)
x/staking/keeper/invariants.go 50.49% <0.00%> (ø)
x/staking/keeper/migrations.go 50.00% <0.00%> (ø)
x/staking/legacy/v040/keys.go 0.00% <0.00%> (ø)
x/staking/legacy/v040/types.go 0.00% <0.00%> (ø)
x/staking/legacy/v043/json.go 36.98% <36.98%> (ø)
types/staking.go 50.00% <50.00%> (ø)
x/staking/genesis.go 55.90% <50.00%> (-4.73%) ⬇️
x/staking/types/params.go 44.87% <55.55%> (+1.39%) ⬆️
... and 17 more

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@alexanderbez
Copy link
Contributor

Each param change set has a validation function, e.g. https://github.com/cosmos/cosmos-sdk/blob/master/x/mint/types/params.go#L93

@sunnya97
Copy link
Member Author

@alexanderbez No, I mean that #8909 makes it such that a CreateValidator message with < 1 consensus power of self-bond fails the ValidateBasic of the MsgCreateValidator. But this can't be done now, because in this PR the MsgCreateValidator.ValidateBasic function doesn't have the ctx, and so can't know what the current power reduction is.

@alexanderbez
Copy link
Contributor

alexanderbez commented Mar 22, 2021

Ahhh, yes, you're right. I think our only option is to remove it from the stateless ValidateBasic and add the check to the MsgCreateValidator message handler.

@sunnya97
Copy link
Member Author

sunnya97 commented Mar 22, 2021

Yeah, that's what I started doing, but actually I think that might be doubling down on the wrong solution. I wrote this on the #8909 (comment) PR.

I think always requiring a CreateValidator to have a minimum of 1 consensus power isn't correct. At the moment, power-reduction is really low, so it is fine. However, #8505 makes power reduction an on-chain param, with the intent that some use cases might want the number of tokens needed to get one consensus power gets really high. In these cases, we want validators to be able to declare the validator without needing to provide 1 full consensus power by themselves.

To solve the problem this was meant to tackle (which I agree is quite annoying an issue), I believe an error should be thrown during the Genesis validation. A genesis file to be valid, should require that the total consensus power of all the genesis validators is >0. This seems like a better place to solve this issue than requiring all CreateValidators to have 1 consensus power self-bond, even after genesis.

@sunnya97 sunnya97 added this to the v0.43 milestone Apr 2, 2021
@sunnya97 sunnya97 self-assigned this Apr 2, 2021
Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Code lgtm, but it seems like migrations (both JSON and in-place) are not handled correctly

CHANGELOG.md Outdated Show resolved Hide resolved
x/staking/legacy/v040/migrate.go Outdated Show resolved Hide resolved
x/staking/legacy/v043/store_test.go Show resolved Hide resolved
@sunnya97
Copy link
Member Author

sunnya97 commented Apr 8, 2021

@AmauryM, fixed the migrations issues

@sunnya97
Copy link
Member Author

sunnya97 commented Apr 8, 2021

Still not sure why test-rosetta is failing though

@clevinson
Copy link
Contributor

Maybe @jgimeno or @fdymylja have ideas?

@fdymylja
Copy link
Contributor

fdymylja commented Apr 9, 2021

If the PR breaks state then node data needs to be rebuilt.

To rebuild rosetta with new state:

  • make rosetta-data
  • it's gonna output a cosmos address and a validator address; take the cosmos address and put it in ./contrib/rosetta/configuration/bootstrap.json

after that you can run: make test-rosetta to check if it passes.

@sunnya97
Copy link
Member Author

Thanks @fdymylja!

@sunnya97 sunnya97 merged commit a4c7fd7 into cosmos:master Apr 10, 2021
@sunnya97
Copy link
Member Author

Oops, I forgot the squash and merge 🤦

Is there a way to fix that?

mergify bot pushed a commit that referenced this pull request Jun 14, 2021
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

Closes: #9447

This PR partially reverts #8505. Namely:
- it removes PowerReduction as a staking on-chain param
- however, it keeps #8505's API changes regarding adding a `powerReduction` function argument to staking functions. This allows us to rely less on global variables in said functions.

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Turn staking Power Reduction into an on-chain param
9 participants