Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(revenue): Deprecate x/params usage in x/revenue #1129

Merged
merged 17 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

- (revenue) [#1129](https://github.com/evmos/evmos/pull/1129) Deprecate usage of x/params in x/revenue
- (ante) [#1054](https://github.com/evmos/evmos/pull/1054) Remove validator commission `AnteHandler` decorator and replace it with the new `MinCommissionRate` staking parameter.
- (deps) [\#1041](https://github.com/evmos/evmos/pull/1041) Add ics23 dragonberry replace in go.mod as mentioned in the [Cosmos SDK release](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4)
- (deps) [\#1037](https://github.com/evmos/evmos/pull/1037) Bump Ethermint version to [`v0.20.0-rc2`](https://github.com/evmos/ethermint/releases/tag/v0.20.0-rc2)
Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func NewEvmos(
)

app.RevenueKeeper = revenuekeeper.NewKeeper(
keys[revenuetypes.StoreKey], appCodec, app.GetSubspace(revenuetypes.ModuleName),
keys[revenuetypes.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.BankKeeper, app.EvmKeeper,
authtypes.FeeCollectorName,
)
Expand Down Expand Up @@ -623,7 +623,7 @@ func NewEvmos(
claims.NewAppModule(appCodec, *app.ClaimsKeeper),
vesting.NewAppModule(app.VestingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
recovery.NewAppModule(*app.RecoveryKeeper),
revenue.NewAppModule(app.RevenueKeeper, app.AccountKeeper),
revenue.NewAppModule(app.RevenueKeeper, app.AccountKeeper, app.GetSubspace(revenuetypes.ModuleName)),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down
22 changes: 22 additions & 0 deletions proto/evmos/revenue/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
syntax = "proto3";
package evmos.revenue.v1;

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "evmos/revenue/v1/genesis.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";

Expand All @@ -21,6 +24,11 @@ service Msg {
rpc CancelRevenue(MsgCancelRevenue) returns (MsgCancelRevenueResponse) {
option (google.api.http).post = "/evmos/revenue/v1/tx/cancel_revenue";
};
// UpdateParams defined a governance operation for updating the x/revenue module parameters.
// The authority is hard-coded to the Cosmos SDK x/gov module account
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse) {
option (google.api.http).post ="/evmos/revenue/v1/tx/update_params";
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
};
}

// MsgRegisterRevenue defines a message that registers a Revenue
Expand Down Expand Up @@ -70,3 +78,17 @@ message MsgCancelRevenue {

// MsgCancelRevenueResponse defines the MsgCancelRevenue response type
message MsgCancelRevenueResponse {}

// MsgUpdateParams defines a Msg for updating the x/revenue module parameters.
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/revenue 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.
message MsgUpdateParamsResponse {}
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions x/erc20/types/erc20.pb.go

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

6 changes: 5 additions & 1 deletion x/revenue/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package revenue

import (
"cosmossdk.io/errors"
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/evmos/evmos/v10/x/revenue/keeper"
Expand All @@ -13,7 +14,10 @@ func InitGenesis(
k keeper.Keeper,
data types.GenesisState,
) {
k.SetParams(ctx, data.Params)
err := k.SetParams(ctx, data.Params)
if err != nil {
panic(errors.Wrapf(err, "failed setting params"))
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
}

for _, revenue := range data.Revenues {
contract := revenue.GetContractAddr()
Expand Down
4 changes: 4 additions & 0 deletions x/revenue/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func NewHandler(server types.MsgServer) sdk.Handler {
case *types.MsgCancelRevenue:
res, err := server.CancelRevenue(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgUpdateParams:
res, err := server.UpdateParams(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

default:
return nil, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
}
Expand Down
18 changes: 6 additions & 12 deletions x/revenue/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"

"github.com/evmos/evmos/v10/x/revenue/types"
Expand All @@ -15,10 +14,10 @@ import (
// Keeper of this module maintains collections of revenues for contracts
// registered to receive transaction fees.
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramstore 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
bankKeeper types.BankKeeper
evmKeeper types.EVMKeeper
feeCollectorName string
Expand All @@ -28,20 +27,15 @@ type Keeper struct {
func NewKeeper(
storeKey storetypes.StoreKey,
cdc codec.BinaryCodec,
ps paramtypes.Subspace,
authority string,
bk types.BankKeeper,
evmKeeper types.EVMKeeper,
feeCollector string,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
storeKey: storeKey,
cdc: cdc,
paramstore: ps,
authority: authority,
bankKeeper: bk,
evmKeeper: evmKeeper,
feeCollectorName: feeCollector,
Expand Down
26 changes: 26 additions & 0 deletions x/revenue/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"
v2 "github.com/evmos/evmos/v10/x/revenue/migrations/v2"
"github.com/evmos/evmos/v10/x/revenue/types"
)

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

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

// Migrate1to2 migrates the store from consensus version 1 to 2
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
20 changes: 20 additions & 0 deletions x/revenue/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package keeper
import (
"context"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/pkg/errors"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -260,3 +263,20 @@ func (k Keeper) CancelRevenue(

return &types.MsgCancelRevenueResponse{}, nil
}

// UpdateParams implements the gRPC MsgServer interface. When an UpdateParams
// proposal passes, it updates the module parameters. The update can only be
// performed if the requested authority is the Cosmos SDK governance module
// account.
func (k *Keeper) 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)
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
}

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

return &types.MsgUpdateParamsResponse{}, nil
}
24 changes: 19 additions & 5 deletions x/revenue/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ import (
"github.com/evmos/evmos/v10/x/revenue/types"
)

// GetParams returns the total set of fees parameters.
// GetParams returns the total set of fee market parameters.
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramstore.GetParamSetIfExists(ctx, &params)
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
return params
}

k.cdc.MustUnmarshal(bz, &params)
return params
}

// SetParams sets the fees parameters to the param space.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramstore.SetParamSet(ctx, &params)
// SetParams sets the FeeMarket params in a single key
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}

store.Set(types.ParamsKey, bz)

return nil
}
37 changes: 37 additions & 0 deletions x/revenue/migrations/v2/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v2

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
v2types "github.com/evmos/evmos/v10/x/revenue/migrations/v2/types"
"github.com/evmos/evmos/v10/x/revenue/types"
)

// MigrateStore migrates the x/evm module state from the consensus version 1 to
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
// version 2. Specifically, it takes the parameters that are currently stored
// and managed by the Cosmos SDK params module and stores them directly into the x/evm module state.
func MigrateStore(
ctx sdk.Context,
storeKey storetypes.StoreKey,
legacySubspace types.Subspace,
cdc codec.BinaryCodec,
) error {
store := ctx.KVStore(storeKey)
var params v2types.Params

legacySubspace.GetParamSetIfExists(ctx, &params)

if err := params.Validate(); err != nil {
return err
}

bz, err := cdc.Marshal(&params)
if err != nil {
return err
}

store.Set(types.ParamsKey, bz)

return nil
}
46 changes: 46 additions & 0 deletions x/revenue/migrations/v2/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v2_test

import (
"testing"

"github.com/evmos/ethermint/encoding"
v4 "github.com/evmos/evmos/v10/x/revenue/migrations/v2"
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
v2types "github.com/evmos/evmos/v10/x/revenue/migrations/v2/types"
"github.com/evmos/evmos/v10/x/revenue/types"

"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/evmos/ethermint/app"
"github.com/stretchr/testify/require"
)

type mockSubspace struct {
ps v2types.Params
}

func newMockSubspace(ps v2types.Params) mockSubspace {
return mockSubspace{ps: ps}
}

func (ms mockSubspace) GetParamSetIfExists(ctx sdk.Context, ps types.LegacyParams) {
*ps.(*v2types.Params) = ms.ps
}

func TestMigrate(t *testing.T) {
encCfg := encoding.MakeConfig(app.ModuleBasics)
cdc := encCfg.Codec

storeKey := sdk.NewKVStoreKey(types.ModuleName)
tKey := sdk.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
kvStore := ctx.KVStore(storeKey)

legacySubspace := newMockSubspace(v2types.DefaultParams())
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))

paramsBz := kvStore.Get(v2types.ParamsKey)
var params v2types.Params
cdc.MustUnmarshal(paramsBz, &params)

require.Equal(t, params, legacySubspace.ps)
}
Loading