Skip to content

Commit

Permalink
Backport/for v5.0.8 (#1011)
Browse files Browse the repository at this point in the history
* feat: add ibc-antehandler to the default handlers

* fix: testnet cli command update genesis supply

* chore: fix lint

Co-authored-by: billy rennekamp <[email protected]>
  • Loading branch information
yaruwangway and okwme authored Oct 8, 2021
1 parent f6f354d commit 23f6ee2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
57 changes: 57 additions & 0 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 13 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gaia

import (
"fmt"
"io"
stdlog "log"
"net/http"
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion cmd/gaiad/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", " ")
Expand Down

0 comments on commit 23f6ee2

Please sign in to comment.