Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

chore(feemarket) - Depreacte usage of x/params in x/feemarket #1509

Merged
merged 31 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d49eb1b
(refactor): Added new MsgUpdateParams tx and generated new proto files
Vvaradinov Nov 29, 2022
9f6ebea
(refactor): Refactor for migration of x/params
Vvaradinov Nov 29, 2022
dd53d2e
(fix): Refactor to use single Params store key for easier more readab…
Vvaradinov Nov 29, 2022
b0b53a7
(fix): removed unused
Vvaradinov Nov 29, 2022
c62bfc3
(fix): add validation
Vvaradinov Nov 29, 2022
1ddab52
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Nov 29, 2022
ad0e605
(fix): fix linter
Vvaradinov Nov 29, 2022
248a326
remove line
Vvaradinov Nov 29, 2022
2258375
Merge branch 'Vvaradinov/refactor-feemarket-params' of https://github…
Vvaradinov Nov 29, 2022
b3a02d0
Added changes from code review
Vvaradinov Dec 1, 2022
aec42ab
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Dec 1, 2022
902bef8
Apply changes from code review
Vvaradinov Dec 1, 2022
02bc49c
Merge branch 'Vvaradinov/refactor-feemarket-params' of https://github…
Vvaradinov Dec 1, 2022
b3be8c5
(fix): Made ParamKey back to a string
Vvaradinov Dec 1, 2022
7382120
Added CHANGELOG entry
Vvaradinov Dec 1, 2022
dfd77e3
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Dec 12, 2022
752d0d9
Apply suggestions from code review
Vvaradinov Dec 12, 2022
0f6098d
(fix): remove HTTP endpoint exposure
Vvaradinov Dec 12, 2022
89a5cd7
Merge branch 'Vvaradinov/refactor-feemarket-params' of https://github…
Vvaradinov Dec 12, 2022
0ace96b
Apply suggestions from code review
Vvaradinov Dec 12, 2022
58ca91a
fix: Apply changes from code review and run linter
Vvaradinov Dec 12, 2022
f0363f4
Update x/feemarket/keeper/params.go
Vvaradinov Dec 15, 2022
922aec2
Update x/feemarket/types/msg.go
Vvaradinov Dec 19, 2022
fa697c7
tests: added tests for msg_server and msg
Vvaradinov Dec 19, 2022
60f7267
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Dec 19, 2022
e66eac8
tests: add failing test for migration
Vvaradinov Dec 19, 2022
1edc17b
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Jan 3, 2023
bb363c7
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Jan 3, 2023
3f6581d
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Jan 4, 2023
5462da8
Merge branch 'main' into Vvaradinov/refactor-feemarket-params
Vvaradinov Jan 5, 2023
e7fd485
Update x/feemarket/keeper/params.go
fedekunze Jan 5, 2023
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 @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### State Machine Breaking

