Skip to content

Commit

Permalink
feat: gov switch params (#613)
Browse files Browse the repository at this point in the history
Co-authored-by: fx0x55 <80245546+fx0x55@users.noreply.github.com>
  • Loading branch information
zakir-code and fx0x55 committed Aug 1, 2024
1 parent cc63f68 commit 8b6ff1d
Show file tree
Hide file tree
Showing 30 changed files with 1,993 additions and 593 deletions.
26 changes: 26 additions & 0 deletions ante/disable_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethante "github.com/evmos/ethermint/app/ante"
)

type DisableMsgDecorator struct {
govKeeper Govkeeper
// disabledMsgs is a set that contains type urls of unauthorized msgs.
disabledMsgTypes []string
}

func NewDisableMsgDecorator(disabledMsgTypes []string, govKeeper Govkeeper) DisableMsgDecorator {
return DisableMsgDecorator{disabledMsgTypes: disabledMsgTypes, govKeeper: govKeeper}
}

func (dms DisableMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
disabledMsgs := dms.govKeeper.GetDisabledMsgs(ctx)
disabledMsgs = append(disabledMsgs, dms.disabledMsgTypes...)
if len(disabledMsgs) == 0 {
return next(ctx, tx, simulate)
}

return ethante.NewAuthzLimiterDecorator(disabledMsgs).AnteHandle(ctx, tx, simulate, next)
}
4 changes: 4 additions & 0 deletions ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ type FeeMarketKeeper interface {
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
GetBaseFeeEnabled(ctx sdk.Context) bool
}

type Govkeeper interface {
GetDisabledMsgs(ctx sdk.Context) []string
}
9 changes: 8 additions & 1 deletion ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type HandlerOptions struct {
EvmKeeper ethante.EVMKeeper
FeeMarketKeeper FeeMarketKeeper
IbcKeeper *ibckeeper.Keeper
GovKeeper Govkeeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer ante.SignatureVerificationGasConsumer
TxFeeChecker ante.TxFeeChecker
Expand All @@ -46,6 +47,12 @@ func (options HandlerOptions) Validate() error {
if options.EvmKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler")
}
if options.IbcKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "ibc keeper is required for AnteHandler")
}
if options.GovKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "gov keeper is required for AnteHandler")
}
return nil
}

Expand Down Expand Up @@ -78,7 +85,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
// disable the Msg types that cannot be included on an authz.MsgExec msgs field
ethante.NewAuthzLimiterDecorator(options.DisabledAuthzMsgs),
NewDisableMsgDecorator(options.DisabledAuthzMsgs, options.GovKeeper),
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
NewRejectExtensionOptionsDecorator(),
ante.NewValidateBasicDecorator(),
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (app *App) setAnteHandler(appOpts servertypes.AppOptions) {
EvmKeeper: app.EvmKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
IbcKeeper: app.IBCKeeper,
GovKeeper: app.GovKeeper,
SignModeHandler: app.txConfig.SignModeHandler(),
SigGasConsumer: fxante.DefaultSigVerificationGasConsumer,
MaxTxGasWanted: maxGasWanted,
Expand Down
2 changes: 1 addition & 1 deletion app/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMakeEncodingConfig_RegisterInterfaces(t *testing.T) {
for implInterfaces.Next() {
count2++
}
assert.Equal(t, 296, count2)
assert.Equal(t, 298, count2)

typeURLMap := interfaceRegistry.FieldByName("typeURLMap").MapRange()
for typeURLMap.Next() {
Expand Down
Loading

0 comments on commit 8b6ff1d

Please sign in to comment.