diff --git a/CHANGELOG.md b/CHANGELOG.md index b456119afd..99de92cfc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (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) @@ -48,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +- (erc20) [#1059](https://github.com/evmos/evmos/pull/1059) Add util functions (iterator and params) for ERC20 module. - (go) [\#1039](https://github.com/evmos/evmos/pull/1039) Bump go v1.19 - (deps) [\#1033](https://github.com/evmos/evmos/pull/1033) Bump Cosmos SDK to [`v0.46.4`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.4) - (ante) [\#993](https://github.com/evmos/evmos/pull/993) Re-order AnteHandlers for better performance diff --git a/app/ante/comission.go b/app/ante/comission.go deleted file mode 100644 index 7a105d81b8..0000000000 --- a/app/ante/comission.go +++ /dev/null @@ -1,85 +0,0 @@ -package ante - -import ( - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - errortypes "github.com/cosmos/cosmos-sdk/types/errors" - - sdkerrors "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/x/authz" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -var minCommission = sdk.NewDecWithPrec(5, 2) // 5% - -// TODO: remove once Cosmos SDK is upgraded to v0.46 - -// ValidatorCommissionDecorator validates that the validator commission is always -// greater or equal than the min commission rate -type ValidatorCommissionDecorator struct { - cdc codec.BinaryCodec -} - -// NewValidatorCommissionDecorator creates a new NewValidatorCommissionDecorator -func NewValidatorCommissionDecorator(cdc codec.BinaryCodec) ValidatorCommissionDecorator { - return ValidatorCommissionDecorator{ - cdc: cdc, - } -} - -// AnteHandle checks if the tx contains a staking create validator or edit validator. -// It errors if the the commission rate is below the min threshold. -func (vcd ValidatorCommissionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - for _, msg := range tx.GetMsgs() { - switch msg := msg.(type) { - case *authz.MsgExec: - // Check for bypassing authorization - if err := vcd.validateAuthz(ctx, msg); err != nil { - return ctx, err - } - - default: - if err := vcd.validateMsg(ctx, msg); err != nil { - return ctx, err - } - } - } - - return next(ctx, tx, simulate) -} - -// validateAuthz validates the authorization internal message -func (vcd ValidatorCommissionDecorator) validateAuthz(ctx sdk.Context, execMsg *authz.MsgExec) error { - for _, v := range execMsg.Msgs { - var innerMsg sdk.Msg - err := vcd.cdc.UnpackAny(v, &innerMsg) - if err != nil { - return sdkerrors.Wrap(err, "cannot unmarshal authz exec msgs") - } - - if err := vcd.validateMsg(ctx, innerMsg); err != nil { - return err - } - } - - return nil -} - -// validateMsg checks that the commission rate is over 5% for create and edit validator msgs -func (vcd ValidatorCommissionDecorator) validateMsg(_ sdk.Context, msg sdk.Msg) error { - switch msg := msg.(type) { - case *stakingtypes.MsgCreateValidator: - if msg.Commission.Rate.LT(minCommission) { - return sdkerrors.Wrapf( - errortypes.ErrInvalidRequest, - "validator commission %s be lower than minimum of %s", msg.Commission.Rate, minCommission) - } - case *stakingtypes.MsgEditValidator: - if msg.CommissionRate != nil && msg.CommissionRate.LT(minCommission) { - return sdkerrors.Wrapf( - errortypes.ErrInvalidRequest, - "validator commission %s be lower than minimum of %s", msg.CommissionRate, minCommission) - } - } - return nil -} diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index 9535c2dbbf..d79f87d672 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -90,7 +90,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc), - NewValidatorCommissionDecorator(options.Cdc), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), ante.NewValidateSigCountDecorator(options.AccountKeeper), @@ -114,7 +113,6 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc), - NewValidatorCommissionDecorator(options.Cdc), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewSetPubKeyDecorator(options.AccountKeeper), ante.NewValidateSigCountDecorator(options.AccountKeeper), diff --git a/app/app.go b/app/app.go index 7586f8f686..009bdfa352 100644 --- a/app/app.go +++ b/app/app.go @@ -159,6 +159,8 @@ func init() { // modify fee market parameter defaults through global feemarkettypes.DefaultMinGasPrice = MainnetMinGasPrices feemarkettypes.DefaultMinGasMultiplier = MainnetMinGasMultiplier + // modify default min commission to 5% + stakingtypes.DefaultMinCommissionRate = sdk.NewDecWithPrec(5, 2) } // Name defines the application binary name @@ -1109,6 +1111,7 @@ func (app *Evmos) setupUpgradeHandlers() { v10.UpgradeName, v10.CreateUpgradeHandler( app.mm, app.configurator, + app.StakingKeeper, ), ) diff --git a/app/upgrades/v10/upgrades.go b/app/upgrades/v10/upgrades.go index ab8a948fc3..ae150f9acd 100644 --- a/app/upgrades/v10/upgrades.go +++ b/app/upgrades/v10/upgrades.go @@ -3,6 +3,8 @@ package v10 import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) @@ -10,12 +12,30 @@ import ( func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + stakingKeeper stakingkeeper.Keeper, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) + setMinCommissionRate(ctx, stakingKeeper) + // Leave modules are as-is to avoid running InitGenesis. logger.Debug("running module migrations ...") return mm.RunMigrations(ctx, configurator, vm) } } + +// setMinCommissionRate sets the minimum commission rate for validators +// to 5%. +func setMinCommissionRate(ctx sdk.Context, sk stakingkeeper.Keeper) { + stakingParams := stakingtypes.Params{ + UnbondingTime: sk.UnbondingTime(ctx), + MaxValidators: sk.MaxValidators(ctx), + MaxEntries: sk.MaxEntries(ctx), + HistoricalEntries: sk.HistoricalEntries(ctx), + BondDenom: sk.BondDenom(ctx), + MinCommissionRate: sdk.NewDecWithPrec(5, 2), // 5% + } + + sk.SetParams(ctx, stakingParams) +} diff --git a/docs/developers/connect.md b/docs/developers/connect.md index eec60eb22d..c2d6846974 100644 --- a/docs/developers/connect.md +++ b/docs/developers/connect.md @@ -50,6 +50,7 @@ You can also use [chainlist.org](https://chainlist.org/) to add the node directl | `https://evmos-rest.publicnode.com` | `Cosmos` `REST` | [PublicNode (by Allnodes)](https://evmos.publicnode.com/) | | `https://evmos-api.validatrium.club` | `Tendermint` `API` | [Validatrium](https://validatrium.com/) | | `https://evmos-rpc.validatrium.club` | `Tendermint` `RPC` | [Validatrium](https://validatrium.com/) | +| `https://evmos-rpc.gateway.pokt.network` | `Ethereum` `JSON-RPC` | [PocketNetwork](https://www.pokt.network/) | ::: ::: tab Testnet diff --git a/docs/protocol/telemetry.md b/docs/protocol/telemetry.md index a81091aed0..ef45ea820b 100644 --- a/docs/protocol/telemetry.md +++ b/docs/protocol/telemetry.md @@ -6,7 +6,7 @@ order: 3 Gather relevant insights about the Evmos application and modules with custom metrics and telemetry. {synopsis} -To understand how to use the metrics below, please refer to the [Cosmos SDK telemetry documentation](https://docs.cosmos.network/master/core/telemetry.html). +To understand how to use the metrics below, please refer to the [Cosmos SDK telemetry documentation](https://docs.cosmos.network/main/core/telemetry.html). ## Supported Metrics diff --git a/go.mod b/go.mod index bc377d6465..48a880234d 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.8.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/onsi/ginkgo/v2 v2.4.0 + github.com/onsi/ginkgo/v2 v2.5.0 github.com/onsi/gomega v1.24.0 github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 @@ -24,7 +24,7 @@ require ( github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.34.22 github.com/tendermint/tm-db v0.6.7 - go.opencensus.io v0.23.0 + go.opencensus.io v0.24.0 google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 google.golang.org/grpc v1.50.1 google.golang.org/protobuf v1.28.1 diff --git a/go.sum b/go.sum index b407aafb88..f2b25ad976 100644 --- a/go.sum +++ b/go.sum @@ -805,8 +805,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA= github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= -github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo= +github.com/onsi/ginkgo/v2 v2.5.0 h1:TRtrvv2vdQqzkwrQ1ke6vtXf7IK34RBUJafIy1wMwls= +github.com/onsi/ginkgo/v2 v2.5.0/go.mod h1:Luc4sArBICYCS8THh8v3i3i5CuSZO+RaQRaJoeNwomw= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= @@ -1065,8 +1065,9 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= +go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= diff --git a/x/erc20/keeper/mint.go b/x/erc20/keeper/mint.go index d0445a1538..879be96520 100644 --- a/x/erc20/keeper/mint.go +++ b/x/erc20/keeper/mint.go @@ -19,8 +19,7 @@ func (k Keeper) MintingEnabled( sender, receiver sdk.AccAddress, token string, ) (types.TokenPair, error) { - params := k.GetParams(ctx) - if !params.EnableErc20 { + if !k.IsERC20Enabled(ctx) { return types.TokenPair{}, sdkerrors.Wrap( types.ErrERC20Disabled, "module is currently disabled by governance", ) diff --git a/x/erc20/keeper/params.go b/x/erc20/keeper/params.go index 0286ee20a2..c4982c1c24 100644 --- a/x/erc20/keeper/params.go +++ b/x/erc20/keeper/params.go @@ -16,3 +16,10 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramstore.SetParamSet(ctx, ¶ms) } + +// IsERC20Enabled returns true if the module logic is enabled +func (k Keeper) IsERC20Enabled(ctx sdk.Context) bool { + var enabled bool + k.paramstore.GetIfExists(ctx, types.ParamStoreKeyEnableErc20, &enabled) + return enabled +} diff --git a/x/erc20/keeper/token_pairs.go b/x/erc20/keeper/token_pairs.go index dcc5796d4a..b76402e23b 100644 --- a/x/erc20/keeper/token_pairs.go +++ b/x/erc20/keeper/token_pairs.go @@ -12,6 +12,16 @@ import ( func (k Keeper) GetTokenPairs(ctx sdk.Context) []types.TokenPair { tokenPairs := []types.TokenPair{} + k.IterateTokenPairs(ctx, func(tokenPair types.TokenPair) (stop bool) { + tokenPairs = append(tokenPairs, tokenPair) + return false + }) + + return tokenPairs +} + +// IterateTokenPairs iterates over all the stored token pairs +func (k Keeper) IterateTokenPairs(ctx sdk.Context, cb func(tokenPair types.TokenPair) (stop bool)) { store := ctx.KVStore(k.storeKey) iterator := sdk.KVStorePrefixIterator(store, types.KeyPrefixTokenPair) defer iterator.Close() @@ -20,10 +30,10 @@ func (k Keeper) GetTokenPairs(ctx sdk.Context) []types.TokenPair { var tokenPair types.TokenPair k.cdc.MustUnmarshal(iterator.Value(), &tokenPair) - tokenPairs = append(tokenPairs, tokenPair) + if cb(tokenPair) { + break + } } - - return tokenPairs } // GetTokenPairID returns the pair id from either of the registered tokens. diff --git a/x/erc20/proposal_handler.go b/x/erc20/proposal_handler.go index 7dae97a06d..b7a86cdb00 100644 --- a/x/erc20/proposal_handler.go +++ b/x/erc20/proposal_handler.go @@ -15,8 +15,7 @@ import ( func NewErc20ProposalHandler(k *keeper.Keeper) govv1beta1.Handler { return func(ctx sdk.Context, content govv1beta1.Content) error { // Check if the conversion is globally enabled - params := k.GetParams(ctx) - if !params.EnableErc20 { + if !k.IsERC20Enabled(ctx) { return sdkerrors.Wrap( types.ErrERC20Disabled, "registration is currently disabled by governance", )