Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Gas consumption script #1029

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions app/antehander.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
)

// NewAnteDecorators returns an AnteDecorators that check and increment
// sequence numbers, checks signatures & account numbers, and deducts fees from
// the first signer.
func NewAnteDecorators(options ante.HandlerOptions) ([]sdk.AnteDecorator, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
}

return anteDecorators, nil
}
19 changes: 17 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const (
BondDenomAlias = "microtia"
// DisplayDenom defines the name, symbol, and display value of the Celestia token.
DisplayDenom = "TIA"
// MonitorGasOptionKey is the key used in the app options that determines if
// the gas monitor should be used
MonitorGasOptionKey = "MonitorGas"
)

// These constants are derived from the above variables.
Expand Down Expand Up @@ -501,7 +504,7 @@ func New(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
anteHandler, err := ante.NewAnteHandler(
anteDecorators, err := NewAnteDecorators(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
Expand All @@ -513,7 +516,19 @@ func New(
if err != nil {
panic(err)
}
app.SetAnteHandler(anteHandler)

gasMonitor := appOpts.Get(MonitorGasOptionKey)
// insert the gas monitor into the earliest position if it is configured
if gasMonitor != nil {
decorator, ok := gasMonitor.(sdk.AnteDecorator)
if !ok {
panic("unexpected gas metor decorator")
}
anteDecorators = append(anteDecorators, nil)
copy(anteDecorators[2:], anteDecorators[1:])
anteDecorators[1] = decorator
}
app.SetAnteHandler(sdk.ChainAnteDecorators(anteDecorators...))
app.setPostHanders()

if loadLatest {
Expand Down
Loading