From 4270dbe7dc7fe79aca9f7c7a3013db09bf7db68a Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 15 Jun 2023 15:10:02 +0200 Subject: [PATCH 1/2] extract out ante into a separate file --- app/ante.go | 38 ++++++++++++++++++++++++++++++++++++++ app/app.go | 21 ++++++++------------- 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 app/ante.go diff --git a/app/ante.go b/app/ante.go new file mode 100644 index 0000000000..a44bd8b9f9 --- /dev/null +++ b/app/ante.go @@ -0,0 +1,38 @@ +package app + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/auth/signing" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante" + ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper" +) + +func NewAnteHandler( + accountKeeper ante.AccountKeeper, + bankKeeper authtypes.BankKeeper, + feegrantKeeper ante.FeegrantKeeper, + signModeHandler signing.SignModeHandler, + sigGasConsumer ante.SignatureVerificationGasConsumer, + channelKeeper *ibckeeper.Keeper, +) sdk.AnteHandler { + return sdk.ChainAnteDecorators( + ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + // reject all tx extensions + ante.NewExtensionOptionsDecorator(nil), + ante.NewValidateBasicDecorator(), + ante.TxTimeoutHeightDecorator{}, + ante.NewValidateMemoDecorator(accountKeeper), + ante.NewConsumeGasForTxSizeDecorator(accountKeeper), + // check that the fee matches the gas and the local minimum gas price + // of the validator + ante.NewDeductFeeDecorator(accountKeeper, bankKeeper, feegrantKeeper, nil), + ante.NewSetPubKeyDecorator(accountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewValidateSigCountDecorator(accountKeeper), + ante.NewSigGasConsumeDecorator(accountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(accountKeeper, signModeHandler), + ante.NewIncrementSequenceDecorator(accountKeeper), + ibcante.NewRedundantRelayDecorator(channelKeeper), + ) +} diff --git a/app/app.go b/app/app.go index 4d414d4d60..83470191d4 100644 --- a/app/app.go +++ b/app/app.go @@ -531,19 +531,14 @@ func New( app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) app.SetEndBlocker(app.EndBlocker) - anteHandler, err := ante.NewAnteHandler( - ante.HandlerOptions{ - AccountKeeper: app.AccountKeeper, - BankKeeper: app.BankKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), - FeegrantKeeper: app.FeeGrantKeeper, - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - }, - ) - if err != nil { - panic(err) - } - app.SetAnteHandler(anteHandler) + app.SetAnteHandler(NewAnteHandler( + app.AccountKeeper, + app.BankKeeper, + app.FeeGrantKeeper, + encodingConfig.TxConfig.SignModeHandler(), + ante.DefaultSigVerificationGasConsumer, + app.IBCKeeper, + )) app.setPostHanders() if loadLatest { From d1377b195ff616e6e3ee61990292772da31836df Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 15 Jun 2023 15:17:54 +0200 Subject: [PATCH 2/2] use method instead --- app/ante.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ante.go b/app/ante.go index a44bd8b9f9..08aa86584d 100644 --- a/app/ante.go +++ b/app/ante.go @@ -22,7 +22,7 @@ func NewAnteHandler( // reject all tx extensions ante.NewExtensionOptionsDecorator(nil), ante.NewValidateBasicDecorator(), - ante.TxTimeoutHeightDecorator{}, + ante.NewTxTimeoutHeightDecorator(), ante.NewValidateMemoDecorator(accountKeeper), ante.NewConsumeGasForTxSizeDecorator(accountKeeper), // check that the fee matches the gas and the local minimum gas price