* (feemarket) [#1509](https://github.com/evmos/ethermint/pull/1509) Deprecate usage of x/params in x/feemarket
* (deps) [#1361](https://github.com/evmos/ethermint/pull/1361) Bump ibc-go to [`v5.1.0`](https://github.com/cosmos/ibc-go/releases/tag/v5.1.0)
* (evm) [\#1272](https://github.com/evmos/ethermint/pull/1272) Implement modular interface for the EVM.
* (deps) [#1168](https://github.com/evmos/ethermint/pull/1168) Upgrade Cosmos SDK to [`v0.46.6`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.6).
Expand Down
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ func NewEthermintApp(

// Create Ethermint keepers
app.FeeMarketKeeper = feemarketkeeper.NewKeeper(
appCodec, app.GetSubspace(feemarkettypes.ModuleName), keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey],
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
keys[feemarkettypes.StoreKey], tkeys[feemarkettypes.TransientKey],
)

app.EvmKeeper = evmkeeper.NewKeeper(
Expand Down Expand Up @@ -491,7 +492,7 @@ func NewEthermintApp(
transferModule,
// Ethermint app modules
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
feemarket.NewAppModule(app.FeeMarketKeeper),
feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down
3 changes: 1 addition & 2 deletions proto/ethermint/evm/v1/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ message ChainConfig {
];
// dao_fork_support defines whether the nodes supports or opposes the DAO hard-fork
bool dao_fork_support = 3
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
[(gogoproto.customname) = "DAOForkSupport", (gogoproto.moretags) = "yaml:\"dao_fork_support\""];
// eip150_block: EIP150 implements the Gas price changes
// (https://github.com/ethereum/EIPs/issues/150) EIP150 HF block (nil no fork)
string eip150_block = 4 [
Expand Down Expand Up @@ -127,7 +127,6 @@ message ChainConfig {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"cancun_block\""
];

}

// State represents a single Storage key value pair item.
Expand Down
30 changes: 30 additions & 0 deletions proto/ethermint/feemarket/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";
package ethermint.feemarket.v1;

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "ethermint/feemarket/v1/feemarket.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/evmos/ethermint/x/feemarket/types";

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

// MsgUpdateParams defines a Msg for updating the x/feemarket 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/feemarket 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 {}
4 changes: 2 additions & 2 deletions x/evm/types/evm.pb.go

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

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

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"

Expand All @@ -14,7 +15,11 @@ func InitGenesis(
k keeper.Keeper,
data types.GenesisState,
) []abci.ValidatorUpdate {
k.SetParams(ctx, data.Params)
err := k.SetParams(ctx, data.Params)
if err != nil {
panic(errorsmod.Wrap(err, "could not set parameters at genesis"))
}

k.SetBlockGasWanted(ctx, data.BlockGas)

return []abci.ValidatorUpdate{}
Expand Down
26 changes: 26 additions & 0 deletions x/feemarket/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package feemarket

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/evmos/ethermint/x/feemarket/types"
)

// NewHandler returns a handler for Ethermint type messages.
func NewHandler(server types.MsgServer) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())

switch msg := msg.(type) {
case *types.MsgUpdateParams:
// execute state transition
res, err := server.UpdateParams(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)

default:
err := errorsmod.Wrapf(errortypes.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
return nil, err
}
}
}
15 changes: 5 additions & 10 deletions x/feemarket/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/ethermint/x/feemarket/types"
Expand All @@ -22,23 +21,18 @@ type Keeper struct {
// Store key required for the Fee Market Prefix KVStore.
storeKey storetypes.StoreKey
transientKey storetypes.StoreKey
// module specific parameter space that can be configured through governance
paramSpace paramtypes.Subspace
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
authority string
}

// NewKeeper generates new fee market module keeper
func NewKeeper(
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
cdc codec.BinaryCodec, paramSpace paramtypes.Subspace, storeKey, transientKey storetypes.StoreKey,
cdc codec.BinaryCodec, authority string, storeKey, transientKey storetypes.StoreKey,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
authority: authority,
transientKey: transientKey,
}
}
Expand Down Expand Up @@ -98,6 +92,7 @@ func (k Keeper) AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64

// GetBaseFeeV1 get the base fee from v1 version of states.
// return nil if base fee is not enabled
// TODO: Figure out if this will be deleted ?
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
func (k Keeper) GetBaseFeeV1(ctx sdk.Context) *big.Int {
store := ctx.KVStore(k.storeKey)
bz := store.Get(KeyPrefixBaseFeeV1)
Expand Down
19 changes: 16 additions & 3 deletions x/feemarket/keeper/migrations.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
v4 "github.com/evmos/ethermint/x/feemarket/migrations/v4"
"github.com/evmos/ethermint/x/feemarket/types"
)

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

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

// Migrate3to4 migrates the store from consensus version 3 to 4
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
}
41 changes: 41 additions & 0 deletions x/feemarket/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
v4types "github.com/evmos/ethermint/x/feemarket/migrations/v4/types"
"github.com/evmos/ethermint/x/feemarket/types"
)

type mockSubspace struct {
ps v4types.Params
}

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

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

func (suite *KeeperTestSuite) TestMigrations() {
legacySubspace := newMockSubspace(v4types.DefaultParams())
migrator := feemarketkeeper.NewMigrator(suite.app.FeeMarketKeeper, legacySubspace)

testCases := []struct {
name string
migrateFunc func(ctx sdk.Context) error
}{
{
"Run Migrate3to4",
migrator.Migrate3to4,
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
err := tc.migrateFunc(suite.ctx)
suite.Require().NoError(err)
})
}
}
27 changes: 27 additions & 0 deletions x/feemarket/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/evmos/ethermint/x/feemarket/types"
)

// 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) {
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
if k.authority != req.Authority {
return nil, errorsmod.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
}
49 changes: 30 additions & 19 deletions x/feemarket/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ package keeper
import (
"math/big"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/evmos/ethermint/x/feemarket/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// GetParams returns the total set of fee market parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
// TODO: update once https://github.com/cosmos/cosmos-sdk/pull/12615 is merged
// and released
for _, pair := range params.ParamSetPairs() {
k.paramSpace.GetIfExists(ctx, pair.Key, pair.Value)
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamsKey)
if bz == nil {
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
return params
}

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

// SetParams sets the fee market parameters to the param space.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
// SetParams sets the fee market params in a single key
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
}

// ----------------------------------------------------------------------------
Expand All @@ -30,15 +40,11 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {

// GetBaseFeeEnabled returns true if base fee is enabled
func (k Keeper) GetBaseFeeEnabled(ctx sdk.Context) bool {
var noBaseFee bool
var enableHeight int64
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyNoBaseFee, &noBaseFee)
k.paramSpace.GetIfExists(ctx, types.ParamStoreKeyEnableHeight, &enableHeight)
return !noBaseFee && ctx.BlockHeight() >= enableHeight
params := k.GetParams(ctx)
return !params.NoBaseFee && ctx.BlockHeight() >= params.EnableHeight
}

// GetBaseFee get's the base fee from the paramSpace
// return nil if base fee is not enabled
// GetBaseFee gets the base fee from the store
func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
params := k.GetParams(ctx)
if params.NoBaseFee {
Expand All @@ -50,11 +56,16 @@ func (k Keeper) GetBaseFee(ctx sdk.Context) *big.Int {
// try v1 format
return k.GetBaseFeeV1(ctx)
}

return baseFee
}

// SetBaseFee set's the base fee in the paramSpace
// SetBaseFee set's the base fee in the store
func (k Keeper) SetBaseFee(ctx sdk.Context, baseFee *big.Int) {
k.paramSpace.Set(ctx, types.ParamStoreKeyBaseFee, sdkmath.NewIntFromBigInt(baseFee))
params := k.GetParams(ctx)
params.BaseFee = sdk.NewInt(baseFee.Int64())
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
err := k.SetParams(ctx, params)
if err != nil {
// TODO: Do we throw error ?
Vvaradinov marked this conversation as resolved.
Show resolved Hide resolved
return
}
}
Loading