From 547fbbbb060b613eed7a23ea51bf24e2b40e7ff8 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Wed, 13 Nov 2024 21:45:21 +0100 Subject: [PATCH] [Tokenomics] refactor: `MintAllocationApplication` var usage to param usage (#918) ## Summary - Replace usage of tokenomicskeeper.MintAllocationSupplier with the new param and delete it. - Add disable_individual_update tag to tokenomics params fields for use in integration testing - Eliminate untestable scenarios - revert temporary begin blocker validation ## Issue - `TODO_BETA` ## Type of change Select one or more from the following: - [ ] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [x] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [ ] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --------- Co-authored-by: Redouane Lakrache --- api/poktroll/proof/tx.pulsar.go | 4 +- api/poktroll/tokenomics/params.pulsar.go | 2 +- tests/integration/params/update_param_test.go | 14 +- testutil/integration/suites/param_configs.go | 10 ++ x/tokenomics/keeper/keeper.go | 16 --- .../keeper/msg_server_update_param.go | 16 +-- .../keeper/msg_server_update_param_test.go | 122 +----------------- x/tokenomics/keeper/msg_update_params_test.go | 24 ++-- x/tokenomics/keeper/token_logic_modules.go | 6 +- .../keeper/token_logic_modules_test.go | 15 +-- x/tokenomics/module/abci.go | 14 -- x/tokenomics/module/helpers_test.go | 2 + x/tokenomics/module/module.go | 4 +- x/tokenomics/module/tx_update_params.go | 4 +- x/tokenomics/module/tx_update_params_test.go | 63 --------- x/tokenomics/types/genesis_test.go | 10 +- .../types/message_update_params_test.go | 26 +++- x/tokenomics/types/params.go | 19 +++ x/tokenomics/types/params.pb.go | 2 +- 19 files changed, 115 insertions(+), 258 deletions(-) delete mode 100644 x/tokenomics/module/tx_update_params_test.go diff --git a/api/poktroll/proof/tx.pulsar.go b/api/poktroll/proof/tx.pulsar.go index cc72dd116..9b5ab2fb2 100644 --- a/api/poktroll/proof/tx.pulsar.go +++ b/api/poktroll/proof/tx.pulsar.go @@ -5,13 +5,13 @@ import ( _ "cosmossdk.io/api/amino" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" _ "cosmossdk.io/api/cosmos/msg/v1" + session "github.com/pokt-network/poktroll/api/poktroll/session" + _ "github.com/pokt-network/poktroll/api/poktroll/shared" binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-proto" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" - session "github.com/pokt-network/poktroll/api/poktroll/session" - _ "github.com/pokt-network/poktroll/api/poktroll/shared" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" diff --git a/api/poktroll/tokenomics/params.pulsar.go b/api/poktroll/tokenomics/params.pulsar.go index f31b520e6..d9578f45f 100644 --- a/api/poktroll/tokenomics/params.pulsar.go +++ b/api/poktroll/tokenomics/params.pulsar.go @@ -609,7 +609,7 @@ type Params struct { // to the service source owner account address during claim settlement. MintAllocationSourceOwner float64 `protobuf:"fixed64,4,opt,name=mint_allocation_source_owner,json=mintAllocationSourceOwner,proto3" json:"mint_allocation_source_owner,omitempty"` // mint_allocation_application is the percentage of the minted tokens which are sent - // to the service source owner account address during claim settlement. + // to the application account address during claim settlement. MintAllocationApplication float64 `protobuf:"fixed64,5,opt,name=mint_allocation_application,json=mintAllocationApplication,proto3" json:"mint_allocation_application,omitempty"` } diff --git a/tests/integration/params/update_param_test.go b/tests/integration/params/update_param_test.go index 3110ddcf2..064ae7239 100644 --- a/tests/integration/params/update_param_test.go +++ b/tests/integration/params/update_param_test.go @@ -51,9 +51,14 @@ func (s *msgUpdateParamTestSuite) TestUnauthorizedMsgUpdateParamFails() { // to that field's value. validParamsValue := reflect.ValueOf(moduleCfg.ValidParams) for fieldIdx := 0; fieldIdx < validParamsValue.NumField(); fieldIdx++ { - fieldValue := validParamsValue.Field(fieldIdx) + validParamsFieldValue := validParamsValue.Field(fieldIdx) fieldName := validParamsValue.Type().Field(fieldIdx).Name + // Skip fields which in the excludedParams map. + if _, ok := suites.ExcludedParams[fieldName]; ok { + continue + } + testName := fmt.Sprintf("%s_%s", moduleName, fieldName) s.T().Run(testName, func(t *testing.T) { // Reset the app state in order to assert that each module @@ -66,7 +71,7 @@ func (s *msgUpdateParamTestSuite) TestUnauthorizedMsgUpdateParamFails() { updateResBz, err := s.RunUpdateParamAsSigner(t, moduleName, fieldName, - fieldValue.Interface(), + validParamsFieldValue.Interface(), s.unauthorizedAddr, ) require.ErrorContains(t, err, authz.ErrNoAuthorizationFound.Error()) @@ -88,6 +93,11 @@ func (s *msgUpdateParamTestSuite) TestAuthorizedMsgUpdateParamSucceeds() { fieldExpectedValue := validParamsValue.Field(fieldIdx) fieldName := validParamsValue.Type().Field(fieldIdx).Name + // Skip fields which in the excludedParams map. + if _, ok := suites.ExcludedParams[fieldName]; ok { + continue + } + testName := fmt.Sprintf("%s_%s", moduleName, fieldName) s.T().Run(testName, func(t *testing.T) { // Reset the app state in order to assert that each module diff --git a/testutil/integration/suites/param_configs.go b/testutil/integration/suites/param_configs.go index 27f72ac4d..dd8c548da 100644 --- a/testutil/integration/suites/param_configs.go +++ b/testutil/integration/suites/param_configs.go @@ -29,6 +29,16 @@ const ( ParamTypeCoin ParamType = "Coin" ) +// TODO_UPNEXT(@bryanchriswhite): Promote mint_allocation_XXX params to +// a new mint_allocation message type. This map will no longer be needed +var ExcludedParams = map[string]struct{}{ + "MintAllocationDao": {}, + "MintAllocationProposer": {}, + "MintAllocationSupplier": {}, + "MintAllocationSourceOwner": {}, + "MintAllocationApplication": {}, +} + // ModuleParamConfig holds type information about a module's parameters update // message(s) along with default and valid non-default values and a query constructor // function for the module. It is used by ParamsSuite to construct and send diff --git a/x/tokenomics/keeper/keeper.go b/x/tokenomics/keeper/keeper.go index 648f828e5..c21be050f 100644 --- a/x/tokenomics/keeper/keeper.go +++ b/x/tokenomics/keeper/keeper.go @@ -1,7 +1,6 @@ package keeper import ( - "context" "fmt" "cosmossdk.io/core/store" @@ -85,18 +84,3 @@ func (k Keeper) Logger() log.Logger { func (k Keeper) GetAuthority() string { return k.authority } - -// MintAllocationsSum returns the sum of all mint allocation percentages. -func (k Keeper) MintAllocationsSum(ctx context.Context) float64 { - params := k.GetParams(ctx) - mintAllocationDAO := params.GetMintAllocationDao() - mintAllocationProposer := params.GetMintAllocationProposer() - mintAllocationSupplier := params.GetMintAllocationSupplier() - mintAllocationSourceOwner := params.GetMintAllocationSourceOwner() - - return mintAllocationDAO + - mintAllocationProposer + - mintAllocationSupplier + - mintAllocationSourceOwner + - MintAllocationApplication -} diff --git a/x/tokenomics/keeper/msg_server_update_param.go b/x/tokenomics/keeper/msg_server_update_param.go index a7cc7269b..6ce663fb5 100644 --- a/x/tokenomics/keeper/msg_server_update_param.go +++ b/x/tokenomics/keeper/msg_server_update_param.go @@ -33,20 +33,16 @@ func (k msgServer) UpdateParam( switch msg.Name { case tokenomicstypes.ParamMintAllocationDao: - logger = logger.With("param_value", msg.GetAsFloat()) - params.MintAllocationDao = msg.GetAsFloat() case tokenomicstypes.ParamMintAllocationProposer: - logger = logger.With("param_value", msg.GetAsFloat()) - params.MintAllocationProposer = msg.GetAsFloat() case tokenomicstypes.ParamMintAllocationSupplier: - logger = logger.With("param_value", msg.GetAsFloat()) - params.MintAllocationSupplier = msg.GetAsFloat() case tokenomicstypes.ParamMintAllocationSourceOwner: - logger = logger.With("param_value", msg.GetAsFloat()) - params.MintAllocationSourceOwner = msg.GetAsFloat() case tokenomicstypes.ParamMintAllocationApplication: - logger = logger.With("param_value", msg.GetAsFloat()) - params.MintAllocationApplication = msg.GetAsFloat() + return nil, status.Error( + codes.InvalidArgument, + tokenomicstypes.ErrTokenomicsParamInvalid.Wrapf( + "%s cannot be updated individually as all mint allocation percentages MUST ALWAYS sum to 1", msg.Name, + ).Error(), + ) default: return nil, status.Error( codes.InvalidArgument, diff --git a/x/tokenomics/keeper/msg_server_update_param_test.go b/x/tokenomics/keeper/msg_server_update_param_test.go index 36751a95c..84ee340f6 100644 --- a/x/tokenomics/keeper/msg_server_update_param_test.go +++ b/x/tokenomics/keeper/msg_server_update_param_test.go @@ -2,136 +2,24 @@ package keeper_test import ( "testing" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/stretchr/testify/require" - - testkeeper "github.com/pokt-network/poktroll/testutil/keeper" - tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) func TestMsgUpdateParam_UpdateMintAllocationDaoOnly(t *testing.T) { - var expectedMintAllocationDao float64 = 3.14159 - - // Set the parameters to their default values - k, msgSrv, ctx := setupMsgServer(t) - defaultParams := tokenomicstypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) - - // Ensure the default values are different from the new values we want to set - require.NotEqual(t, expectedMintAllocationDao, defaultParams.MintAllocationDao) - - // Update the new parameter - updateParamMsg := &tokenomicstypes.MsgUpdateParam{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.ParamMintAllocationDao, - AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationDao}, - } - res, err := msgSrv.UpdateParam(ctx, updateParamMsg) - require.NoError(t, err) - require.Equal(t, expectedMintAllocationDao, res.Params.MintAllocationDao) - - // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationDao)) + t.Skip("since the mint allocation percentages must sum to 1, it is not possible to modify only one of them") } func TestMsgUpdateParam_UpdateMintAllocationProposerOnly(t *testing.T) { - var expectedMintAllocationProposer float64 = 3.14159 - - // Set the parameters to their default values - k, msgSrv, ctx := setupMsgServer(t) - defaultParams := tokenomicstypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) - - // Ensure the default values are different from the new values we want to set - require.NotEqual(t, expectedMintAllocationProposer, defaultParams.MintAllocationProposer) - - // Update the new parameter - updateParamMsg := &tokenomicstypes.MsgUpdateParam{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.ParamMintAllocationProposer, - AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationProposer}, - } - res, err := msgSrv.UpdateParam(ctx, updateParamMsg) - require.NoError(t, err) - require.Equal(t, expectedMintAllocationProposer, res.Params.MintAllocationProposer) - - // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationProposer)) + t.Skip("since the mint allocation percentages must sum to 1, it is not possible to modify only one of them") } func TestMsgUpdateParam_UpdateMintAllocationSupplierOnly(t *testing.T) { - var expectedMintAllocationSupplier float64 = 3.14159 - - // Set the parameters to their default values - k, msgSrv, ctx := setupMsgServer(t) - defaultParams := tokenomicstypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) - - // Ensure the default values are different from the new values we want to set - require.NotEqual(t, expectedMintAllocationSupplier, defaultParams.MintAllocationSupplier) - - // Update the new parameter - updateParamMsg := &tokenomicstypes.MsgUpdateParam{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.ParamMintAllocationSupplier, - AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationSupplier}, - } - res, err := msgSrv.UpdateParam(ctx, updateParamMsg) - require.NoError(t, err) - require.Equal(t, expectedMintAllocationSupplier, res.Params.MintAllocationSupplier) - - // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationSupplier)) + t.Skip("since the mint allocation percentages must sum to 1, it is not possible to modify only one of them") } func TestMsgUpdateParam_UpdateMintAllocationSourceOwnerOnly(t *testing.T) { - var expectedMintAllocationSourceOwner float64 = 3.14159 - - // Set the parameters to their default values - k, msgSrv, ctx := setupMsgServer(t) - defaultParams := tokenomicstypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) - - // Ensure the default values are different from the new values we want to set - require.NotEqual(t, expectedMintAllocationSourceOwner, defaultParams.MintAllocationSourceOwner) - - // Update the new parameter - updateParamMsg := &tokenomicstypes.MsgUpdateParam{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.ParamMintAllocationSourceOwner, - AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationSourceOwner}, - } - res, err := msgSrv.UpdateParam(ctx, updateParamMsg) - require.NoError(t, err) - require.Equal(t, expectedMintAllocationSourceOwner, res.Params.MintAllocationSourceOwner) - - // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationSourceOwner)) + t.Skip("since the mint allocation percentages must sum to 1, it is not possible to modify only one of them") } func TestMsgUpdateParam_UpdateMintAllocationApplicationOnly(t *testing.T) { - var expectedMintAllocationApplication float64 = 3.14159 - - // Set the parameters to their default values - k, msgSrv, ctx := setupMsgServer(t) - defaultParams := tokenomicstypes.DefaultParams() - require.NoError(t, k.SetParams(ctx, defaultParams)) - - // Ensure the default values are different from the new values we want to set - require.NotEqual(t, expectedMintAllocationApplication, defaultParams.MintAllocationApplication) - - // Update the new parameter - updateParamMsg := &tokenomicstypes.MsgUpdateParam{ - Authority: authtypes.NewModuleAddress(govtypes.ModuleName).String(), - Name: tokenomicstypes.ParamMintAllocationApplication, - AsType: &tokenomicstypes.MsgUpdateParam_AsFloat{AsFloat: expectedMintAllocationApplication}, - } - res, err := msgSrv.UpdateParam(ctx, updateParamMsg) - require.NoError(t, err) - require.Equal(t, expectedMintAllocationApplication, res.Params.MintAllocationApplication) - - // Ensure the other parameters are unchanged - testkeeper.AssertDefaultParamsEqualExceptFields(t, &defaultParams, res.Params, string(tokenomicstypes.KeyMintAllocationApplication)) + t.Skip("since the mint allocation percentages must sum to 1, it is not possible to modify only one of them") } diff --git a/x/tokenomics/keeper/msg_update_params_test.go b/x/tokenomics/keeper/msg_update_params_test.go index a112ec5d8..b6518bce3 100644 --- a/x/tokenomics/keeper/msg_update_params_test.go +++ b/x/tokenomics/keeper/msg_update_params_test.go @@ -6,17 +6,17 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/sample" - "github.com/pokt-network/poktroll/x/tokenomics/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) func TestMsgUpdateParams(t *testing.T) { tokenomicsKeeper, srv, ctx := setupMsgServer(t) - require.NoError(t, tokenomicsKeeper.SetParams(ctx, types.DefaultParams())) + require.NoError(t, tokenomicsKeeper.SetParams(ctx, tokenomicstypes.DefaultParams())) tests := []struct { desc string - req *types.MsgUpdateParams + req *tokenomicstypes.MsgUpdateParams shouldError bool expectedErrMsg string @@ -24,9 +24,9 @@ func TestMsgUpdateParams(t *testing.T) { { desc: "invalid authority address", - req: &types.MsgUpdateParams{ + req: &tokenomicstypes.MsgUpdateParams{ Authority: "invalid", - Params: types.Params{}, + Params: tokenomicstypes.DefaultParams(), }, shouldError: true, @@ -35,9 +35,9 @@ func TestMsgUpdateParams(t *testing.T) { { desc: "incorrect authority address", - req: &types.MsgUpdateParams{ + req: &tokenomicstypes.MsgUpdateParams{ Authority: sample.AccAddress(), - Params: types.Params{}, + Params: tokenomicstypes.DefaultParams(), }, shouldError: true, @@ -46,9 +46,15 @@ func TestMsgUpdateParams(t *testing.T) { { desc: "successful param update", - req: &types.MsgUpdateParams{ + req: &tokenomicstypes.MsgUpdateParams{ Authority: tokenomicsKeeper.GetAuthority(), - Params: types.Params{}, + Params: tokenomicstypes.Params{ + MintAllocationDao: 0.1, + MintAllocationProposer: 0.1, + MintAllocationSupplier: 0.1, + MintAllocationSourceOwner: 0.1, + MintAllocationApplication: 0.6, + }, }, shouldError: false, diff --git a/x/tokenomics/keeper/token_logic_modules.go b/x/tokenomics/keeper/token_logic_modules.go index c57aa0165..7968579c9 100644 --- a/x/tokenomics/keeper/token_logic_modules.go +++ b/x/tokenomics/keeper/token_logic_modules.go @@ -33,9 +33,6 @@ var ( ) const ( - // TODO_BETA(@bryanchriswhite): Make all of these governance params - MintAllocationApplication = 0.0 - // MintDistributionAllowableTolerancePercent is the percent difference that is allowable // between the number of minted/ tokens in the tokenomics module and what is distributed // to pocket network participants. @@ -449,7 +446,8 @@ func (k Keeper) TokenLogicModuleGlobalMint( logger.Info(fmt.Sprintf("minted (%s) to the tokenomics module account", newMintCoin)) // Send a portion of the rewards to the application - appCoin, err := k.sendRewardsToAccount(ctx, tokenomicstypes.ModuleName, application.GetAddress(), &newMintAmtFloat, MintAllocationApplication) + mintAllocationApplication := k.GetParams(ctx).MintAllocationApplication + appCoin, err := k.sendRewardsToAccount(ctx, tokenomicstypes.ModuleName, application.GetAddress(), &newMintAmtFloat, mintAllocationApplication) if err != nil { return tokenomicstypes.ErrTokenomicsSendingMintRewards.Wrapf("sending rewards to application: %v", err) } diff --git a/x/tokenomics/keeper/token_logic_modules_test.go b/x/tokenomics/keeper/token_logic_modules_test.go index 8e3cd4904..a2d6fdf30 100644 --- a/x/tokenomics/keeper/token_logic_modules_test.go +++ b/x/tokenomics/keeper/token_logic_modules_test.go @@ -400,17 +400,14 @@ func TestProcessTokenLogicModules_TLMGlobalMint_Valid_MintDistributionCorrect(t } // Compute mint per actor - mintAllocationDao := keepers.Keeper.GetParams(ctx).MintAllocationDao - mintAllocationProposer := keepers.Keeper.GetParams(ctx).MintAllocationProposer - mintAllocationSupplier := keepers.Keeper.GetParams(ctx).MintAllocationSupplier - mintAllocationSourceOwner := keepers.Keeper.GetParams(ctx).MintAllocationSourceOwner + tokenomicsParams := keepers.Keeper.GetParams(ctx) numTokensMinted := numTokensClaimed * tokenomicskeeper.GlobalInflationPerClaim numTokensMintedInt := cosmosmath.NewIntFromUint64(uint64(numTokensMinted)) - daoMint := cosmosmath.NewInt(int64(numTokensMinted * mintAllocationDao)) - propMint := cosmosmath.NewInt(int64(numTokensMinted * mintAllocationProposer)) - serviceOwnerMint := cosmosmath.NewInt(int64(numTokensMinted * mintAllocationSourceOwner)) - appMint := cosmosmath.NewInt(int64(numTokensMinted * tokenomicskeeper.MintAllocationApplication)) - supplierMint := float32(numTokensMinted * mintAllocationSupplier) + daoMint := cosmosmath.NewInt(int64(numTokensMinted * tokenomicsParams.MintAllocationDao)) + propMint := cosmosmath.NewInt(int64(numTokensMinted * tokenomicsParams.MintAllocationProposer)) + serviceOwnerMint := cosmosmath.NewInt(int64(numTokensMinted * tokenomicsParams.MintAllocationSourceOwner)) + appMint := cosmosmath.NewInt(int64(numTokensMinted * tokenomicsParams.MintAllocationApplication)) + supplierMint := float32(numTokensMinted * tokenomicsParams.MintAllocationSupplier) // Ensure the balance was increase be the appropriate amount require.Equal(t, daoBalanceBefore.Amount.Add(daoMint).Add(numTokensMintedInt), daoBalanceAfter.Amount) diff --git a/x/tokenomics/module/abci.go b/x/tokenomics/module/abci.go index 4087c601d..fc0776c68 100644 --- a/x/tokenomics/module/abci.go +++ b/x/tokenomics/module/abci.go @@ -1,7 +1,6 @@ package tokenomics import ( - "context" "fmt" cosmostelemetry "github.com/cosmos/cosmos-sdk/telemetry" @@ -13,19 +12,6 @@ import ( "github.com/pokt-network/poktroll/x/tokenomics/types" ) -// BeginBlocker called at the start of every block. -// -// TODO_UPNEXT(@bryanchriswhite): Revert the addition of this and move this check into the -// tokenomics module ParamsValidateBasic() method once all allocation params are available. -func BeginBlocker(ctx context.Context, k keeper.Keeper) error { - // Ensure 100% of minted rewards are allocated - if 1.0 != k.MintAllocationsSum(ctx) { - return fmt.Errorf("mint allocation percentages do not add to 1.0") - } - - return nil -} - // EndBlocker called at every block and settles all pending claims. func EndBlocker(ctx sdk.Context, k keeper.Keeper) (err error) { // Telemetry: measure the end-block execution time following standard cosmos-sdk practices. diff --git a/x/tokenomics/module/helpers_test.go b/x/tokenomics/module/helpers_test.go index 63545283c..3d71c0a71 100644 --- a/x/tokenomics/module/helpers_test.go +++ b/x/tokenomics/module/helpers_test.go @@ -16,6 +16,8 @@ var _ = strconv.IntSize // networkWithDefaultConfig is a helper function to create a network for testing // with a default tokenomics genesis state. +// +//lint:ignore U1000 Ignore unused function for testing purposes func networkWithDefaultConfig(t *testing.T) *network.Network { t.Helper() cfg := network.DefaultConfig() diff --git a/x/tokenomics/module/module.go b/x/tokenomics/module/module.go index 26d4e0adb..d6c79ce91 100644 --- a/x/tokenomics/module/module.go +++ b/x/tokenomics/module/module.go @@ -147,8 +147,8 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block. // The begin block implementation is optional. -func (am AppModule) BeginBlock(ctx context.Context) error { - return BeginBlocker(ctx, am.tokenomicsKeeper) +func (am AppModule) BeginBlock(_ context.Context) error { + return nil } // EndBlock contains the logic that is automatically triggered at the end of each block. diff --git a/x/tokenomics/module/tx_update_params.go b/x/tokenomics/module/tx_update_params.go index 43aae6072..d36dc4525 100644 --- a/x/tokenomics/module/tx_update_params.go +++ b/x/tokenomics/module/tx_update_params.go @@ -13,7 +13,9 @@ import ( var _ = strconv.Itoa(0) -// TODO_POST_MAINNET(@bryanchriswhite, #322): Update the CLI once we determine settle on how to maintain and update parameters. +// TODO_UPNEXT(@bryanchriswhite): Remove this. It's not used nor useful. +// Parameter updates currently happen via authz exec messages and in the +// future will be committed via governance proposals. func CmdUpdateParams() *cobra.Command { cmd := &cobra.Command{ Use: "update-params", diff --git a/x/tokenomics/module/tx_update_params_test.go b/x/tokenomics/module/tx_update_params_test.go deleted file mode 100644 index c21dca4f8..000000000 --- a/x/tokenomics/module/tx_update_params_test.go +++ /dev/null @@ -1,63 +0,0 @@ -package tokenomics_test - -import ( - "fmt" - "testing" - - cometcli "github.com/cometbft/cometbft/libs/cli" - "github.com/cosmos/cosmos-sdk/client/flags" - clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/gogo/status" - "github.com/stretchr/testify/require" - - "github.com/pokt-network/poktroll/testutil/network" - tokenomics "github.com/pokt-network/poktroll/x/tokenomics/module" -) - -func TestCLI_UpdateParams(t *testing.T) { - net := networkWithDefaultConfig(t) - ctx := net.Validators[0].ClientCtx - - common := []string{ - fmt.Sprintf("--%s=json", cometcli.OutputFlag), - fmt.Sprintf("--%s=%s", flags.FlagFrom, net.Validators[0].Address.String()), - fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), - fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, network.NewBondDenomCoins(t, net, 10)), - } - - tests := []struct { - desc string - args []string - expectedErr error - expectedExtraErrMsg string - }{ - { - desc: "valid update of all params", - args: []string{}, - expectedErr: nil, - }, - } - - for _, test := range tests { - t.Run(test.desc, func(t *testing.T) { - args := append(common, test.args...) - out, err := clitestutil.ExecTestCLICmd(ctx, tokenomics.CmdUpdateParams(), args) - if test.expectedErr != nil { - _, ok := status.FromError(test.expectedErr) - require.True(t, ok) - require.ErrorIs(t, err, test.expectedErr) - require.Contains(t, err.Error(), test.expectedExtraErrMsg) - } else { - require.NoError(t, err) - var resp sdk.TxResponse - require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) - require.NotNil(t, resp) - require.NotNil(t, resp.TxHash) - // You can reference Cosmos SDK error codes here: https://github.com/cosmos/cosmos-sdk/blob/main/types/errors/errors.go - require.Equal(t, uint32(0), resp.Code, "tx response failed: %v", resp) - } - }) - } -} diff --git a/x/tokenomics/types/genesis_test.go b/x/tokenomics/types/genesis_test.go index 0e84dc6be..94360494c 100644 --- a/x/tokenomics/types/genesis_test.go +++ b/x/tokenomics/types/genesis_test.go @@ -5,24 +5,24 @@ import ( "github.com/stretchr/testify/require" - "github.com/pokt-network/poktroll/x/tokenomics/types" + tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) func TestGenesisState_Validate(t *testing.T) { tests := []struct { desc string - genState *types.GenesisState + genState *tokenomicstypes.GenesisState isValid bool }{ { desc: "default is valid", - genState: types.DefaultGenesis(), + genState: tokenomicstypes.DefaultGenesis(), isValid: true, }, { desc: "valid genesis state", - genState: &types.GenesisState{ - Params: types.Params{}, + genState: &tokenomicstypes.GenesisState{ + Params: tokenomicstypes.DefaultParams(), // this line is used by starport scaffolding # types/genesis/validField }, isValid: true, diff --git a/x/tokenomics/types/message_update_params_test.go b/x/tokenomics/types/message_update_params_test.go index 914051b92..76396bbf5 100644 --- a/x/tokenomics/types/message_update_params_test.go +++ b/x/tokenomics/types/message_update_params_test.go @@ -15,7 +15,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { expectedErr error }{ { - desc: "invalid authority address", + desc: "invalid: non-bech32 authority address", msg: MsgUpdateParams{ Authority: "invalid_address", Params: Params{}, @@ -23,11 +23,33 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) { expectedErr: ErrTokenomicsAddressInvalid, }, { - desc: "valid address", + desc: "invalid: empty params", msg: MsgUpdateParams{ Authority: sample.AccAddress(), Params: Params{}, }, + expectedErr: ErrTokenomicsParamInvalid, + }, + { + desc: "valid: address and default params", + msg: MsgUpdateParams{ + Authority: sample.AccAddress(), + Params: DefaultParams(), + }, + }, + { + desc: "invalid: mint allocation params don't sum to 1", + msg: MsgUpdateParams{ + Authority: sample.AccAddress(), + Params: Params{ + MintAllocationDao: 0.1, + MintAllocationProposer: 0.1, + MintAllocationSupplier: 0.1, + MintAllocationSourceOwner: 0.1, + MintAllocationApplication: 0.1, + }, + }, + expectedErr: ErrTokenomicsParamInvalid, }, } diff --git a/x/tokenomics/types/params.go b/x/tokenomics/types/params.go index cb4f5f082..7ae0c0335 100644 --- a/x/tokenomics/types/params.go +++ b/x/tokenomics/types/params.go @@ -110,6 +110,10 @@ func (params *Params) ValidateBasic() error { return err } + if err := ValidateMintAllocationSum(params); err != nil { + return err + } + return nil } @@ -182,3 +186,18 @@ func ValidateMintAllocationApplication(mintAllocationApplication any) error { return nil } + +// ValidateMintAllocationSum validates that the sum of all actor mint allocations is exactly 1. +func ValidateMintAllocationSum(params *Params) error { + sum := params.MintAllocationDao + + params.MintAllocationProposer + + params.MintAllocationSupplier + + params.MintAllocationSourceOwner + + params.MintAllocationApplication + + if sum != 1 { + return ErrTokenomicsParamInvalid.Wrapf("mint allocation percentages do not add to 1.0: got %f", sum) + } + + return nil +} diff --git a/x/tokenomics/types/params.pb.go b/x/tokenomics/types/params.pb.go index 26eeca14d..7c59416cb 100644 --- a/x/tokenomics/types/params.pb.go +++ b/x/tokenomics/types/params.pb.go @@ -40,7 +40,7 @@ type Params struct { // to the service source owner account address during claim settlement. MintAllocationSourceOwner float64 `protobuf:"fixed64,4,opt,name=mint_allocation_source_owner,json=mintAllocationSourceOwner,proto3" json:"mint_allocation_source_owner" yaml:"mint_allocation_source_owner"` // mint_allocation_application is the percentage of the minted tokens which are sent - // to the service source owner account address during claim settlement. + // to the application account address during claim settlement. MintAllocationApplication float64 `protobuf:"fixed64,5,opt,name=mint_allocation_application,json=mintAllocationApplication,proto3" json:"mint_allocation_application" yaml:"mint_allocation_application"` }