Skip to content

Commit

Permalink
[Tokenomics] refactor: MintAllocationApplication var usage to param…
Browse files Browse the repository at this point in the history
… 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 <r3d0ne@gmail.com>
  • Loading branch information
bryanchriswhite and red-0ne authored Nov 13, 2024
1 parent 9ce532b commit 547fbbb
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 258 deletions.
4 changes: 2 additions & 2 deletions api/poktroll/proof/tx.pulsar.go

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

2 changes: 1 addition & 1 deletion api/poktroll/tokenomics/params.pulsar.go

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

14 changes: 12 additions & 2 deletions tests/integration/params/update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions testutil/integration/suites/param_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions x/tokenomics/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"context"
"fmt"

"cosmossdk.io/core/store"
Expand Down Expand Up @@ -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
}
16 changes: 6 additions & 10 deletions x/tokenomics/keeper/msg_server_update_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
122 changes: 5 additions & 117 deletions x/tokenomics/keeper/msg_server_update_param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
24 changes: 15 additions & 9 deletions x/tokenomics/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ 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
}{
{
desc: "invalid authority address",

req: &types.MsgUpdateParams{
req: &tokenomicstypes.MsgUpdateParams{
Authority: "invalid",
Params: types.Params{},
Params: tokenomicstypes.DefaultParams(),
},

shouldError: true,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions x/tokenomics/keeper/token_logic_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 6 additions & 9 deletions x/tokenomics/keeper/token_logic_modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 547fbbb

Please sign in to comment.