diff --git a/CHANGELOG.md b/CHANGELOG.md index f72b22bd595..4bfe7302ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [5.0.8] - 2021-10-14 + +* (gaia) This release includes a new AnteHandler that rejects redundant IBC transactions to save relayers fees. ## [5.0.7] - 2021-09-30 @@ -369,7 +372,8 @@ See the [Tendermint v0.34.7 SDK changelog](https://github.com/tendermint/tenderm -[Unreleased]: https://github.com/cosmos/gaia/compare/v5.0.7...HEAD +[Unreleased]: https://github.com/cosmos/gaia/compare/v5.0.8...HEAD +[v5.0.8]: https://github.com/cosmos/gaia/releases/tag/v5.0.8 [v5.0.7]: https://github.com/cosmos/gaia/releases/tag/v5.0.7 [v5.0.6]: https://github.com/cosmos/gaia/releases/tag/v5.0.6 [v5.0.5]: https://github.com/cosmos/gaia/releases/tag/v5.0.5 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, "", " ")