diff --git a/api/cosmos/distribution/v1beta1/distribution.pulsar.go b/api/cosmos/distribution/v1beta1/distribution.pulsar.go index 856240f07509..2abeacdb23b5 100644 --- a/api/cosmos/distribution/v1beta1/distribution.pulsar.go +++ b/api/cosmos/distribution/v1beta1/distribution.pulsar.go @@ -6602,11 +6602,14 @@ type Params struct { unknownFields protoimpl.UnknownFields CommunityTax string `protobuf:"bytes,1,opt,name=community_tax,json=communityTax,proto3" json:"community_tax,omitempty"` - // 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. // // Deprecated: Do not use. BaseProposerReward string `protobuf:"bytes,2,opt,name=base_proposer_reward,json=baseProposerReward,proto3" json:"base_proposer_reward,omitempty"` + // Deprecated: The bonus_proposer_reward field is deprecated and is no longer used + // in the x/distribution module's reward mechanism. + // // Deprecated: Do not use. BonusProposerReward string `protobuf:"bytes,3,opt,name=bonus_proposer_reward,json=bonusProposerReward,proto3" json:"bonus_proposer_reward,omitempty"` WithdrawAddrEnabled bool `protobuf:"varint,4,opt,name=withdraw_addr_enabled,json=withdrawAddrEnabled,proto3" json:"withdraw_addr_enabled,omitempty"` diff --git a/proto/cosmos/distribution/v1beta1/distribution.proto b/proto/cosmos/distribution/v1beta1/distribution.proto index cbebaa14feec..9ffd6132fdb8 100644 --- a/proto/cosmos/distribution/v1beta1/distribution.proto +++ b/proto/cosmos/distribution/v1beta1/distribution.proto @@ -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", diff --git a/tests/e2e/distribution/suite.go b/tests/e2e/distribution/suite.go index eaab5a4c0a39..00b7884ab879 100644 --- a/tests/e2e/distribution/suite.go +++ b/tests/e2e/distribution/suite.go @@ -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`, }, diff --git a/tests/fixtures/adr-024-coin-metadata_genesis.json b/tests/fixtures/adr-024-coin-metadata_genesis.json index d56ed836fa89..ecedfd67cb7c 100644 --- a/tests/fixtures/adr-024-coin-metadata_genesis.json +++ b/tests/fixtures/adr-024-coin-metadata_genesis.json @@ -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": { diff --git a/tests/integration/distribution/keeper/common_test.go b/tests/integration/distribution/keeper/common_test.go index f5d7ff33b858..4ab7cead571a 100644 --- a/tests/integration/distribution/keeper/common_test.go +++ b/tests/integration/distribution/keeper/common_test.go @@ -15,7 +15,6 @@ var ( valConsPk2 = PKS[2] valConsAddr0 = sdk.ConsAddress(valConsPk0.Address()) - valConsAddr1 = sdk.ConsAddress(valConsPk1.Address()) distrAcc = authtypes.NewEmptyModuleAccount(types.ModuleName) ) diff --git a/tests/integration/distribution/keeper/grpc_query_test.go b/tests/integration/distribution/keeper/grpc_query_test.go index 594d319d5c1a..6074126b0956 100644 --- a/tests/integration/distribution/keeper/grpc_query_test.go +++ b/tests/integration/distribution/keeper/grpc_query_test.go @@ -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, } @@ -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) } diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index cdee1d04bdf4..7fd0963822ac 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -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 { @@ -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, @@ -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, @@ -57,69 +55,41 @@ 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", @@ -127,8 +97,8 @@ func (s *KeeperTestSuite) TestMsgUpdateParams() { Authority: s.distrKeeper.GetAuthority(), Params: types.Params{ CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, + BaseProposerReward: sdk.ZeroDec(), + BonusProposerReward: sdk.ZeroDec(), WithdrawAddrEnabled: withdrawAddrEnabled, }, }, diff --git a/tests/integration/distribution/keeper/params_test.go b/tests/integration/distribution/keeper/params_test.go deleted file mode 100644 index 16ae36d69fee..000000000000 --- a/tests/integration/distribution/keeper/params_test.go +++ /dev/null @@ -1,117 +0,0 @@ -package keeper_test - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/distribution/types" -) - -func (s *KeeperTestSuite) TestParams() { - // default params - communityTax := sdk.NewDecWithPrec(2, 2) // 2% - baseProposerReward := sdk.NewDecWithPrec(1, 2) // 1% - bonusProposerReward := sdk.NewDecWithPrec(4, 2) // 4% - withdrawAddrEnabled := true - - testCases := []struct { - name string - input types.Params - expErr bool - expErrMsg string - }{ - { - name: "community tax > 1", - input: types.Params{ - CommunityTax: sdk.NewDecWithPrec(2, 0), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "community tax should be non-negative and less than one", - }, - { - name: "negative community tax", - input: types.Params{ - CommunityTax: sdk.NewDecWithPrec(-2, 1), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "community tax should be non-negative and less than one", - }, - { - name: "base proposer reward > 1", - input: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: sdk.NewDecWithPrec(2, 0), - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "sum of base, bonus proposer rewards, and community tax cannot be greater than one", - }, - { - name: "negative base proposer reward", - input: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: sdk.NewDecWithPrec(-2, 0), - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "base proposer reward should be positive", - }, - { - name: "bonus proposer reward > 1", - input: 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.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: sdk.NewDecWithPrec(-2, 0), - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "bonus proposer reward should be positive", - }, - { - name: "all good", - input: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: false, - }, - } - - for _, tc := range testCases { - tc := tc - s.Run(tc.name, func() { - expected := s.distrKeeper.GetParams(s.ctx) - err := s.distrKeeper.SetParams(s.ctx, tc.input) - - if tc.expErr { - s.Require().Error(err) - s.Require().Contains(err.Error(), tc.expErrMsg) - } else { - expected = tc.input - s.Require().NoError(err) - } - - params := s.distrKeeper.GetParams(s.ctx) - s.Require().Equal(expected, params) - }) - } -} diff --git a/x/bank/simulation/genesis_test.go b/x/bank/simulation/genesis_test.go index 69e1a6923455..55d19f804977 100644 --- a/x/bank/simulation/genesis_test.go +++ b/x/bank/simulation/genesis_test.go @@ -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") diff --git a/x/distribution/README.md b/x/distribution/README.md index 52d3acbb601e..7b96e1ae2fbf 100644 --- a/x/distribution/README.md +++ b/x/distribution/README.md @@ -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 @@ -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 ``` @@ -781,8 +779,8 @@ Example Output: { "params": { "communityTax": "20000000000000000", - "baseProposerReward": "10000000000000000", - "bonusProposerReward": "40000000000000000", + "baseProposerReward": "00000000000000000", + "bonusProposerReward": "00000000000000000", "withdrawAddrEnabled": true } } diff --git a/x/distribution/keeper/msg_server.go b/x/distribution/keeper/msg_server.go index 5b81f256e339..f9e87eb8265c 100644 --- a/x/distribution/keeper/msg_server.go +++ b/x/distribution/keeper/msg_server.go @@ -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 diff --git a/x/distribution/keeper/params_test.go b/x/distribution/keeper/params_test.go index 46c433d41ddc..af4b40b68740 100644 --- a/x/distribution/keeper/params_test.go +++ b/x/distribution/keeper/params_test.go @@ -40,9 +40,7 @@ func TestParams(t *testing.T) { ) // 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 { @@ -55,8 +53,8 @@ func TestParams(t *testing.T) { name: "community tax > 1", input: types.Params{ CommunityTax: sdk.NewDecWithPrec(2, 0), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, + BaseProposerReward: sdk.ZeroDec(), + BonusProposerReward: sdk.ZeroDec(), WithdrawAddrEnabled: withdrawAddrEnabled, }, expErr: true, @@ -66,8 +64,8 @@ func TestParams(t *testing.T) { name: "negative community tax", input: types.Params{ CommunityTax: sdk.NewDecWithPrec(-2, 1), - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, + BaseProposerReward: sdk.ZeroDec(), + BonusProposerReward: sdk.ZeroDec(), WithdrawAddrEnabled: withdrawAddrEnabled, }, expErr: true, @@ -77,52 +75,30 @@ func TestParams(t *testing.T) { name: "base proposer reward > 1", input: 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", - }, - { - name: "negative base proposer reward", - input: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: sdk.NewDecWithPrec(-2, 0), - BonusProposerReward: bonusProposerReward, - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "base proposer reward should be positive", + expErr: false, + expErrMsg: "base proposer rewards should not be taken into account", }, { name: "bonus proposer reward > 1", input: types.Params{ CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: sdk.NewDecWithPrec(2, 0), + 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", - }, - { - name: "negative bonus proposer reward", - input: types.Params{ - CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: sdk.NewDecWithPrec(-2, 0), - WithdrawAddrEnabled: withdrawAddrEnabled, - }, - expErr: true, - expErrMsg: "bonus proposer reward should be positive", + expErr: false, + expErrMsg: "bonus proposer rewards should not be taken into account", }, { name: "all good", input: types.Params{ CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, + BaseProposerReward: sdk.ZeroDec(), + BonusProposerReward: sdk.ZeroDec(), WithdrawAddrEnabled: withdrawAddrEnabled, }, expErr: false, diff --git a/x/distribution/migrations/v3/json.go b/x/distribution/migrations/v3/json.go new file mode 100644 index 000000000000..21f5f1f45245 --- /dev/null +++ b/x/distribution/migrations/v3/json.go @@ -0,0 +1,18 @@ +package v3 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +// MigrateJSON accepts exported v2 (v0.46) x/distribution genesis state and migrates it to +// v3 (v0.47) x/distribution genesis state. The migration includes: +// +// Reset of the deprecated rewards to zero. +func MigrateJSON(oldState *types.GenesisState) *types.GenesisState { + // reset deprecated rewards to zero + oldState.Params.BaseProposerReward = sdk.ZeroDec() + oldState.Params.BonusProposerReward = sdk.ZeroDec() + + return oldState +} diff --git a/x/distribution/migrations/v3/json_test.go b/x/distribution/migrations/v3/json_test.go new file mode 100644 index 000000000000..41b969330b2f --- /dev/null +++ b/x/distribution/migrations/v3/json_test.go @@ -0,0 +1,64 @@ +package v3_test + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/client" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/distribution" + v3 "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v3" + "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +func TestMigrateJSON(t *testing.T) { + encodingConfig := moduletestutil.MakeTestEncodingConfig(distribution.AppModuleBasic{}) + clientCtx := client.Context{}. + WithInterfaceRegistry(encodingConfig.InterfaceRegistry). + WithTxConfig(encodingConfig.TxConfig). + WithCodec(encodingConfig.Codec) + + distrGenState := types.DefaultGenesisState() + + oldDistrState := distrGenState + oldDistrState.Params.BaseProposerReward = sdk.NewDecWithPrec(1, 2) + oldDistrState.Params.BonusProposerReward = sdk.NewDecWithPrec(4, 2) + + migrated := v3.MigrateJSON(oldDistrState) + require.Equal(t, migrated, distrGenState) + + bz, err := clientCtx.Codec.MarshalJSON(migrated) + require.NoError(t, err) + + // Indent the JSON bz correctly. + var jsonObj map[string]interface{} + err = json.Unmarshal(bz, &jsonObj) + require.NoError(t, err) + indentedBz, err := json.MarshalIndent(jsonObj, "", "\t") + require.NoError(t, err) + + expected := `{ + "delegator_starting_infos": [], + "delegator_withdraw_infos": [], + "fee_pool": { + "community_pool": [] + }, + "outstanding_rewards": [], + "params": { + "base_proposer_reward": "0.000000000000000000", + "bonus_proposer_reward": "0.000000000000000000", + "community_tax": "0.020000000000000000", + "withdraw_addr_enabled": true + }, + "previous_proposer": "", + "validator_accumulated_commissions": [], + "validator_current_rewards": [], + "validator_historical_rewards": [], + "validator_slash_events": [] +}` + + require.Equal(t, expected, string(indentedBz)) +} diff --git a/x/distribution/migrations/v3/migrate.go b/x/distribution/migrations/v3/migrate.go index d5e2f4086a07..9fd682b29980 100644 --- a/x/distribution/migrations/v3/migrate.go +++ b/x/distribution/migrations/v3/migrate.go @@ -23,6 +23,10 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace var currParams types.Params legacySubspace.GetParamSet(ctx, &currParams) + // reset unused params + currParams.BaseProposerReward = sdk.ZeroDec() + currParams.BonusProposerReward = sdk.ZeroDec() + if err := currParams.ValidateBasic(); err != nil { return err } diff --git a/x/distribution/simulation/genesis.go b/x/distribution/simulation/genesis.go index ddda98a939ce..5607f133beb4 100644 --- a/x/distribution/simulation/genesis.go +++ b/x/distribution/simulation/genesis.go @@ -13,10 +13,8 @@ import ( // Simulation parameter constants const ( - CommunityTax = "community_tax" - BaseProposerReward = "base_proposer_reward" - BonusProposerReward = "bonus_proposer_reward" - WithdrawEnabled = "withdraw_enabled" + CommunityTax = "community_tax" + WithdrawEnabled = "withdraw_enabled" ) // GenCommunityTax randomized CommunityTax @@ -24,16 +22,6 @@ func GenCommunityTax(r *rand.Rand) math.LegacyDec { return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2)) } -// GenBaseProposerReward randomized BaseProposerReward -func GenBaseProposerReward(r *rand.Rand) math.LegacyDec { - return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2)) -} - -// GenBonusProposerReward randomized BonusProposerReward -func GenBonusProposerReward(r *rand.Rand) math.LegacyDec { - return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2)) -} - // GenWithdrawEnabled returns a randomized WithdrawEnabled parameter. func GenWithdrawEnabled(r *rand.Rand) bool { return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled @@ -47,18 +35,6 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { communityTax = GenCommunityTax(r) }, ) - var baseProposerReward sdk.Dec - simState.AppParams.GetOrGenerate( - simState.Cdc, BaseProposerReward, &baseProposerReward, simState.Rand, - func(r *rand.Rand) { baseProposerReward = GenBaseProposerReward(r) }, - ) - - var bonusProposerReward sdk.Dec - simState.AppParams.GetOrGenerate( - simState.Cdc, BonusProposerReward, &bonusProposerReward, simState.Rand, - func(r *rand.Rand) { bonusProposerReward = GenBonusProposerReward(r) }, - ) - var withdrawEnabled bool simState.AppParams.GetOrGenerate( simState.Cdc, WithdrawEnabled, &withdrawEnabled, simState.Rand, @@ -69,8 +45,6 @@ func RandomizedGenState(simState *module.SimulationState) { FeePool: types.InitialFeePool(), Params: types.Params{ CommunityTax: communityTax, - BaseProposerReward: baseProposerReward, - BonusProposerReward: bonusProposerReward, WithdrawAddrEnabled: withdrawEnabled, }, } diff --git a/x/distribution/simulation/genesis_test.go b/x/distribution/simulation/genesis_test.go index 259f0512d7a0..14d4a067807f 100644 --- a/x/distribution/simulation/genesis_test.go +++ b/x/distribution/simulation/genesis_test.go @@ -40,13 +40,11 @@ func TestRandomizedGenState(t *testing.T) { var distrGenesis types.GenesisState simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &distrGenesis) - dec1, _ := sdk.NewDecFromStr("0.170000000000000000") - dec2, _ := sdk.NewDecFromStr("0.010000000000000000") - dec3, _ := sdk.NewDecFromStr("0.210000000000000000") + dec1, _ := sdk.NewDecFromStr("0.210000000000000000") - require.Equal(t, dec1, distrGenesis.Params.BaseProposerReward) - require.Equal(t, dec2, distrGenesis.Params.BonusProposerReward) - require.Equal(t, dec3, distrGenesis.Params.CommunityTax) + require.Equal(t, sdk.ZeroDec(), distrGenesis.Params.BaseProposerReward) //nolint:staticcheck + require.Equal(t, sdk.ZeroDec(), distrGenesis.Params.BonusProposerReward) //nolint:staticcheck + require.Equal(t, dec1, distrGenesis.Params.CommunityTax) require.Equal(t, true, distrGenesis.Params.WithdrawAddrEnabled) require.Len(t, distrGenesis.DelegatorStartingInfos, 0) require.Len(t, distrGenesis.DelegatorWithdrawInfos, 0) diff --git a/x/distribution/types/distribution.pb.go b/x/distribution/types/distribution.pb.go index c345762d3a58..044d1cd06d96 100644 --- a/x/distribution/types/distribution.pb.go +++ b/x/distribution/types/distribution.pb.go @@ -30,9 +30,11 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the set of params for the distribution module. type Params struct { CommunityTax github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=community_tax,json=communityTax,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"community_tax"` - // The base_proposer_reward and bonus_proposer_reward fields are deprecated - // and are no longer used in the x/distribution module's reward mechanism. - BaseProposerReward github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=base_proposer_reward,json=baseProposerReward,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"base_proposer_reward"` // Deprecated: Do not use. + // Deprecated: The base_proposer_reward field is deprecated and is no longer used + // in the x/distribution module's reward mechanism. + BaseProposerReward github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=base_proposer_reward,json=baseProposerReward,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"base_proposer_reward"` // Deprecated: Do not use. + // Deprecated: The bonus_proposer_reward field is deprecated and is no longer used + // in the x/distribution module's reward mechanism. BonusProposerReward github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=bonus_proposer_reward,json=bonusProposerReward,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"bonus_proposer_reward"` // Deprecated: Do not use. WithdrawAddrEnabled bool `protobuf:"varint,4,opt,name=withdraw_addr_enabled,json=withdrawAddrEnabled,proto3" json:"withdraw_addr_enabled,omitempty"` } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index 1e9e8f416e52..e13d1bdc506e 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -1,6 +1,8 @@ package types import ( + "errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -184,6 +186,11 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { // ValidateBasic performs basic MsgUpdateParams message validation. func (msg MsgUpdateParams) ValidateBasic() error { + if (!msg.Params.BaseProposerReward.IsNil() && !msg.Params.BaseProposerReward.IsZero()) || + (!msg.Params.BonusProposerReward.IsNil() && !msg.Params.BonusProposerReward.IsZero()) { + return errors.New("base and bonus proposer reward are deprecated fields and should not be used") + } + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", err) } diff --git a/x/distribution/types/params.go b/x/distribution/types/params.go index ea3739ea3725..6d13892dccee 100644 --- a/x/distribution/types/params.go +++ b/x/distribution/types/params.go @@ -12,8 +12,8 @@ import ( func DefaultParams() Params { return Params{ CommunityTax: sdk.NewDecWithPrec(2, 2), // 2% - BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1% - BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4% + BaseProposerReward: sdk.ZeroDec(), // deprecated + BonusProposerReward: sdk.ZeroDec(), // deprecated WithdrawAddrEnabled: true, } } @@ -25,21 +25,6 @@ func (p Params) ValidateBasic() error { "community tax should be non-negative and less than one: %s", p.CommunityTax, ) } - if p.BaseProposerReward.IsNegative() { - return fmt.Errorf( - "base proposer reward should be positive: %s", p.BaseProposerReward, - ) - } - if p.BonusProposerReward.IsNegative() { - return fmt.Errorf( - "bonus proposer reward should be positive: %s", p.BonusProposerReward, - ) - } - if v := p.BaseProposerReward.Add(p.BonusProposerReward).Add(p.CommunityTax); v.GT(math.LegacyOneDec()) { - return fmt.Errorf( - "sum of base, bonus proposer rewards, and community tax cannot be greater than one: %s", v, - ) - } return nil } @@ -63,44 +48,6 @@ func validateCommunityTax(i interface{}) error { return nil } -func validateBaseProposerReward(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() { - return fmt.Errorf("base proposer reward must be not nil") - } - if v.IsNegative() { - return fmt.Errorf("base proposer reward must be positive: %s", v) - } - if v.GT(math.LegacyOneDec()) { - return fmt.Errorf("base proposer reward too large: %s", v) - } - - return nil -} - -func validateBonusProposerReward(i interface{}) error { - v, ok := i.(sdk.Dec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - if v.IsNil() { - return fmt.Errorf("bonus proposer reward must be not nil") - } - if v.IsNegative() { - return fmt.Errorf("bonus proposer reward must be positive: %s", v) - } - if v.GT(math.LegacyOneDec()) { - return fmt.Errorf("bonus proposer reward too large: %s", v) - } - - return nil -} - func validateWithdrawAddrEnabled(i interface{}) error { _, ok := i.(bool) if !ok { diff --git a/x/distribution/types/params_internal_test.go b/x/distribution/types/params_internal_test.go index 55d846eaad1d..2ea34f965e10 100644 --- a/x/distribution/types/params_internal_test.go +++ b/x/distribution/types/params_internal_test.go @@ -28,8 +28,6 @@ func Test_validateAuxFuncs(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { require.Equal(t, tt.wantErr, validateCommunityTax(tt.args.i) != nil) - require.Equal(t, tt.wantErr, validateBaseProposerReward(tt.args.i) != nil) - require.Equal(t, tt.wantErr, validateBonusProposerReward(tt.args.i) != nil) }) } } diff --git a/x/distribution/types/params_legacy.go b/x/distribution/types/params_legacy.go index f82901383df1..26ebfc8b5d0e 100644 --- a/x/distribution/types/params_legacy.go +++ b/x/distribution/types/params_legacy.go @@ -5,8 +5,6 @@ import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" // Parameter keys var ( ParamStoreKeyCommunityTax = []byte("communitytax") - ParamStoreKeyBaseProposerReward = []byte("baseproposerreward") - ParamStoreKeyBonusProposerReward = []byte("bonusproposerreward") ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled") ) @@ -19,8 +17,6 @@ func ParamKeyTable() paramtypes.KeyTable { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(ParamStoreKeyCommunityTax, &p.CommunityTax, validateCommunityTax), - paramtypes.NewParamSetPair(ParamStoreKeyBaseProposerReward, &p.BaseProposerReward, validateBaseProposerReward), - paramtypes.NewParamSetPair(ParamStoreKeyBonusProposerReward, &p.BonusProposerReward, validateBonusProposerReward), paramtypes.NewParamSetPair(ParamStoreKeyWithdrawAddrEnabled, &p.WithdrawAddrEnabled, validateWithdrawAddrEnabled), } } diff --git a/x/distribution/types/params_test.go b/x/distribution/types/params_test.go index d156df728d65..e58e8e2065dc 100644 --- a/x/distribution/types/params_test.go +++ b/x/distribution/types/params_test.go @@ -23,18 +23,17 @@ func TestParams_ValidateBasic(t *testing.T) { fields fields wantErr bool }{ - {"success", fields{toDec("0.1"), toDec("0.5"), toDec("0.4"), false}, false}, - {"negative community tax", fields{toDec("-0.1"), toDec("0.5"), toDec("0.4"), false}, true}, - {"negative base proposer reward", fields{toDec("0.1"), toDec("-0.5"), toDec("0.4"), false}, true}, - {"negative bonus proposer reward", fields{toDec("0.1"), toDec("0.5"), toDec("-0.4"), false}, true}, - {"total sum greater than 1", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, true}, + {"success", fields{toDec("0.1"), toDec("0"), toDec("0"), false}, false}, + {"negative community tax", fields{toDec("-0.1"), toDec("0"), toDec("0"), false}, true}, + {"negative base proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, + {"negative bonus proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false}, + {"total sum greater than 1 (must not matter)", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, false}, + {"community tax greater than 1", fields{toDec("1.1"), toDec("0"), toDec("0"), false}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { p := types.Params{ CommunityTax: tt.fields.CommunityTax, - BaseProposerReward: tt.fields.BaseProposerReward, - BonusProposerReward: tt.fields.BonusProposerReward, WithdrawAddrEnabled: tt.fields.WithdrawAddrEnabled, } if err := p.ValidateBasic(); (err != nil) != tt.wantErr { diff --git a/x/genutil/migrations/v047/migrate.go b/x/genutil/migrations/v047/migrate.go index 8bfdff608a93..0e3512257aae 100644 --- a/x/genutil/migrations/v047/migrate.go +++ b/x/genutil/migrations/v047/migrate.go @@ -6,6 +6,9 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankv4 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v4" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + v1distr "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v1" + v3distr "github.com/cosmos/cosmos-sdk/x/distribution/migrations/v3" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" v4gov "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -47,5 +50,13 @@ func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap { appState[v1auth.ModuleName] = clientCtx.Codec.MustMarshalJSON(newAuthState) } + // Migrate x/distribution params (reset unused) + if oldDistState, ok := appState[v1distr.ModuleName]; ok { + var old distrtypes.GenesisState + clientCtx.Codec.MustUnmarshalJSON(oldDistState, &old) + newDistState := v3distr.MigrateJSON(&old) + appState[v1distr.ModuleName] = clientCtx.Codec.MustMarshalJSON(newDistState) + } + return appState }