From b2c652c99b430b4d5c0a6409d73eb82a5a848649 Mon Sep 17 00:00:00 2001 From: yaruwang Date: Wed, 29 Sep 2021 16:45:35 +0200 Subject: [PATCH 1/3] feat: add ibc-antehandler to the default handlers --- app/ante_handler.go | 57 +++++++++++++++++++++++++++++++++++++++++++++ app/app.go | 18 ++++++++++---- 2 files changed, 70 insertions(+), 5 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) { From a897370f2293c877d8d06c8273d1f26e271c6a66 Mon Sep 17 00:00:00 2001 From: yaruwang Date: Wed, 29 Sep 2021 16:47:27 +0200 Subject: [PATCH 2/3] fix: testnet cli command update genesis supply --- cmd/gaiad/cmd/testnet.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/gaiad/cmd/testnet.go b/cmd/gaiad/cmd/testnet.go index 5020265daf4..9abe9028e58 100644 --- a/cmd/gaiad/cmd/testnet.go +++ b/cmd/gaiad/cmd/testnet.go @@ -287,8 +287,11 @@ func initGenFiles( // set the balances in the genesis state 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, "", " ") From 6477e6deb123a64e3c96c164b40fd59dac18cbae Mon Sep 17 00:00:00 2001 From: billy rennekamp Date: Thu, 7 Oct 2021 12:43:39 +0200 Subject: [PATCH 3/3] chore: fix lint --- cmd/gaiad/cmd/testnet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaiad/cmd/testnet.go b/cmd/gaiad/cmd/testnet.go index 9abe9028e58..e540e5a0268 100644 --- a/cmd/gaiad/cmd/testnet.go +++ b/cmd/gaiad/cmd/testnet.go @@ -287,7 +287,7 @@ func initGenFiles( // set the balances in the genesis state var bankGenState banktypes.GenesisState clientCtx.JSONMarshaler.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState) - + bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances) for _, bal := range bankGenState.Balances { bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...)