From 23f6ee20949fc78e0ed9345af97b5b6658b7899d Mon Sep 17 00:00:00 2001 From: yaruwangway <69694322+yaruwangway@users.noreply.github.com> Date: Fri, 8 Oct 2021 16:13:42 +0200 Subject: [PATCH] Backport/for v5.0.8 (#1011) * feat: add ibc-antehandler to the default handlers * fix: testnet cli command update genesis supply * chore: fix lint Co-authored-by: billy rennekamp --- app/ante_handler.go | 57 ++++++++++++++++++++++++++++++++++++++++ app/app.go | 18 +++++++++---- cmd/gaiad/cmd/testnet.go | 5 +++- 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 app/ante_handler.go diff --git a/app/ante_handler.go b/app/ante_handler.go new file mode 100644 index 00000000000..0517dd6c32b --- /dev/null +++ b/app/ante_handler.go @@ -0,0 +1,57 @@ +package gaia + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/auth/types" + channelkeeper "github.com/cosmos/cosmos-sdk/x/ibc/core/04-channel/keeper" + ibcante "github.com/cosmos/cosmos-sdk/x/ibc/core/ante" +) + +type HandlerOptions struct { + AccountKeeper ante.AccountKeeper + BankKeeper types.BankKeeper + SignModeHandler signing.SignModeHandler + SigGasConsumer ante.SignatureVerificationGasConsumer + IBCChannelkeeper channelkeeper.Keeper +} + +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { + if options.AccountKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + } + if options.BankKeeper == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + } + if options.SignModeHandler == nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + } + + var sigGasConsumer = options.SigGasConsumer + if sigGasConsumer == nil { + sigGasConsumer = ante.DefaultSigVerificationGasConsumer + } + + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first + ante.NewRejectExtensionOptionsDecorator(), + ante.NewMempoolFeeDecorator(), + ante.NewValidateBasicDecorator(), + ante.TxTimeoutHeightDecorator{}, + ante.NewValidateMemoDecorator(options.AccountKeeper), + ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), + ante.NewRejectFeeGranterDecorator(), + // SetPubKeyDecorator must be called before all signature verification decorators + ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewAnteDecorator(options.IBCChannelkeeper), + } + + return sdk.ChainAnteDecorators(anteDecorators...), nil +} diff --git a/app/app.go b/app/app.go index 8c446b49470..faabf50fee5 100644 --- a/app/app.go +++ b/app/app.go @@ -1,6 +1,7 @@ package gaia import ( + "fmt" "io" stdlog "log" "net/http" @@ -410,12 +411,19 @@ func NewGaiaApp( // initialize BaseApp app.SetInitChainer(app.InitChainer) app.SetBeginBlocker(app.BeginBlocker) - app.SetAnteHandler( - ante.NewAnteHandler( - app.AccountKeeper, app.BankKeeper, ante.DefaultSigVerificationGasConsumer, - encodingConfig.TxConfig.SignModeHandler(), - ), + anteHandler, err := NewAnteHandler( + HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + IBCChannelkeeper: app.IBCKeeper.ChannelKeeper, + }, ) + if err != nil { + panic(fmt.Errorf("failed to create AnteHandler: %s", err)) + } + app.SetAnteHandler(anteHandler) app.SetEndBlocker(app.EndBlocker) app.UpgradeKeeper.SetUpgradeHandler("Gravity-DEX", func(ctx sdk.Context, plan upgradetypes.Plan) { diff --git a/cmd/gaiad/cmd/testnet.go b/cmd/gaiad/cmd/testnet.go index 5020265daf4..e540e5a0268 100644 --- a/cmd/gaiad/cmd/testnet.go +++ b/cmd/gaiad/cmd/testnet.go @@ -288,7 +288,10 @@ func initGenFiles( var bankGenState banktypes.GenesisState clientCtx.JSONMarshaler.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) - bankGenState.Balances = genBalances + bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances) + for _, bal := range bankGenState.Balances { + bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...) + } appGenState[banktypes.ModuleName] = clientCtx.JSONMarshaler.MustMarshalJSON(&bankGenState) appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")