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

fix(distribution): correct default for deprecated distribution params #14462

Merged
merged 6 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions api/cosmos/distribution/v1beta1/distribution.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions proto/cosmos/distribution/v1beta1/distribution.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ message Params {
(gogoproto.nullable) = false
];

// The base_proposer_reward and bonus_proposer_reward fields are deprecated
// and are no longer used in the x/distribution module's reward mechanism.
// Deprecated: The base_proposer_reward field is deprecated and is no longer used
// in the x/distribution module's reward mechanism.
string base_proposer_reward = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
deprecated = true
];

// Deprecated: The bonus_proposer_reward field is deprecated and is no longer used
// in the x/distribution module's reward mechanism.
string bonus_proposer_reward = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/distribution/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func (s *E2ETestSuite) TestGetCmdQueryParams() {
{
"json output",
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
`{"community_tax":"0.020000000000000000","base_proposer_reward":"0.010000000000000000","bonus_proposer_reward":"0.040000000000000000","withdraw_addr_enabled":true}`,
`{"community_tax":"0.020000000000000000","base_proposer_reward":"0.000000000000000000","bonus_proposer_reward":"0.000000000000000000","withdraw_addr_enabled":true}`,
},
{
"text output",
[]string{fmt.Sprintf("--%s=text", flags.FlagOutput)},
`base_proposer_reward: "0.010000000000000000"
bonus_proposer_reward: "0.040000000000000000"
`base_proposer_reward: "0.000000000000000000"
bonus_proposer_reward: "0.000000000000000000"
community_tax: "0.020000000000000000"
withdraw_addr_enabled: true`,
},
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/adr-024-coin-metadata_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@
"distribution": {
"params": {
"community_tax": "0.020000000000000000",
"base_proposer_reward": "0.010000000000000000",
"bonus_proposer_reward": "0.040000000000000000",
"base_proposer_reward": "0.000000000000000000",
"bonus_proposer_reward": "0.000000000000000000",
"withdraw_addr_enabled": true
},
"fee_pool": {
Expand Down
1 change: 0 additions & 1 deletion tests/integration/distribution/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var (
valConsPk2 = PKS[2]

valConsAddr0 = sdk.ConsAddress(valConsPk0.Address())
valConsAddr1 = sdk.ConsAddress(valConsPk1.Address())

distrAcc = authtypes.NewEmptyModuleAccount(types.ModuleName)
)
6 changes: 3 additions & 3 deletions tests/integration/distribution/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func (suite *KeeperTestSuite) TestGRPCParams() {
func() {
params = types.Params{
CommunityTax: sdk.NewDecWithPrec(3, 1),
BaseProposerReward: sdk.NewDecWithPrec(2, 1),
BonusProposerReward: sdk.NewDecWithPrec(1, 1),
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: true,
}

Expand All @@ -117,7 +117,7 @@ func (suite *KeeperTestSuite) TestGRPCParams() {
if testCase.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(paramsRes)
suite.Require().Equal(paramsRes.Params, expParams)
suite.Require().Equal(expParams, paramsRes.Params)
} else {
suite.Require().Error(err)
}
Expand Down
64 changes: 17 additions & 47 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (

func (s *KeeperTestSuite) TestMsgUpdateParams() {
// default params
communityTax := sdk.NewDecWithPrec(2, 2) // 2%
baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1%
bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4%
communityTax := sdk.NewDecWithPrec(2, 2) // 2%
withdrawAddrEnabled := true

testCases := []struct {
Expand All @@ -29,9 +27,9 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: "invalid",
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(2, 0),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
Expand All @@ -43,9 +41,9 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(2, 0),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
Expand All @@ -57,78 +55,50 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() {
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: sdk.NewDecWithPrec(-2, 1),
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
},
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
},
{
name: "base proposer reward > 1",
name: "base proposer reward set",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(2, 0),
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.NewDecWithPrec(1, 2),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
expErrMsg: "cannot update base or bonus proposer reward because these are deprecated fields: invalid request",
},
{
name: "negative base proposer reward",
name: "bonus proposer reward set",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: sdk.NewDecWithPrec(-2, 0),
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.NewDecWithPrec(1, 2),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "base proposer reward should be positive",
},
{
name: "bonus proposer reward > 1",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one",
},
{
name: "negative bonus proposer reward",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: sdk.NewDecWithPrec(-2, 0),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
expErr: true,
expErrMsg: "bonus proposer reward should be positive",
expErrMsg: "cannot update base or bonus proposer reward because these are deprecated fields: invalid request",
},
{
name: "all good",
input: &types.MsgUpdateParams{
Authority: s.distrKeeper.GetAuthority(),
Params: types.Params{
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
BaseProposerReward: sdk.ZeroDec(),
BonusProposerReward: sdk.ZeroDec(),
WithdrawAddrEnabled: withdrawAddrEnabled,
},
},
Expand Down
117 changes: 0 additions & 117 deletions tests/integration/distribution/keeper/params_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/bank/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestRandomizedGenState(t *testing.T) {
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &bankGenesis)

assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled")
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // SA1019: Params.GetSendEnabled is deprecated: use SendEnabled instead.
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck
if assert.Len(t, bankGenesis.Balances, 3) {
assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].GetAddress().String(), "Balances[2] address")
assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins")
Expand Down
14 changes: 6 additions & 8 deletions x/distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,10 @@ The distribution module contains the following parameters:
| Key | Type | Example |
| ------------------- | ------------ | -------------------------- |
| communitytax | string (dec) | "0.020000000000000000" [0] |
| baseproposerreward | string (dec) | "0.010000000000000000" [0] |
| bonusproposerreward | string (dec) | "0.040000000000000000" [0] |
| withdrawaddrenabled | bool | true |

* [0] `communitytax`, `baseproposerreward` and `bonusproposerreward` must be
positive and their sum cannot exceed 1.00.
* [0] `communitytax` must be positive and cannot exceed 1.00.
* `baseproposerreward` and `bonusproposerreward` were parameters that are deprecated in v0.47 and are not used.

## Client

Expand Down Expand Up @@ -594,8 +592,8 @@ simd query distribution params
Example Output:

```yml
base_proposer_reward: "0.010000000000000000"
bonus_proposer_reward: "0.040000000000000000"
base_proposer_reward: "0.000000000000000000"
bonus_proposer_reward: "0.000000000000000000"
community_tax: "0.020000000000000000"
withdraw_addr_enabled: true
```
Expand Down Expand Up @@ -781,8 +779,8 @@ Example Output:
{
"params": {
"communityTax": "20000000000000000",
"baseProposerReward": "10000000000000000",
"bonusProposerReward": "40000000000000000",
"baseProposerReward": "00000000000000000",
"bonusProposerReward": "00000000000000000",
"withdrawAddrEnabled": true
}
}
Expand Down
5 changes: 5 additions & 0 deletions x/distribution/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}

if (!req.Params.BaseProposerReward.IsNil() && !req.Params.BaseProposerReward.IsZero()) || //nolint:staticcheck
(!req.Params.BonusProposerReward.IsNil() && !req.Params.BonusProposerReward.IsZero()) { //nolint:staticcheck
return nil, errors.Wrapf(errors.ErrInvalidRequest, "cannot update base or bonus proposer reward because these are deprecated fields")
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
return nil, err
Expand Down
Loading