Skip to content

Commit 2758025

Browse files
stana-miricdusan-maksimovicMSalopekmpoke
authored
feat!: Introduce feemarket module (#3028)
* Added feemarket module Co-authored-by: Dusan Maksimovic <[email protected]> * Added blocksdk support Co-authored-by: Dusan Maksimovic <[email protected]> * Removed globalfee from app Co-authored-by: Dusan Maksimovic <[email protected]> * Cleanup and lint fix Co-authored-by: Dusan Maksimovic <[email protected]> * added post-handler and test for feemarket Co-authored-by: Stana Miric <[email protected]> * tests fix part 1 Co-authored-by: Dusan Maksimovic <[email protected]> * test fix part 2 Co-authored-by: Dusan Maksimovic <[email protected]> * added changelog Co-authored-by: Dusan Maksimovic <[email protected]> * update x/feemarket dependency * fix broken dep update for feemarket * Fixed merge errors & unit tests Co-authored-by: Stana Miric <[email protected]> * Removed Skip Block SDK Co-authored-by: Stana Miric <[email protected]> * set upgrade params and test fixes * fix e2e tests & cleanup * merge fix * globalfee module removed from the repository * simplify the check for expected user balances in e2e tests * upgrade to a new version of the feemarket & minimum fees enforcement if feemarket is disabled * deps: bump feemarket v1.0.2-sdk47; bump hermes v1.9.0 * scripts: update hermes configs * update changelogs (depr x/globalfee) * e2e: change sequence on validator genesis acc * e2e: mv hermes calls in ibc_tests * e2e: adjust gas in staking ops * e2e: mv extension tests; update feegrant tests * deps: bump feemarket v1.0.3-sdk47 * Update .changelog/unreleased/features/3028-add-feemarket Co-authored-by: Marius Poke <[email protected]> * Update .changelog/unreleased/state-breaking/3028-add-feemarket Co-authored-by: Marius Poke <[email protected]> * update changelogs --------- Co-authored-by: Dusan Maksimovic <[email protected]> Co-authored-by: MSalopek <[email protected]> Co-authored-by: Marius Poke <[email protected]>
1 parent f6b45e2 commit 2758025

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1273
-5398
lines changed

.changelog/config.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ entry_indent = 2
1515
# to Markdown) and a path relative to the project folder (i.e. relative to
1616
# the parent of the `.changelog` folder).
1717
[components.all]
18-
globalfee = { name = "GlobalFee", path = "x/globalfee" }
1918
tests = { name = "Tests", path = "tests" }
2019
docs = { name = "Documentation", path = "docs" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Add feemarket module
2+
- Remove globalfee module from the app and repository
3+
- Remove auth module 'DeductFeeDecorator'
4+
- Remove x/globalfee module
5+
([\#3028](https://github.com/cosmos/gaia/pull/3028))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Bump go version to 1.22
2+
([\#3028](https://github.com/cosmos/gaia/pull/3028))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the feemarket module. Remove the auth module 'DeductFeeDecorator'.
2+
([\#3028](https://github.com/cosmos/gaia/pull/3028))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Add the feemarket module. Remove the globalfee module from the app and repository. Remove the auth module 'DeductFeeDecorator'.
2+
([\#3028](https://github.com/cosmos/gaia/pull/3028))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Add feemarket module
2+
- Remove globalfee module from the app and repository
3+
- Remove auth module 'DeductFeeDecorator'
4+
- Remove x/globalfee module
5+
([\#3028](https://github.com/cosmos/gaia/pull/3028))

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ where:
247247
not necessarily with the same `short-description` or content;
248248
- `pr-number` is the PR number;
249249
- `short-description` is a short (4 to 6 word), hyphen separated description of the change;
250-
- `component` is used for changes that affect one of the components defined in the [config](.changelog/config.toml), e.g., `tests`, `globalfee`.
250+
- `component` is used for changes that affect one of the components defined in the [config](.changelog/config.toml), e.g., `tests`, `docs`.
251251
252252
For examples, see the [.changelog](.changelog) folder.
253253

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BUILDDIR ?= $(CURDIR)/build
2121
TEST_DOCKER_REPO=cosmos/contrib-gaiatest
2222

2323
GO_SYSTEM_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1-2)
24-
REQUIRE_GO_VERSION = 1.21
24+
REQUIRE_GO_VERSION = 1.22
2525

2626
export GO111MODULE = on
2727

ante/ante.go

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package ante
22

33
import (
4+
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante"
5+
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
6+
47
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
58
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
69

@@ -9,22 +12,23 @@ import (
912
"github.com/cosmos/cosmos-sdk/codec"
1013
sdk "github.com/cosmos/cosmos-sdk/types"
1114
"github.com/cosmos/cosmos-sdk/x/auth/ante"
12-
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
1315
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
1416

1517
gaiaerrors "github.com/cosmos/gaia/v18/types/errors"
16-
gaiafeeante "github.com/cosmos/gaia/v18/x/globalfee/ante"
1718
)
1819

20+
// UseFeeMarketDecorator to make the integration testing easier: we can switch off its ante and post decorators with this flag
21+
var UseFeeMarketDecorator = true
22+
1923
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
2024
// channel keeper.
2125
type HandlerOptions struct {
2226
ante.HandlerOptions
23-
Codec codec.BinaryCodec
24-
IBCkeeper *ibckeeper.Keeper
25-
GlobalFeeSubspace paramtypes.Subspace
26-
StakingKeeper *stakingkeeper.Keeper
27-
TxFeeChecker ante.TxFeeChecker
27+
Codec codec.BinaryCodec
28+
IBCkeeper *ibckeeper.Keeper
29+
StakingKeeper *stakingkeeper.Keeper
30+
FeeMarketKeeper *feemarketkeeper.Keeper
31+
TxFeeChecker ante.TxFeeChecker
2832
}
2933

3034
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
@@ -40,9 +44,8 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
4044
if opts.IBCkeeper == nil {
4145
return nil, errorsmod.Wrap(gaiaerrors.ErrLogic, "IBC keeper is required for AnteHandler")
4246
}
43-
44-
if opts.GlobalFeeSubspace.Name() == "" {
45-
return nil, errorsmod.Wrap(gaiaerrors.ErrNotFound, "globalfee param store is required for AnteHandler")
47+
if opts.FeeMarketKeeper == nil {
48+
return nil, errorsmod.Wrap(gaiaerrors.ErrLogic, "FeeMarket keeper is required for AnteHandler")
4649
}
4750

4851
if opts.StakingKeeper == nil {
@@ -62,8 +65,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
6265
ante.NewValidateMemoDecorator(opts.AccountKeeper),
6366
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
6467
NewGovVoteDecorator(opts.Codec, opts.StakingKeeper),
65-
gaiafeeante.NewFeeDecorator(opts.GlobalFeeSubspace, opts.StakingKeeper),
66-
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker),
6768
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
6869
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
6970
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
@@ -72,5 +73,16 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
7273
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
7374
}
7475

76+
if UseFeeMarketDecorator {
77+
anteDecorators = append(anteDecorators,
78+
feemarketante.NewFeeMarketCheckDecorator(
79+
opts.FeeMarketKeeper,
80+
ante.NewDeductFeeDecorator(
81+
opts.AccountKeeper,
82+
opts.BankKeeper,
83+
opts.FeegrantKeeper,
84+
opts.TxFeeChecker)))
85+
}
86+
7587
return sdk.ChainAnteDecorators(anteDecorators...), nil
7688
}

app/app.go

+53-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/gorilla/mux"
1111
"github.com/rakyll/statik/fs"
12+
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
1213
"github.com/spf13/cast"
1314

1415
// unnamed import of statik for swagger UI support
@@ -56,7 +57,6 @@ import (
5657
"github.com/cosmos/gaia/v18/app/params"
5758
"github.com/cosmos/gaia/v18/app/upgrades"
5859
v18 "github.com/cosmos/gaia/v18/app/upgrades/v18"
59-
"github.com/cosmos/gaia/v18/x/globalfee"
6060
)
6161

6262
var (
@@ -223,20 +223,34 @@ func NewGaiaApp(
223223
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
224224
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
225225
},
226-
Codec: appCodec,
227-
IBCkeeper: app.IBCKeeper,
228-
GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName),
229-
StakingKeeper: app.StakingKeeper,
230-
// If TxFeeChecker is nil the default ante TxFeeChecker is used
231-
// so we use this no-op to keep the global fee module behaviour unchanged
232-
TxFeeChecker: noOpTxFeeChecker,
226+
Codec: appCodec,
227+
IBCkeeper: app.IBCKeeper,
228+
StakingKeeper: app.StakingKeeper,
229+
FeeMarketKeeper: app.FeeMarketKeeper,
230+
TxFeeChecker: func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
231+
return minTxFeesChecker(ctx, tx, *app.FeeMarketKeeper)
232+
},
233233
},
234234
)
235235
if err != nil {
236236
panic(fmt.Errorf("failed to create AnteHandler: %s", err))
237237
}
238238

239+
postHandlerOptions := PostHandlerOptions{
240+
AccountKeeper: app.AccountKeeper,
241+
BankKeeper: app.BankKeeper,
242+
FeeGrantKeeper: app.FeeGrantKeeper,
243+
FeeMarketKeeper: app.FeeMarketKeeper,
244+
}
245+
postHandler, err := NewPostHandler(postHandlerOptions)
246+
if err != nil {
247+
panic(err)
248+
}
249+
250+
// set ante and post handlers
239251
app.SetAnteHandler(anteHandler)
252+
app.SetPostHandler(postHandler)
253+
240254
app.SetInitChainer(app.InitChainer)
241255
app.SetBeginBlocker(app.BeginBlocker)
242256
app.SetEndBlocker(app.EndBlocker)
@@ -442,13 +456,41 @@ func (ao EmptyAppOptions) Get(_ string) interface{} {
442456
return nil
443457
}
444458

445-
// noOpTxFeeChecker is an ante TxFeeChecker for the DeductFeeDecorator, see x/auth/ante/fee.go,
446-
// it performs a no-op by not checking tx fees and always returns a zero tx priority
447-
func noOpTxFeeChecker(_ sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
459+
// minTxFeesChecker will be executed only if the feemarket module is disabled.
460+
// In this case, the auth module's DeductFeeDecorator is executed, and
461+
// we use the minTxFeesChecker to enforce the minimum transaction fees.
462+
// Min tx fees are calculated as gas_limit * feemarket_min_base_gas_price
463+
func minTxFeesChecker(ctx sdk.Context, tx sdk.Tx, feemarketKp feemarketkeeper.Keeper) (sdk.Coins, int64, error) {
448464
feeTx, ok := tx.(sdk.FeeTx)
449465
if !ok {
450466
return nil, 0, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
451467
}
452468

469+
// To keep the gentxs with zero fees, we need to skip the validation in the first block
470+
if ctx.BlockHeight() == 0 {
471+
return feeTx.GetFee(), 0, nil
472+
}
473+
474+
feeMarketParams, err := feemarketKp.GetParams(ctx)
475+
if err != nil {
476+
return nil, 0, err
477+
}
478+
479+
feeRequired := sdk.NewCoins(
480+
sdk.NewCoin(
481+
feeMarketParams.FeeDenom,
482+
feeMarketParams.MinBaseGasPrice.MulInt(sdk.NewIntFromUint64(feeTx.GetGas())).Ceil().RoundInt()))
483+
484+
feeCoins := feeTx.GetFee()
485+
if len(feeCoins) != 1 {
486+
return nil, 0, fmt.Errorf(
487+
"expected exactly one fee coin; got %s, required: %s", feeCoins.String(), feeRequired.String())
488+
}
489+
490+
if !feeCoins.IsAnyGTE(feeRequired) {
491+
return nil, 0, fmt.Errorf(
492+
"not enough fees provided; got %s, required: %s", feeCoins.String(), feeRequired.String())
493+
}
494+
453495
return feeTx.GetFee(), 0, nil
454496
}

app/keepers/keepers.go

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package keepers
22

33
import (
4+
"fmt"
45
"os"
56

67
ratelimit "github.com/Stride-Labs/ibc-rate-limiting/ratelimit"
78
ratelimitkeeper "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/keeper"
89
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
10+
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
11+
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
912

1013
// unnamed import of statik for swagger UI support
1114
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
@@ -77,8 +80,6 @@ import (
7780
"github.com/cosmos/cosmos-sdk/x/upgrade"
7881
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
7982
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
80-
81-
"github.com/cosmos/gaia/v18/x/globalfee"
8283
)
8384

8485
type AppKeepers struct {
@@ -108,6 +109,7 @@ type AppKeepers struct {
108109
FeeGrantKeeper feegrantkeeper.Keeper
109110
AuthzKeeper authzkeeper.Keeper
110111
ConsensusParamsKeeper consensusparamkeeper.Keeper
112+
FeeMarketKeeper *feemarketkeeper.Keeper
111113

112114
// ICS
113115
ProviderKeeper icsproviderkeeper.Keeper
@@ -278,6 +280,14 @@ func NewAppKeeper(
278280
),
279281
)
280282

283+
appKeepers.FeeMarketKeeper = feemarketkeeper.NewKeeper(
284+
appCodec,
285+
appKeepers.keys[feemarkettypes.StoreKey],
286+
appKeepers.AccountKeeper,
287+
&DefaultFeemarketDenomResolver{},
288+
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
289+
)
290+
281291
// UpgradeKeeper must be created before IBCKeeper
282292
appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper(
283293
skipUpgradeHeights,
@@ -514,8 +524,21 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
514524
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
515525
paramsKeeper.Subspace(pfmroutertypes.ModuleName).WithKeyTable(pfmroutertypes.ParamKeyTable())
516526
paramsKeeper.Subspace(ratelimittypes.ModuleName)
517-
paramsKeeper.Subspace(globalfee.ModuleName)
518527
paramsKeeper.Subspace(providertypes.ModuleName)
519528

520529
return paramsKeeper
521530
}
531+
532+
type DefaultFeemarketDenomResolver struct{}
533+
534+
func (r *DefaultFeemarketDenomResolver) ConvertToDenom(_ sdk.Context, coin sdk.DecCoin, denom string) (sdk.DecCoin, error) {
535+
if coin.Denom == denom {
536+
return coin, nil
537+
}
538+
539+
return sdk.DecCoin{}, fmt.Errorf("error resolving denom")
540+
}
541+
542+
func (r *DefaultFeemarketDenomResolver) ExtraDenoms(_ sdk.Context) ([]string, error) {
543+
return []string{}, nil
544+
}

app/keepers/keys.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keepers
22

33
import (
44
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
5+
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
56

67
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
78
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
@@ -57,6 +58,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
5758
ratelimittypes.StoreKey,
5859
providertypes.StoreKey,
5960
consensusparamtypes.StoreKey,
61+
feemarkettypes.StoreKey,
6062
)
6163

6264
// Define transient store keys

0 commit comments

Comments
 (0)