Skip to content

Commit

Permalink
add globalfee ante and antispam gov ante
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed Oct 31, 2023
1 parent e600a16 commit ca410f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
30 changes: 18 additions & 12 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ 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"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// 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) {
Expand All @@ -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() == "" {
Expand All @@ -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(),
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -916,18 +918,23 @@ 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,
FeegrantKeeper: app.FeeGrantKeeper,
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 {
Expand Down

0 comments on commit ca410f8

Please sign in to comment.