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

refactor: generic fallback ante decorator (backport #102) #106

Merged
merged 3 commits into from
Jun 10, 2024
Merged
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
10 changes: 6 additions & 4 deletions tests/app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
authante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
feemarketante.NewFeeMarketCheckDecorator( // fee market check replaces fee deduct decorator
options.FeeMarketKeeper,
options.AccountKeeper,
options.BaseOptions.BankKeeper,
options.BaseOptions.FeegrantKeeper,
options.BaseOptions.TxFeeChecker,
authante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BaseOptions.BankKeeper,
options.BaseOptions.FeegrantKeeper,
options.BaseOptions.TxFeeChecker,
),
), // fees are deducted in the fee market deduct post handler
authante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
authante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
1 change: 0 additions & 1 deletion tests/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"

feemarketmodule "github.com/skip-mev/feemarket/x/feemarket"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
Expand Down
20 changes: 13 additions & 7 deletions x/feemarket/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"

feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)
Expand All @@ -32,22 +31,23 @@ func newFeeMarketCheckDecorator(fmk FeeMarketKeeper) feeMarketCheckDecorator {
//
// CONTRACT: Tx must implement FeeTx interface
type FeeMarketCheckDecorator struct {
feemarketKeeper FeeMarketKeeper
feemarketKeeper FeeMarketKeeper

feemarketDecorator feeMarketCheckDecorator
cosmosDecorator ante.DeductFeeDecorator
fallbackDecorator sdk.AnteDecorator
}

func NewFeeMarketCheckDecorator(fmk FeeMarketKeeper, ak AccountKeeper, bk BankKeeper, fgk FeeGrantKeeper, txfc ante.TxFeeChecker) FeeMarketCheckDecorator {
func NewFeeMarketCheckDecorator(fmk FeeMarketKeeper, fallbackDecorator sdk.AnteDecorator) FeeMarketCheckDecorator {
return FeeMarketCheckDecorator{
feemarketKeeper: fmk,
feemarketDecorator: newFeeMarketCheckDecorator(
fmk,
),
cosmosDecorator: ante.NewDeductFeeDecorator(ak, bk, fgk, txfc),
fallbackDecorator: fallbackDecorator,
}
}

// AnteHandle calls the feemarket internal antehandler if the keeper is enabled. If disabled, the Cosmos SDK
// AnteHandle calls the feemarket internal antehandler if the keeper is enabled. If disabled, the fallback
// fee antehandler is fallen back to.
func (d FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
params, err := d.feemarketKeeper.GetParams(ctx)
Expand All @@ -57,7 +57,13 @@ func (d FeeMarketCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if params.Enabled {
return d.feemarketDecorator.anteHandle(ctx, tx, simulate, next)
}
return d.cosmosDecorator.AnteHandle(ctx, tx, simulate, next)

// only use fallback if not nil
if d.fallbackDecorator != nil {
return d.fallbackDecorator.AnteHandle(ctx, tx, simulate, next)
}

return next(ctx, tx, simulate)
}

// anteHandle checks if the tx provides sufficient fee to cover the required fee from the fee market.
Expand Down
10 changes: 6 additions & 4 deletions x/feemarket/ante/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ func (s *TestSuite) SetupHandlers(mock bool) {
authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
feemarketante.NewFeeMarketCheckDecorator( // fee market replaces fee deduct decorator
s.FeeMarketKeeper,
s.AccountKeeper,
s.BankKeeper,
s.FeeGrantKeeper,
nil,
authante.NewDeductFeeDecorator(
s.AccountKeeper,
s.BankKeeper,
s.FeeGrantKeeper,
nil,
),
),
authante.NewSigGasConsumeDecorator(s.AccountKeeper, authante.DefaultSigVerificationGasConsumer),
}
Expand Down
Loading