From ca410f86b931556f24ae238f1157b409645f8018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=E1=BA=B7c?= Date: Tue, 31 Oct 2023 13:40:56 +0700 Subject: [PATCH] add globalfee ante and antispam gov ante --- ante/ante.go | 30 ++++++++++++++++++------------ app/app.go | 19 +++++++++++++------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ante/ante.go b/ante/ante.go index c9cf15e2..e8e44074 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -2,15 +2,19 @@ package ante import ( "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" - authante "github.com/cosmos/cosmos-sdk/x/auth/ante" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" + migaloofeeante "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/globalfee/ante" ) @@ -18,14 +22,14 @@ import ( // channel keeper. type HandlerOptions struct { ante.HandlerOptions - Codec codec.BinaryCodec - GovKeeper *govkeeper.Keeper - IBCkeeper *ibckeeper.Keeper - ExtensionOptionChecker authante.ExtensionOptionChecker - BypassMinFeeMsgTypes []string - GlobalFeeSubspace paramtypes.Subspace - StakingSubspace paramtypes.Subspace - TxFeeChecker authante.TxFeeChecker + Codec codec.BinaryCodec + GovKeeper *govkeeper.Keeper + IBCKeeper *ibckeeper.Keeper + WasmConfig *wasmTypes.WasmConfig + BypassMinFeeMsgTypes []string + GlobalFeeSubspace paramtypes.Subspace + StakingSubspace paramtypes.Subspace + TXCounterStoreKey storetypes.StoreKey } func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { @@ -38,7 +42,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { if opts.SignModeHandler == nil { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for AnteHandler") } - if opts.IBCkeeper == nil { + if opts.IBCKeeper == nil { return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler") } if opts.GlobalFeeSubspace.Name() == "" { @@ -63,7 +67,9 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { var maxBypassMinFeeMsgGasUsage uint64 = 200_000 anteDecorators := []sdk.AnteDecorator{ - ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early + wasmkeeper.NewCountTXDecorator(opts.TXCounterStoreKey), ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker), ante.NewValidateBasicDecorator(), ante.NewTxTimeoutHeightDecorator(), @@ -78,7 +84,7 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer), ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler), ante.NewIncrementSequenceDecorator(opts.AccountKeeper), - ibcante.NewRedundantRelayDecorator(opts.IBCkeeper), + ibcante.NewRedundantRelayDecorator(opts.IBCKeeper), } return sdk.ChainAnteDecorators(anteDecorators...), nil diff --git a/app/app.go b/app/app.go index dd352938..3256c7bf 100644 --- a/app/app.go +++ b/app/app.go @@ -9,6 +9,7 @@ import ( "sort" "strings" + "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/globalfee" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" @@ -101,7 +102,6 @@ import ( ibcmock "github.com/cosmos/ibc-go/v6/testing/mock" bank "github.com/terra-money/alliance/custom/bank" custombankkeeper "github.com/terra-money/alliance/custom/bank/keeper" - "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/globalfee" // use TFL's ibc-hooks from Osmosis' ibc-hooks ibchooks "github.com/terra-money/core/v2/x/ibc-hooks" @@ -141,6 +141,8 @@ import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" appparams "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app/params" + migalooante "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/ante" + // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -916,8 +918,8 @@ func NewMigalooApp( // register upgrade app.setupUpgradeHandlers(cfg) - anteHandler, err := NewAnteHandler( - HandlerOptions{ + anteHandler, err := migalooante.NewAnteHandler( + migalooante.HandlerOptions{ HandlerOptions: ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, @@ -925,9 +927,14 @@ func NewMigalooApp( SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, - IBCKeeper: app.IBCKeeper, - WasmConfig: &wasmConfig, - TXCounterStoreKey: keys[wasm.StoreKey], + Codec: appCodec, + GovKeeper: &app.GovKeeper, + IBCKeeper: app.IBCKeeper, + WasmConfig: &wasmConfig, + BypassMinFeeMsgTypes: bypassMinFeeMsgTypes, + GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), + StakingSubspace: app.GetSubspace(stakingtypes.ModuleName), + TXCounterStoreKey: keys[wasm.StoreKey], }, ) if err != nil {