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: globalfee module #99

Merged
merged 3 commits into from
Oct 12, 2023
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
17 changes: 17 additions & 0 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ package app

import (
errorsmod "cosmossdk.io/errors"
globalfeeante "github.com/OmniFlix/omniflixhub/v2/x/globalfee/ante"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
)

// Lower back to 1 mil after https://github.com/cosmos/relayer/issues/1255
const maxBypassMinFeeMsgGasUsage = 2_000_000

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
Expand All @@ -21,6 +27,11 @@ type HandlerOptions struct {
IBCKeeper *ibckeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
Codec codec.BinaryCodec

BypassMinFeeMsgTypes []string

GlobalFeeKeeper globalfeekeeper.Keeper
StakingKeeper stakingkeeper.Keeper
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand All @@ -46,6 +57,12 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
globalfeeante.NewFeeDecorator(
options.BypassMinFeeMsgTypes,
options.GlobalFeeKeeper,
options.StakingKeeper,
maxBypassMinFeeMsgGasUsage,
),
ante.NewDeductFeeDecorator(
options.AccountKeeper,
options.BankKeeper,
Expand Down
30 changes: 29 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"

"github.com/OmniFlix/omniflixhub/v2/app/openapiconsole"
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/docs"
Expand Down Expand Up @@ -39,9 +40,13 @@ import (
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
"github.com/spf13/cast"

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"

"github.com/OmniFlix/omniflixhub/v2/app/keepers"
"github.com/OmniFlix/omniflixhub/v2/app/upgrades"
v012 "github.com/OmniFlix/omniflixhub/v2/app/upgrades/v012"
Expand Down Expand Up @@ -211,6 +216,10 @@ func NewOmniFlixApp(
GovKeeper: app.GovKeeper,
IBCKeeper: app.IBCKeeper,
Codec: appCodec,

BypassMinFeeMsgTypes: GetDefaultBypassFeeMessages(),
GlobalFeeKeeper: app.GlobalFeeKeeper,
StakingKeeper: *app.StakingKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -394,3 +403,22 @@ func GetMaccPerms() map[string][]string {
}
return dupMaccPerms
}

func GetDefaultBypassFeeMessages() []string {
return []string{
// IBC messages
sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}),
sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}),
sdk.MsgTypeURL(&ibctransfertypes.MsgTransfer{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgTimeout{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgTimeoutOnClose{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgChannelOpenTry{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgChannelOpenConfirm{}),
sdk.MsgTypeURL(&ibcchanneltypes.MsgChannelOpenAck{}),
}
}

func (app *OmniFlixApp) GetChainBondDenom() string {
return "uflix"
}
13 changes: 13 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keepers

import (
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -40,6 +41,9 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

"github.com/OmniFlix/omniflixhub/v2/x/globalfee"
globalfeekeeper "github.com/OmniFlix/omniflixhub/v2/x/globalfee/keeper"

mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"

Expand Down Expand Up @@ -116,6 +120,7 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -217,6 +222,7 @@ func NewAppKeeper(
keys[feegrant.StoreKey],
appKeepers.AccountKeeper,
)

appKeepers.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
Expand Down Expand Up @@ -357,6 +363,12 @@ func NewAppKeeper(
)
icaHostIBCModule := icahost.NewIBCModule(appKeepers.ICAHostKeeper)

appKeepers.GlobalFeeKeeper = globalfeekeeper.NewKeeper(
appCodec,
keys[globalfeetypes.StoreKey],
govModAddress,
)

appKeepers.AllocKeeper = *allockeeper.NewKeeper(
appCodec,
appKeepers.keys[alloctypes.StoreKey],
Expand Down Expand Up @@ -450,6 +462,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(alloctypes.ModuleName)
paramsKeeper.Subspace(onfttypes.ModuleName)
paramsKeeper.Subspace(marketplacetypes.ModuleName)
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keepers

import (
alloctypes "github.com/OmniFlix/omniflixhub/v2/x/alloc/types"
globalfeetypes "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types"
itctypes "github.com/OmniFlix/omniflixhub/v2/x/itc/types"
marketplacetypes "github.com/OmniFlix/omniflixhub/v2/x/marketplace/types"
onfttypes "github.com/OmniFlix/onft/types"
Expand Down Expand Up @@ -49,6 +50,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
capabilitytypes.StoreKey,
crisistypes.StoreKey,
feegrant.StoreKey,
globalfeetypes.StoreKey,
authzkeeper.StoreKey,
alloctypes.StoreKey,
onfttypes.StoreKey,
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
appparams "github.com/OmniFlix/omniflixhub/v2/app/params"
"github.com/OmniFlix/omniflixhub/v2/x/globalfee"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
Expand Down Expand Up @@ -107,6 +108,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
globalfee.AppModuleBasic{},

alloc.AppModuleBasic{},
onft.AppModuleBasic{},
Expand All @@ -126,6 +128,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
globalfee.ModuleName: nil,
alloctypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
onfttypes.ModuleName: nil,
marketplacetypes.ModuleName: nil,
Expand All @@ -140,6 +143,7 @@ func appModules(
skipGenesisInvariants bool,
) []module.AppModule {
appCodec := encodingConfig.Marshaler
bondDenom := app.GetChainBondDenom()
return []module.AppModule{
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
Expand Down Expand Up @@ -191,6 +195,7 @@ func appModules(
transfer.NewAppModule(app.TransferKeeper),
ica.NewAppModule(nil, &app.ICAHostKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper),
globalfee.NewAppModule(appCodec, app.GlobalFeeKeeper, bondDenom),
alloc.NewAppModule(appCodec, app.AllocKeeper, app.GetSubspace(alloctypes.ModuleName)),
onft.NewAppModule(
appCodec,
Expand Down Expand Up @@ -272,6 +277,7 @@ func orderBeginBlockers() []string {
authtypes.ModuleName,
crisistypes.ModuleName,
feegrant.ModuleName,
globalfee.ModuleName,
onfttypes.ModuleName,
marketplacetypes.ModuleName,
streampaytypes.ModuleName,
Expand Down Expand Up @@ -301,6 +307,7 @@ func orderEndBlockers() []string {
distrtypes.ModuleName,
ibcexported.ModuleName,
feegrant.ModuleName,
globalfee.ModuleName,
authz.ModuleName,
alloctypes.ModuleName,
onfttypes.ModuleName,
Expand Down Expand Up @@ -338,6 +345,7 @@ func orderInitGenesis() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
feegrant.ModuleName,
globalfee.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ require (
google.golang.org/protobuf v1.31.0
)

require github.com/gogo/protobuf v1.3.2 // indirect

require (
cosmossdk.io/api v0.3.1
cosmossdk.io/errors v1.0.0
cosmossdk.io/math v1.1.2
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/compute v1.20.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.0 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/api v0.3.1
cosmossdk.io/core v0.5.1 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0
cosmossdk.io/log v1.2.1 // indirect
cosmossdk.io/math v1.1.2
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down Expand Up @@ -84,7 +86,6 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down
43 changes: 43 additions & 0 deletions proto/OmniFlix/globalfee/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
syntax = "proto3";
package OmniFlix.globalfee.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types";

// GenesisState - initial state of module
message GenesisState {
// Params of this module
Params params = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "params,omitempty"
];
}

// Params defines the set of module parameters.
message Params {
// minimum_gas_prices stores the minimum gas price(s) for all TX on the chain.
// When multiple coins are defined then they are accepted alternatively.
// The list must be sorted by denoms asc. No duplicate denoms or zero amount
// values allowed. For more information see
// https://docs.cosmos.network/main/modules/auth#concepts
repeated cosmos.base.v1beta1.DecCoin minimum_gas_prices = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "minimum_gas_prices,omitempty",
(gogoproto.moretags) = "yaml:\"minimum_gas_prices\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];

// bypass_min_fee_msg_types defines a list of message type urls
// that are free of fee charge.
repeated string bypass_min_fee_msg_types = 2 [
(gogoproto.jsontag) = "bypass_min_fee_msg_types,omitempty",
(gogoproto.moretags) = "yaml:\"bypass_min_fee_msg_types\""
];

// max_total_bypass_min_fee_msg_gas_usage defines the total maximum gas usage
// allowed for a transaction containing only messages of types in bypass_min_fee_msg_types
// to bypass fee charge.
uint64 max_total_bypass_min_fee_msg_gas_usage = 3;
}
27 changes: 27 additions & 0 deletions proto/OmniFlix/globalfee/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";
package OmniFlix.globalfee.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "OmniFlix/globalfee/v1beta1/genesis.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types";

// Query defines the gRPC querier service.
service Query {
rpc Params(QueryParamsRequest)
returns (QueryParamsResponse) {
option (google.api.http).get =
"/omniflix/globalfee/v1beta1/params";
}
}

// QueryMinimumGasPricesRequest is the request type for the
// Query/MinimumGasPrices RPC method.
message QueryParamsRequest {}

// QueryMinimumGasPricesResponse is the response type for the
// Query/MinimumGasPrices RPC method.
message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}
40 changes: 40 additions & 0 deletions proto/OmniFlix/globalfee/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
syntax = "proto3";
package OmniFlix.globalfee.v1beta1;


import "cosmos/msg/v1/msg.proto";
import "OmniFlix/globalfee/v1beta1/genesis.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/OmniFlix/omniflixhub/v2/x/globalfee/types";

// Msg defines the x/globalfee Msg service.
service Msg {
// UpdateParams defines a governance operation for updating the x/globalfee module
// parameters. The authority is hard-coded to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/mint parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
6 changes: 6 additions & 0 deletions x/globalfee/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Global fee module

The Global fee module was supplied by the great folks at [TGrade](https://github.com/confio/tgrade) 👋, minor modifications done by [cosmoshub](https://github.com/cosmos/gaia/tree/main/x/globalfee) team.
All credits and big thanks go to the original authors and cosmoshub team.

More information about global fee system please check [here](../../docs/modules/globalfee.md).
Loading
Loading