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

power reduction as on-chain param #65

Conversation

xbuidler
Copy link
Collaborator

Description

Turn staking Power Reduction into an on-chain param

closes: cosmos#8365


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

@xbuidler xbuidler marked this pull request as draft January 26, 2021 13:36
@sunnya97
Copy link

sunnya97 commented Jan 27, 2021

Oh wow. I didn't realize so many tests all over the repo are using it

It seems it's because the tests all want to just provision validators by passing in their power as int64. I wonder if that's really that necessary, the could just pass in a coins amount... Regardless, lets not change that for now.

But what we should do is that in mosts of the tests, the stakingkeeper is already created. So could we have it use the PowerReduction from params instead of the default one?

So just as an example, in this spot: https://github.com/sikkatech/cosmos-sdk/pull/65/files#diff-ed4e03a1684493ef5faebd259fba6adbd95295a1e8e3cecd54c4f27e30de7da9R284

Instead of

func TestTallyDelgatorInherit(t *testing.T) {
	app := simapp.Setup(false)		app := simapp.Setup(false)
	ctx := app.BaseApp.NewContext(false, tmproto.Header{})
	addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
	delTokens := sdk.TokensFromConsensusPower(30, sdk.DefaultPowerReduction)
	...

it could be

func TestTallyDelgatorInherit(t *testing.T) {
	app := simapp.Setup(false)		app := simapp.Setup(false)
	ctx := app.BaseApp.NewContext(false, tmproto.Header{})
	addrs, vals := createValidators(t, ctx, app, []int64{5, 6, 7})
	delTokens := sdk.TokensFromConsensusPower(30, app.StakingKeeper.GetParams(ctx).PowerReduction)
	...

@xbuidler
Copy link
Collaborator Author

xbuidler commented Jan 28, 2021

Instead of

delTokens := sdk.TokensFromConsensusPower(30, sdk.DefaultPowerReduction)

Used

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 30)

@codecov-io
Copy link

codecov-io commented Jan 28, 2021

Codecov Report

Merging #65 (7130544) into master (a87d6ea) will increase coverage by 6.16%.
The diff coverage is 63.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   55.25%   61.41%   +6.16%     
==========================================
  Files         593      657      +64     
  Lines       36990    37401     +411     
==========================================
+ Hits        20437    22970    +2533     
+ Misses      14442    12026    -2416     
- Partials     2111     2405     +294     
Impacted Files Coverage Δ
baseapp/grpcserver.go 2.56% <0.00%> (-0.57%) ⬇️
client/flags/flags.go 20.83% <0.00%> (-0.91%) ⬇️
client/keys/parse.go 76.27% <0.00%> (ø)
client/query.go 20.45% <0.00%> (+1.70%) ⬆️
client/rpc/block.go 10.00% <0.00%> (ø)
client/rpc/validators.go 0.00% <0.00%> (ø)
client/test_helpers.go 0.00% <0.00%> (ø)
client/tx/legacy.go 0.00% <0.00%> (ø)
codec/amino.go 72.22% <ø> (ø)
codec/types/compat.go 68.18% <0.00%> (-0.71%) ⬇️
... and 420 more

@@ -35,7 +35,7 @@ var (
multiPermAcc = authtypes.NewEmptyModuleAccount(multiPerm, authtypes.Burner, authtypes.Minter, authtypes.Staking)
randomPermAcc = authtypes.NewEmptyModuleAccount(randomPerm, "random")

initTokens = sdk.TokensFromConsensusPower(initialPower)
initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction)

Choose a reason for hiding this comment

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

initTokens variable is used in several places, to be secure, variable name should be defaultInitTokens as it's derivated from sdk.DefaultPowerReduction.

Choose a reason for hiding this comment

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

I think that because these are in tests, I think it's okay as is. If this was in state machine codepaths, I'd agree. But this is just a variable name local to the test, and so like to the view of the test, it is the initTokens, not just a default InitTokens.

Ditto to the other similar comments.

Choose a reason for hiding this comment

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

initTokens is a global varible used in tests, it's not local function variable. It can be used in several tests where power reduction could be different.

Copy link

@sunnya97 sunnya97 Feb 1, 2021

Choose a reason for hiding this comment

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

Hmm, ok, makes sense

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For my perspective, global var initTokens can be initialized from DefaultPowerReduction and local initTokens can be initialized from on-chain power reduction. If local test has different on-chain power reduction, it can initialize local initTokens.

@@ -34,7 +34,7 @@ var (
sdk.ValAddress(pubkeys[2].Address()),
}

initAmt = sdk.TokensFromConsensusPower(200)
initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))

Choose a reason for hiding this comment

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

Recommend updates to defaultInitAmt and defaultInitCoins.

@@ -5,5 +5,5 @@ import (
)

var (
InitTokens = sdk.TokensFromConsensusPower(200)
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)

Choose a reason for hiding this comment

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

Recommend an update to DefaultInitTokens

@@ -3,5 +3,5 @@ package keeper_test
import sdk "github.com/cosmos/cosmos-sdk/types"

var (
InitTokens = sdk.TokensFromConsensusPower(200)
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)

Choose a reason for hiding this comment

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

Recommend an update to DefaultInitTokens

@antstalepresh
Copy link

Why rosetta test is cancelled? Is it an expected behavior @sunnya97 @psaradev

@sunnya97
Copy link

@antstalepresh I'm not sure. Maybe it ran out of resources? Going to try rerunning it

Copy link

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Nice work! I didn't realize the power reduction was used so statelessly throughout the SDK tests

client/flags/flags.go Outdated Show resolved Hide resolved
types/staking.go Show resolved Hide resolved
x/gov/common_test.go Show resolved Hide resolved
x/gov/types/params.go Outdated Show resolved Hide resolved
x/staking/keeper/val_state_change.go Outdated Show resolved Hide resolved
x/staking/legacy/v040/migrate.go Outdated Show resolved Hide resolved
x/staking/types/validator.go Outdated Show resolved Hide resolved
@xbuidler xbuidler marked this pull request as ready for review February 3, 2021 10:18
@sunnya97 sunnya97 changed the base branch from master to powerreduction_param February 3, 2021 14:42
@sunnya97 sunnya97 merged commit 2c1ef71 into sikkatech:powerreduction_param Feb 3, 2021
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 this pull request may close these issues.

5 participants