Skip to content

Commit

Permalink
chore: deprecated params module (#128)
Browse files Browse the repository at this point in the history
* chore: deprecate x/param in xpla module

* chore: remove unused proposal(params-change)

* fix: typo
  • Loading branch information
JoowonYun authored and yoosah committed Apr 17, 2024
1 parent 6844be0 commit 2a8ca56
Show file tree
Hide file tree
Showing 21 changed files with 732 additions and 83 deletions.
8 changes: 2 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ import (
govv1betatypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -362,7 +360,6 @@ func NewAppKeeper(
govRouter := govv1betatypes.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1betatypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&appKeepers.Erc20Keeper)).
Expand Down Expand Up @@ -422,7 +419,6 @@ func NewAppKeeper(
)

// RouterKeeper must be created before TransferKeeper
authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()
appKeepers.PFMRouterKeeper = pfmrouterkeeper.NewKeeper(
appCodec, appKeepers.keys[pfmroutertypes.StoreKey],
nil, // Will be zero-value here. Reference is set later on with SetTransferKeeper.
Expand All @@ -431,7 +427,7 @@ func NewAppKeeper(
appKeepers.BankKeeper,
// The ICS4Wrapper is replaced by the IBCFeeKeeper instead of the channel so that sending can be overridden by the middleware
&appKeepers.IBCFeeKeeper,
authority,
govModAddress,
)

appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
Expand Down Expand Up @@ -526,12 +522,12 @@ func NewAppKeeper(
appKeepers.RewardKeeper = rewardkeeper.NewKeeper(
appCodec,
appKeepers.keys[rewardtypes.StoreKey],
appKeepers.GetSubspace(rewardtypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.StakingKeeper,
appKeepers.DistrKeeper,
appKeepers.MintKeeper,
govModAddress,
)

return appKeepers
Expand Down
4 changes: 1 addition & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -95,7 +94,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler {
govProposalHandlers := volunteerclient.ProposalHandler

return append(govProposalHandlers, []govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
Expand Down Expand Up @@ -180,7 +178,7 @@ func appModules(
xplaevm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)),
feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)),
erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)),
reward.NewAppModule(appCodec, app.RewardKeeper, app.BankKeeper, app.StakingKeeper, app.DistrKeeper),
reward.NewAppModule(appCodec, app.RewardKeeper, app.BankKeeper, app.StakingKeeper, app.DistrKeeper, app.GetSubspace(rewardtypes.ModuleName)),
volunteer.NewAppModule(appCodec, app.VolunteerKeeper),
}
}
Expand Down
32 changes: 32 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
- [xpla/reward/v1beta1/tx.proto](#xpla/reward/v1beta1/tx.proto)
- [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector)
- [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse)
- [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse)

- [Msg](#xpla.reward.v1beta1.Msg)

Expand Down Expand Up @@ -224,6 +226,35 @@ MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type.




<a name="xpla.reward.v1beta1.MsgUpdateParams"></a>

### MsgUpdateParams
MsgUpdateParams is the Msg/UpdateParams request type for reward parameters.
Since: cosmos-sdk 0.47


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `params` | [Params](#xpla.reward.v1beta1.Params) | | params defines the x/evm parameters to update. NOTE: All parameters must be supplied. |






<a name="xpla.reward.v1beta1.MsgUpdateParamsResponse"></a>

### MsgUpdateParamsResponse
MsgUpdateParamsResponse defines the response structure for executing a
MsgUpdateParams message.
Since: cosmos-sdk 0.47





<!-- end messages -->

<!-- end enums -->
Expand All @@ -239,6 +270,7 @@ Msg defines the reawrd Msg service.
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `FundFeeCollector` | [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector) | [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse) | FundFeeCollector defines a method to allow an account to directly fund the fee collector. | |
| `UpdateParams` | [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams) | [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse) | UpdateParams defined a governance operation for updating the x/reward module parameters. The authority is hard-coded to the Cosmos SDK x/gov module account | |

<!-- end services -->

Expand Down
26 changes: 26 additions & 0 deletions proto/xpla/reward/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ option go_package = "github.com/xpladev/xpla/x/reward/types";

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "xpla/reward/v1beta1/reward.proto";
import "amino/amino.proto";

// Msg defines the reawrd Msg service.
Expand All @@ -13,6 +16,11 @@ service Msg {
// fund the fee collector.
rpc FundFeeCollector(MsgFundFeeCollector)
returns (MsgFundFeeCollectorResponse);

// UpdateParams defined a governance operation for updating the x/reward
// module parameters. The authority is hard-coded to the Cosmos SDK x/gov
// module account
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgFundFeeCollector allows an account to directly
Expand All @@ -31,3 +39,21 @@ message MsgFundFeeCollector {

// MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type.
message MsgFundFeeCollectorResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type for reward parameters.
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/evm parameters to update.
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
4 changes: 1 addition & 3 deletions tests/integration/testutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
params "github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
Expand Down Expand Up @@ -166,7 +165,6 @@ func CreateTestInput(t *testing.T) TestInput {

govModAddress := authtypes.NewModuleAddress(govtypes.ModuleName).String()

paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, keyParams, tKeyParams)
accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, etherminttypes.ProtoAccount, maccPerms, sdk.GetConfig().GetBech32AccountAddrPrefix(), govModAddress)
bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, blackListAddrs, govModAddress)

Expand Down Expand Up @@ -219,12 +217,12 @@ func CreateTestInput(t *testing.T) TestInput {
keeper := rewardkeeper.NewKeeper(
appCodec,
keyReward,
paramsKeeper.Subspace(rewardtypes.ModuleName),
accountKeeper,
bankKeeper,
stakingKeeper,
distrKeeper,
mintKeeper,
govModAddress,
)

defaults := rewardtypes.Params{
Expand Down
18 changes: 18 additions & 0 deletions x/reward/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
}
)
7 changes: 6 additions & 1 deletion x/reward/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package keeper

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/xpladev/xpla/x/reward/types"
)

func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
k.SetParams(ctx, data.Params)
err := k.SetParams(ctx, data.Params)
if err != nil {
panic(fmt.Errorf("error setting params %s", err))
}
}

func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
Expand Down
5 changes: 2 additions & 3 deletions x/reward/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ var _ types.QueryServer = Keeper{}
// Params queries params of reward module
func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
var params types.Params
k.paramSpace.GetParamSet(ctx, &params)
params := k.GetParams(ctx)

return &types.QueryParamsResponse{Params: params}, nil
}

