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

chore: added anteHandler and postHandler for feemarket #779

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
10 changes: 10 additions & 0 deletions ante/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
didtypes "github.com/cheqd/cheqd-node/x/did/types"
resourcetypes "github.com/cheqd/cheqd-node/x/resource/types"
sdk "github.com/cosmos/cosmos-sdk/types"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
)

type BankKeeper interface {
Expand All @@ -21,3 +22,12 @@ type DidKeeper interface {
type ResourceKeeper interface {
GetParams(ctx sdk.Context) (params resourcetypes.FeeParams)
}

type FeeMarketKeeper interface {
GetState(ctx sdk.Context) (feemarkettypes.State, error)
GetMinGasPrice(ctx sdk.Context, denom string) (sdk.DecCoin, error)
GetParams(ctx sdk.Context) (feemarkettypes.Params, error)
SetState(ctx sdk.Context, state feemarkettypes.State) error
SetParams(ctx sdk.Context, params feemarkettypes.Params) error
ResolveToDenom(ctx sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error)
}
6 changes: 3 additions & 3 deletions ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ var _ = Describe("Fee tests on DeliverTx", func() {
dfd := cheqdante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, nil, nil)
antehandler := sdk.ChainAnteDecorators(dfd)

taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper)
taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper, s.app.FeeMarketKeeper)
posthandler := sdk.ChainPostDecorators(taxDecorator)

// get supply before tx
Expand Down Expand Up @@ -296,7 +296,7 @@ var _ = Describe("Fee tests on DeliverTx", func() {
dfd := cheqdante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, nil, nil)
antehandler := sdk.ChainAnteDecorators(dfd)

taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper)
taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper, s.app.FeeMarketKeeper)
posthandler := sdk.ChainPostDecorators(taxDecorator)

// get supply before tx
Expand Down Expand Up @@ -353,7 +353,7 @@ var _ = Describe("Fee tests on DeliverTx", func() {
dfd := cheqdante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, nil, nil)
antehandler := sdk.ChainAnteDecorators(dfd)

taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper)
taxDecorator := cheqdpost.NewTaxDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.DidKeeper, s.app.ResourceKeeper, s.app.FeeMarketKeeper)
posthandler := sdk.ChainPostDecorators(taxDecorator)

// get supply before tx
Expand Down
1 change: 1 addition & 0 deletions ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (s *AnteTestSuite) SetupTest(isCheckTx bool) error {
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: sdkante.DefaultSigVerificationGasConsumer,
IBCKeeper: s.app.IBCKeeper,
FeeMarketKeeper: s.app.FeeMarketKeeper,
},
)
if err != nil {
Expand Down
14 changes: 13 additions & 1 deletion app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
Expand All @@ -26,6 +28,7 @@ type HandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
DidKeeper cheqdante.DidKeeper
ResourceKeeper cheqdante.ResourceKeeper
FeeMarketKeeper *feemarketkeeper.Keeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -47,6 +50,9 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.IBCKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for ante builder")
}
if options.FeeMarketKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "FeeMarket keeper is required for AnteHandler")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
Expand All @@ -55,14 +61,20 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cheqdante.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),
// v4 -> v5 ibc-go migration, v6 does not need migration
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
feemarketante.NewFeeMarketCheckDecorator(
options.FeeMarketKeeper,
cheqdante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
options.FeegrantKeeper,
options.TxFeeChecker)),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
46 changes: 32 additions & 14 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

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"

// unnamed import of statik for swagger UI support
_ "github.com/cheqd/cheqd-node/app/client/docs/statik"
)
Expand Down Expand Up @@ -172,19 +176,22 @@ var (
resource.AppModuleBasic{},
ibcfee.AppModuleBasic{},
consensus.AppModuleBasic{},
feemarketmodule.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
didtypes.ModuleName: {authtypes.Burner},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
didtypes.ModuleName: {authtypes.Burner},
feemarkettypes.ModuleName: {authtypes.Burner},
feemarkettypes.FeeCollectorName: {authtypes.Burner},
}
)

Expand Down Expand Up @@ -229,6 +236,7 @@ type App struct {
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
FeeMarketKeeper *feemarketkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
GroupKeeper groupkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
Expand Down Expand Up @@ -310,6 +318,7 @@ func New(
ibcfeetypes.StoreKey,
didtypes.StoreKey,
resourcetypes.StoreKey,
feemarkettypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -493,6 +502,9 @@ func New(
),
)

app.FeeMarketKeeper = feemarketkeeper.NewKeeper(appCodec, keys[feemarkettypes.StoreKey], app.AccountKeeper, &feemarkettypes.TestDenomResolver{}, authtypes.NewModuleAddress(govtypes.ModuleName).String())
app.FeeMarketKeeper.SetDenomResolver(&feemarkettypes.TestDenomResolver{})

// IBC Fee Module keeper
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -638,6 +650,7 @@ func New(
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
icaModule,
feemarketmodule.NewAppModule(appCodec, *app.FeeMarketKeeper),
// cheqd modules
did.NewAppModule(appCodec, app.DidKeeper),
resource.NewAppModule(appCodec, app.ResourceKeeper, app.DidKeeper),
Expand Down Expand Up @@ -673,6 +686,7 @@ func New(
didtypes.ModuleName,
resourcetypes.ModuleName,
consensusparamtypes.ModuleName,
feemarkettypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand Down Expand Up @@ -700,6 +714,7 @@ func New(
icatypes.ModuleName,
ibcfeetypes.ModuleName,
consensusparamtypes.ModuleName,
feemarkettypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -732,6 +747,7 @@ func New(
upgradetypes.ModuleName,
paramstypes.ModuleName,
consensusparamtypes.ModuleName,
feemarkettypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down Expand Up @@ -767,6 +783,7 @@ func New(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: authante.DefaultSigVerificationGasConsumer,
IBCKeeper: app.IBCKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
})
if err != nil {
tmos.Exit(err.Error())
Expand All @@ -783,11 +800,12 @@ func New(
app.sm.RegisterStoreDecoders()

postHandler, err := posthandler.NewPostHandler(posthandler.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
DidKeeper: app.DidKeeper,
ResourceKeeper: app.ResourceKeeper,
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
DidKeeper: app.DidKeeper,
ResourceKeeper: app.ResourceKeeper,
FeeMarketKeeper: app.FeeMarketKeeper,
})
if err != nil {
tmos.Exit(err.Error())
Expand Down
Loading