// RewardPool queries the community pool coins
// RewardPool queries the reward pool coins
func (k Keeper) Pool(c context.Context, req *types.QueryPoolRequest) (*types.QueryPoolResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
pool := k.PoolBalances(ctx)
Expand Down
27 changes: 18 additions & 9 deletions x/reward/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package keeper

import (
"fmt"

"github.com/cometbft/cometbft/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/xpladev/xpla/x/reward/types"
)

type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string

authKeeper types.AccountKeeper
bankKeeper types.BankKeeper
Expand All @@ -25,26 +28,32 @@ type Keeper struct {
}

func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
cdc codec.BinaryCodec, key storetypes.StoreKey,
ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, dk types.DistributionKeeper, mk types.MintKeeper,
authority string,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
// ensure reward module account is set
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}

return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
authKeeper: ak,
bankKeeper: bk,
stakingKeeper: sk,
distKeeper: dk,
mintKeeper: mk,
authority: authority,
}
}

// GetAuthority returns the x/reward module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
Expand Down
26 changes: 26 additions & 0 deletions x/reward/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/xpladev/xpla/x/reward/exported"
v2 "github.com/xpladev/xpla/x/reward/migrations/v2"
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
legacySubspace exported.Subspace
}

// NewMigrator returns a new Migrator.
func NewMigrator(keeper Keeper, legacySubspace exported.Subspace) Migrator {
return Migrator{keeper: keeper, legacySubspace: legacySubspace}
}

// Migrate1to2 migrates the x/reward module state from the consensus
// version 1 to version 2. Specifically, it takes the parameters that are currently stored
// and managed by the x/params module and stores them directly into the x/reward
// module state.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
18 changes: 18 additions & 0 deletions x/reward/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package keeper
import (
context "context"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/xpladev/xpla/x/reward/types"
)

Expand Down Expand Up @@ -42,3 +44,19 @@ func (k msgServer) FundFeeCollector(goCtx context.Context, msg *types.MsgFundFee

return &types.MsgFundFeeCollectorResponse{}, nil
}

// UpdateParams implements the gRPC MsgServer interface. After a successful governance vote
// it updates the parameters in the keeper only if the requested authority
// is the Cosmos SDK governance module account
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.authority != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority)
}

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

return &types.MsgUpdateParamsResponse{}, nil
}
Loading

0 comments on commit 2a8ca56

Please sign in to comment.