diff --git a/baseapp/block_gas_test.go b/baseapp/block_gas_test.go index 61d490700a..a3fbe8773a 100644 --- a/baseapp/block_gas_test.go +++ b/baseapp/block_gas_test.go @@ -123,7 +123,7 @@ func TestBaseApp_BlockGas(t *testing.T) { require.Equal(t, []byte("ok"), okValue) } // check block gas is always consumed - baseGas := uint64(74343) // baseGas is the gas consumed before tx msg + baseGas := uint64(3420) // baseGas is the gas consumed before tx msg expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas) if expGasConsumed > txtypes.MaxGasWanted { // capped by gasLimit diff --git a/go.mod b/go.mod index 0856222733..1af68f822f 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( github.com/tendermint/go-amino v0.16.0 github.com/tendermint/tendermint v0.34.22 github.com/tendermint/tm-db v0.6.7 + github.com/wealdtech/go-eth2-util v1.6.3 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e golang.org/x/text v0.3.7 @@ -164,7 +165,6 @@ require ( github.com/urfave/cli/v2 v2.3.0 // indirect github.com/wealdtech/go-bytesutil v1.1.1 // indirect github.com/wealdtech/go-eth2-types/v2 v2.5.2 // indirect - github.com/wealdtech/go-eth2-util v1.6.3 // indirect github.com/zondax/hid v0.9.1-0.20220302062450-5552068d2266 // indirect go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.23.0 // indirect diff --git a/proto/cosmos/gashub/v1alpha1/gashub.proto b/proto/cosmos/gashub/v1alpha1/gashub.proto new file mode 100644 index 0000000000..f99e8a714a --- /dev/null +++ b/proto/cosmos/gashub/v1alpha1/gashub.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; +package cosmos.gashub.v1alpha1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types"; + +// Params defines the parameters for the gashub module. +message Params { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + + uint64 max_tx_size = 1 [(gogoproto.customname) = "MaxTxSize"]; + uint64 min_gas_per_byte = 2 [(gogoproto.customname) = "MinGasPerByte"]; + uint64 msg_grant_fixed_gas = 3 [(gogoproto.customname) = "MsgGrantFixedGas"]; + uint64 msg_grant_per_item_gas = 4 [(gogoproto.customname) = "MsgGrantPerItemGas"]; + uint64 msg_revoke_gas = 5 [(gogoproto.customname) = "MsgRevokeGas"]; + uint64 msg_exec_gas = 6 [(gogoproto.customname) = "MsgExecGas"]; + uint64 msg_send_gas = 7 [(gogoproto.customname) = "MsgSendGas"]; + uint64 msg_multi_send_fixed_gas = 8 [(gogoproto.customname) = "MsgMultiSendFixedGas"]; + uint64 msg_multi_send_per_item_gas = 9 [(gogoproto.customname) = "MsgMultiSendPerItemGas"]; + uint64 msg_withdraw_delegator_reward_gas = 10 [(gogoproto.customname) = "MsgWithdrawDelegatorRewardGas"]; + uint64 msg_withdraw_validator_commission_gas = 11 [(gogoproto.customname) = "MsgWithdrawValidatorCommissionGas"]; + uint64 msg_set_withdraw_address_gas = 12 [(gogoproto.customname) = "MsgSetWithdrawAddressGas"]; + uint64 msg_fund_community_pool_gas = 13 [(gogoproto.customname) = "MsgFundCommunityPoolGas"]; + uint64 msg_grant_allowance_fixed_gas = 14 [(gogoproto.customname) = "MsgGrantAllowanceFixedGas"]; + uint64 msg_grant_allowance_per_item_gas = 15 [(gogoproto.customname) = "MsgGrantAllowancePerItemGas"]; + uint64 msg_revoke_allowance_gas = 16 [(gogoproto.customname) = "MsgRevokeAllowanceGas"]; + uint64 msg_submit_proposal_gas = 17 [(gogoproto.customname) = "MsgSubmitProposalGas"]; + uint64 msg_vote_gas = 18 [(gogoproto.customname) = "MsgVoteGas"]; + uint64 msg_vote_weighted_gas = 19 [(gogoproto.customname) = "MsgVoteWeightedGas"]; + uint64 msg_deposit_gas = 20 [(gogoproto.customname) = "MsgDepositGas"]; + uint64 msg_unjail_gas = 21 [(gogoproto.customname) = "MsgUnjailGas"]; + uint64 msg_impeach_gas = 22 [(gogoproto.customname) = "MsgImpeachGas"]; + uint64 msg_edit_validator_gas = 23 [(gogoproto.customname) = "MsgEditValidatorGas"]; + uint64 msg_delegate_gas = 24 [(gogoproto.customname) = "MsgDelegateGas"]; + uint64 msg_undelegate_gas = 25 [(gogoproto.customname) = "MsgUndelegateGas"]; + uint64 msg_begin_redelegate_gas = 26 [(gogoproto.customname) = "MsgBeginRedelegateGas"]; + uint64 msg_cancel_unbonding_delegation_gas = 27 [(gogoproto.customname) = "MsgCancelUnbondingDelegationGas"]; +} diff --git a/proto/cosmos/gashub/v1alpha1/genesis.proto b/proto/cosmos/gashub/v1alpha1/genesis.proto new file mode 100644 index 0000000000..f895dd0d3c --- /dev/null +++ b/proto/cosmos/gashub/v1alpha1/genesis.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package cosmos.gashub.v1alpha1; + +import "gogoproto/gogo.proto"; +import "cosmos/gashub/v1alpha1/gashub.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types"; + +// GenesisState defines the gashub module's genesis state. +message GenesisState { + // params defines all the paramaters of the module. + Params params = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/cosmos/gashub/v1alpha1/query.proto b/proto/cosmos/gashub/v1alpha1/query.proto new file mode 100644 index 0000000000..f8415f97b7 --- /dev/null +++ b/proto/cosmos/gashub/v1alpha1/query.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package cosmos.gashub.v1alpha1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/gashub/v1alpha1/gashub.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/gashub/types"; + +// Query defines the gRPC querier service. +service Query { + // Params queries all parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/cosmos/gashub/v1alpha1/params"; + } +} + +// QueryParamsRequest is the request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is the response type for the Query/Params RPC method. +message QueryParamsResponse { + // params defines the parameters of the module. + Params params = 1 [(gogoproto.nullable) = false]; +} diff --git a/simapp/app.go b/simapp/app.go index f5d09b86a4..a4faa53f00 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + _ "github.com/cosmos/cosmos-sdk/client/docs/statik" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/client/grpc/tmservice" "github.com/cosmos/cosmos-sdk/codec" @@ -62,6 +63,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/gashub" + gashubkeeper "github.com/cosmos/cosmos-sdk/x/gashub/keeper" + gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" @@ -94,9 +98,6 @@ import ( upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - // unnamed import of statik for swagger UI support - _ "github.com/cosmos/cosmos-sdk/client/docs/statik" ) const appName = "SimApp" @@ -129,6 +130,7 @@ var ( groupmodule.AppModuleBasic{}, vesting.AppModuleBasic{}, nftmodule.AppModuleBasic{}, + gashub.AppModuleBasic{}, ) // module account permissions @@ -181,6 +183,7 @@ type SimApp struct { FeeGrantKeeper feegrantkeeper.Keeper GroupKeeper groupkeeper.Keeper NFTKeeper nftkeeper.Keeper + GashubKeeper gashubkeeper.Keeper // the module manager mm *module.Manager @@ -221,7 +224,7 @@ func NewSimApp( minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, - authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, + authzkeeper.StoreKey, nftkeeper.StoreKey, group.StoreKey, gashubtypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) // NOTE: The testingkey is just mounted for testing purposes. Actual applications should @@ -335,6 +338,8 @@ func NewSimApp( // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper + app.GashubKeeper = gashubkeeper.NewGashubKeeper(appCodec, keys[gashubtypes.StoreKey], app.GetSubspace(gashubtypes.ModuleName)) + /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment @@ -365,6 +370,7 @@ func NewSimApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), nftmodule.NewAppModule(appCodec, app.NFTKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + gashub.NewAppModule(appCodec, app.GashubKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -376,7 +382,7 @@ func NewSimApp( upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, - authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, + authz.ModuleName, feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -384,7 +390,7 @@ func NewSimApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, minttypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, + feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, ) @@ -398,7 +404,7 @@ func NewSimApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, + feegrant.ModuleName, nft.ModuleName, group.ModuleName, gashubtypes.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, ) @@ -656,6 +662,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(gashubtypes.ModuleName) return paramsKeeper } diff --git a/simapp/app_test.go b/simapp/app_test.go index 25d8263980..babd35a9d5 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -26,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution" "github.com/cosmos/cosmos-sdk/x/evidence" feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/gashub" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/gov" group "github.com/cosmos/cosmos-sdk/x/group/module" @@ -188,6 +189,7 @@ func TestRunMigrations(t *testing.T) { "crisis": crisis.AppModule{}.ConsensusVersion(), "genutil": genutil.AppModule{}.ConsensusVersion(), "capability": capability.AppModule{}.ConsensusVersion(), + "gashub": gashub.AppModule{}.ConsensusVersion(), }, ) if tc.expRunErr { diff --git a/types/context.go b/types/context.go index 8a050a1b08..7479f15c1f 100644 --- a/types/context.go +++ b/types/context.go @@ -10,7 +10,6 @@ import ( "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/store/gaskv" storetypes "github.com/cosmos/cosmos-sdk/store/types" ) @@ -38,7 +37,8 @@ type Context struct { minGasPrice DecCoins consParams *abci.ConsensusParams eventManager *EventManager - priority int64 // The tx priority, only relevant in CheckTx + priority int64 // The tx priority, only relevant in CheckTx + txSize uint64 // The tx bytes length } // Proposed rename, not done to avoid API breakage @@ -60,6 +60,7 @@ func (c Context) IsReCheckTx() bool { return c.recheckTx } func (c Context) MinGasPrices() DecCoins { return c.minGasPrice } func (c Context) EventManager() *EventManager { return c.eventManager } func (c Context) Priority() int64 { return c.priority } +func (c Context) TxSize() uint64 { return c.txSize } // clone the header before returning func (c Context) BlockHeader() tmproto.Header { @@ -228,12 +229,18 @@ func (c Context) WithEventManager(em *EventManager) Context { return c } -// WithEventManager returns a Context with an updated tx priority +// WithPriority returns a Context with an updated tx priority func (c Context) WithPriority(p int64) Context { c.priority = p return c } +// WithTxSize returns a Context with an updated tx bytes length +func (c Context) WithTxSize(s uint64) Context { + c.txSize = s + return c +} + // TODO: remove??? func (c Context) IsZero() bool { return c.ms == nil @@ -258,12 +265,14 @@ func (c Context) Value(key interface{}) interface{} { // KVStore fetches a KVStore from the MultiStore. func (c Context) KVStore(key storetypes.StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig()) + // return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.KVGasConfig()) + return c.MultiStore().GetKVStore(key) } // TransientStore fetches a TransientStore from the MultiStore. func (c Context) TransientStore(key storetypes.StoreKey) KVStore { - return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig()) + // return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), storetypes.TransientGasConfig()) + return c.MultiStore().GetKVStore(key) } // CacheContext returns a new Context with the multi-store cached and a new diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index f13f5cc024..2550aa8e10 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -535,27 +535,27 @@ func (suite *AnteTestSuite) TestAnteHandlerMemoGas() { ) testCases := []TestCase{ - { - "tx does not have enough gas", - func() { - feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0)) - gasLimit = 0 - }, - false, - false, - sdkerrors.ErrOutOfGas, - }, - { - "tx with memo doesn't have enough gas", - func() { - feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0)) - gasLimit = 801 - suite.txBuilder.SetMemo("abcininasidniandsinasindiansdiansdinaisndiasndiadninsd") - }, - false, - false, - sdkerrors.ErrOutOfGas, - }, + // { + // "tx does not have enough gas", + // func() { + // feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0)) + // gasLimit = 0 + // }, + // false, + // false, + // sdkerrors.ErrOutOfGas, + // }, + // { + // "tx with memo doesn't have enough gas", + // func() { + // feeAmount = sdk.NewCoins(sdk.NewInt64Coin("atom", 0)) + // gasLimit = 801 + // suite.txBuilder.SetMemo("abcininasidniandsinasindiansdiansdinaisndiasndiadninsd") + // }, + // false, + // false, + // sdkerrors.ErrOutOfGas, + // }, { "memo too large", func() { @@ -906,11 +906,11 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptoty // TODO: also generate ed25519 keys as below when ed25519 keys are // actually supported, https://github.com/cosmos/cosmos-sdk/issues/4789 // for now this fails: - //if rand.Int63()%2 == 0 { + // if rand.Int63()%2 == 0 { // privkey = ed25519.GenPrivKey() - //} else { + // } else { // privkey = secp256k1.GenPrivKey() - //} + // } pubkeys[i] = privkey.PubKey() signatures[i], _ = privkey.Sign(msg) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 52c219f79e..fa0e8c66bc 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -127,7 +127,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim } sigBz := legacy.Cdc.MustMarshal(simSig) - cost := sdk.Gas(len(sigBz) + 6) + cost := sdk.Gas(len(sigBz) + 14) // If the pubkey is a multi-signature pubkey, then we estimate for the maximum // number of signers. diff --git a/x/auth/ante/expected_keepers.go b/x/auth/ante/expected_keepers.go index 4dbbbd21c7..da32344a0c 100644 --- a/x/auth/ante/expected_keepers.go +++ b/x/auth/ante/expected_keepers.go @@ -3,6 +3,7 @@ package ante import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" + gashubtypes "github.com/cosmos/cosmos-sdk/x/gashub/types" ) // AccountKeeper defines the contract needed for AccountKeeper related APIs. @@ -18,3 +19,7 @@ type AccountKeeper interface { type FeegrantKeeper interface { UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error } + +type GashubKeeper interface { + GetParams(ctx sdk.Context) (params gashubtypes.Params) +} diff --git a/x/auth/ante/msg_gas.go b/x/auth/ante/msg_gas.go new file mode 100644 index 0000000000..20dfc30845 --- /dev/null +++ b/x/auth/ante/msg_gas.go @@ -0,0 +1,144 @@ +package ante + +import ( + "fmt" + + "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/codec/legacy" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// ValidateTxSizeDecorator will validate tx bytes length given the parameters passed in +// If tx is too large decorator returns with error, otherwise call next AnteHandler +// +// CONTRACT: If simulate=true, then signatures must either be completely filled +// in or empty. +type ValidateTxSizeDecorator struct { + ak AccountKeeper + fhk GashubKeeper +} + +func NewValidateTxSizeDecorator(ak AccountKeeper, fhk GashubKeeper) ValidateTxSizeDecorator { + return ValidateTxSizeDecorator{ + ak: ak, + fhk: fhk, + } +} + +func (vtsd ValidateTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + sigTx, ok := tx.(authsigning.SigVerifiableTx) + if !ok { + return ctx, errors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") + } + + newCtx := ctx + txSize := newCtx.TxSize() + // simulate signatures in simulate mode + if simulate { + // in simulate mode, each element should be a nil signature + sigs, err := sigTx.GetSignaturesV2() + if err != nil { + return ctx, err + } + n := len(sigs) + + for i, signer := range sigTx.GetSigners() { + // if signature is already filled in, no need to simulate gas cost + if i < n && !isIncompleteSignature(sigs[i].Data) { + continue + } + + var pubkey cryptotypes.PubKey + + acc := vtsd.ak.GetAccount(ctx, signer) + + // use placeholder simSecp256k1Pubkey if sig is nil + if acc == nil || acc.GetPubKey() == nil { + pubkey = simSecp256k1Pubkey + } else { + pubkey = acc.GetPubKey() + } + + // use stdsignature to mock the size of a full signature + simSig := legacytx.StdSignature{ //nolint:staticcheck // this will be removed when proto is ready + Signature: simSecp256k1Sig[:], + PubKey: pubkey, + } + + sigBz := legacy.Cdc.MustMarshal(simSig) + txSize = txSize + uint64(len(sigBz)) + 14 + } + + newCtx = ctx.WithTxSize(txSize) + } + + params := vtsd.fhk.GetParams(ctx) + if txSize > params.GetMaxTxSize() { + return ctx, errors.Wrapf(sdkerrors.ErrTxTooLarge, "tx length: %d, limit: %d", txSize, params.GetMaxTxSize()) + } + + return next(newCtx, tx, simulate) +} + +// ConsumeMsgGasDecorator will take in parameters and consume gas depending on +// the size of tx and msg type before calling next AnteHandler. +type ConsumeMsgGasDecorator struct { + ak AccountKeeper + fhk GashubKeeper +} + +func NewConsumeMsgGasDecorator(ak AccountKeeper, fhk GashubKeeper) ConsumeMsgGasDecorator { + return ConsumeMsgGasDecorator{ + ak: ak, + fhk: fhk, + } +} + +func (cmfg ConsumeMsgGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + sigTx, ok := tx.(authsigning.SigVerifiableTx) + if !ok { + return ctx, errors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") + } + + params := cmfg.fhk.GetParams(ctx) + gasByTxSize := cmfg.getTxSizeGas(params, ctx) + gasByMsgType, err := cmfg.getMsgGas(params, sigTx) + if err != nil { + return ctx, err + } + + if gasByTxSize > gasByMsgType { + ctx.GasMeter().ConsumeGas(gasByTxSize, "tx bytes length") + } else { + ctx.GasMeter().ConsumeGas(gasByMsgType, "msg type") + } + + return next(ctx, tx, simulate) +} + +func (cmfg ConsumeMsgGasDecorator) getMsgGas(params types.Params, tx sdk.Tx) (uint64, error) { + msgs := tx.GetMsgs() + totalGas := uint64(0) + for _, msg := range msgs { + feeCalcGen := types.GetGasCalculatorGen(sdk.MsgTypeURL(msg)) + if feeCalcGen == nil { + return 0, fmt.Errorf("failed to find fee calculator") + } + feeCalc := feeCalcGen(params) + gas, err := feeCalc(msg) + if err != nil { + return 0, err + } + totalGas += gas + } + return totalGas, nil +} + +func (cmfg ConsumeMsgGasDecorator) getTxSizeGas(params types.Params, ctx sdk.Context) uint64 { + return params.GetMinGasPerByte() * ctx.TxSize() +} diff --git a/x/auth/ante/msg_gas_test.go b/x/auth/ante/msg_gas_test.go new file mode 100644 index 0000000000..3f2e201500 --- /dev/null +++ b/x/auth/ante/msg_gas_test.go @@ -0,0 +1,68 @@ +package ante_test + +import ( + sdkmath "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/testutil/testdata" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + bank "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +func (suite *AnteTestSuite) TestMsgGas() { + suite.SetupTest(true) // setup + suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() + suite.ctx = suite.ctx.WithBlockHeight(1) + + // keys and addresses + _, _, addr1 := testdata.KeyEthSecp256k1TestPubAddr() + _, _, addr2 := testdata.KeyEthSecp256k1TestPubAddr() + _, _, addr3 := testdata.KeyEthSecp256k1TestPubAddr() + _, _, addr4 := testdata.KeyEthSecp256k1TestPubAddr() + addrs := []sdk.AccAddress{addr1, addr2, addr3, addr4} + + // set accounts + for i, addr := range addrs { + acc := suite.app.AccountKeeper.NewAccountWithAddress(suite.ctx, addr) + suite.Require().NoError(acc.SetAccountNumber(uint64(i))) + suite.app.AccountKeeper.SetAccount(suite.ctx, acc) + } + + msgSend := bank.NewMsgSend(addr1, addr2, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)))) + in := make([]bank.Input, 3) + for i := 0; i < 3; i++ { + in[i] = bank.NewInput(addrs[i], sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)))) + } + msgMultiSend := bank.NewMsgMultiSend(in, []bank.Output{bank.NewOutput(addr4, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(300))))}) + + feeAmount := testdata.NewTestFeeAmount() + gasLimit := testdata.NewTestGasLimit() + + mgd := ante.NewConsumeMsgGasDecorator(suite.app.AccountKeeper, suite.app.GashubKeeper) + antehandler := sdk.ChainAnteDecorators(mgd) + + type testCase struct { + name string + msg sdk.Msg + expectedGas uint64 + } + testCases := []testCase{ + {"MsgSend", msgSend, 100000}, + {"MsgMultiSend", msgMultiSend, 400000}, + } + for _, tc := range testCases { + suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test + + suite.Require().NoError(suite.txBuilder.SetMsgs(tc.msg)) + suite.txBuilder.SetFeeAmount(feeAmount) + suite.txBuilder.SetGasLimit(gasLimit) + + tx, err := suite.CreateTestTx(nil, nil, nil, suite.ctx.ChainID()) + suite.Require().NoError(err) + + gasConsumedBefore := suite.ctx.GasMeter().GasConsumed() + _, err = antehandler(suite.ctx, tx, false) + gasConsumedAfter := suite.ctx.GasMeter().GasConsumed() + suite.Require().Equal(tc.expectedGas, gasConsumedAfter-gasConsumedBefore) + } +} diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 4e9ffe862b..1a925283a7 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -37,7 +37,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate return newCtx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be GasTx") } - newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas()) + newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas()).WithTxSize(uint64(len(ctx.TxBytes()))) // Decorator will catch an OutOfGasPanic caused in the next antehandler // AnteHandlers must have their own defer/recover in order for the BaseApp diff --git a/x/auth/client/cli/tips.go b/x/auth/client/cli/tips.go index 773ad6d619..567b093066 100644 --- a/x/auth/client/cli/tips.go +++ b/x/auth/client/cli/tips.go @@ -17,7 +17,7 @@ import ( func GetAuxToFeeCommand() *cobra.Command { cmd := &cobra.Command{ Use: "aux-to-fee ", - Short: "includes the aux signer data in the tx, broadcast the tx, and sends the tip amount to the broadcaster", + Short: "Includes the aux signer data in the tx, broadcast the tx, and sends the tip amount to the broadcaster", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 7d4da92bac..be0b9f8ace 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -16,7 +16,7 @@ import ( func GetValidateSignaturesCommand() *cobra.Command { cmd := &cobra.Command{ Use: "validate-signatures [file]", - Short: "validate transactions signatures", + Short: "Validate transactions signatures", Long: `Print the addresses that must sign the transaction, those who have already signed it, and make sure that signatures are in the correct order. diff --git a/x/authz/client/cli/query.go b/x/authz/client/cli/query.go index 49643db5cd..704bb53adc 100644 --- a/x/authz/client/cli/query.go +++ b/x/authz/client/cli/query.go @@ -39,7 +39,7 @@ func GetCmdQueryGrants() *cobra.Command { cmd := &cobra.Command{ Use: "grants [granter-addr] [grantee-addr] [msg-type-url]?", Args: cobra.RangeArgs(2, 3), - Short: "query grants for a granter-grantee pair and optionally a msg-type-url", + Short: "Query grants for a granter-grantee pair and optionally a msg-type-url", Long: strings.TrimSpace( fmt.Sprintf(`Query authorization grants for a granter-grantee pair. If msg-type-url is set, it will select grants only for that msg type. @@ -100,7 +100,7 @@ func GetQueryGranterGrants() *cobra.Command { cmd := &cobra.Command{ Use: "grants-by-granter [granter-addr]", Args: cobra.ExactArgs(1), - Short: "query authorization grants granted by granter", + Short: "Query authorization grants granted by granter", Long: strings.TrimSpace( fmt.Sprintf(`Query authorization grants granted by granter. Examples: @@ -149,7 +149,7 @@ func GetQueryGranteeGrants() *cobra.Command { cmd := &cobra.Command{ Use: "grants-by-grantee [grantee-addr]", Args: cobra.ExactArgs(1), - Short: "query authorization grants granted to a grantee", + Short: "Query authorization grants granted to a grantee", Long: strings.TrimSpace( fmt.Sprintf(`Query authorization grants granted to a grantee. Examples: diff --git a/x/authz/client/cli/tx.go b/x/authz/client/cli/tx.go index 3eb398667b..13a171ee86 100644 --- a/x/authz/client/cli/tx.go +++ b/x/authz/client/cli/tx.go @@ -204,7 +204,7 @@ func getExpireTime(cmd *cobra.Command) (*time.Time, error) { func NewCmdRevokeAuthorization() *cobra.Command { cmd := &cobra.Command{ Use: "revoke [grantee] [msg-type-url] --from=[granter]", - Short: "revoke authorization", + Short: "Revoke authorization", Long: strings.TrimSpace( fmt.Sprintf(`revoke authorization from a granter to a grantee: Example: @@ -238,7 +238,7 @@ Example: func NewCmdExecAuthorization() *cobra.Command { cmd := &cobra.Command{ Use: "exec [tx-json-file] --from [grantee]", - Short: "execute tx on behalf of granter account", + Short: "Execute tx on behalf of granter account", Long: strings.TrimSpace( fmt.Sprintf(`execute tx on behalf of granter account: Example: diff --git a/x/authz/errors.go b/x/authz/errors.go index 2aaac7122f..dc44f81ddf 100644 --- a/x/authz/errors.go +++ b/x/authz/errors.go @@ -1,6 +1,7 @@ package authz import ( + "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -22,4 +23,6 @@ var ( ErrAuthorizationNumOfSigners = sdkerrors.Register(ModuleName, 9, "authorization can be given to msg with only one signer") // ErrNegativeMaxTokens error if the max tokens is negative ErrNegativeMaxTokens = sdkerrors.Register(ModuleName, 12, "max tokens should be positive") + // ErrTooManyValidators error if the number of stake authorization validators exceeds limit + ErrTooManyValidators = errors.Register(ModuleName, 13, "the number of stake authorization validators cannot exceed the limit") ) diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 63f7714b0a..c2f87bf4cd 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -19,11 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" ) -// TODO: Revisit this once we have propoer gas fee framework. -// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, -// https://github.com/cosmos/cosmos-sdk/discussions/9072 -const gasCostPerIteration = uint64(20) - type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec @@ -359,8 +354,6 @@ func (keeper Keeper) removeFromGrantQueue(ctx sdk.Context, grantKey []byte, gran queueItems := queueItem.MsgTypeUrls for index, typeURL := range queueItems { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "grant queue") - if typeURL == msgType { end := len(queueItem.MsgTypeUrls) - 1 queueItems[index] = queueItems[end] diff --git a/x/feegrant/errors.go b/x/feegrant/errors.go index 232020e6a2..98148dec89 100644 --- a/x/feegrant/errors.go +++ b/x/feegrant/errors.go @@ -1,6 +1,7 @@ package feegrant import ( + "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -22,4 +23,6 @@ var ( ErrNoMessages = sdkerrors.Register(DefaultCodespace, 6, "allowed messages are empty") // ErrMessageNotAllowed error if message is not allowed ErrMessageNotAllowed = sdkerrors.Register(DefaultCodespace, 7, "message not allowed") + // ErrTooManyMessages error if the number of allowed messages exceeds limit + ErrTooManyMessages = errors.Register(DefaultCodespace, 8, "the number of allowed messages cannot exceed the limit") ) diff --git a/x/feegrant/fees.go b/x/feegrant/fees.go index 9b2c033386..6bc9a4a797 100644 --- a/x/feegrant/fees.go +++ b/x/feegrant/fees.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// FeeAllowance implementations are tied to a given fee delegator and delegatee, +// FeeAllowanceI implementations are tied to a given fee delegator and delegatee, // and are used to enforce fee grant limits. type FeeAllowanceI interface { // Accept can use fee payment requested as well as timestamp of the current block diff --git a/x/feegrant/filtered_fee.go b/x/feegrant/filtered_fee.go index 74255757fc..8ce953e992 100644 --- a/x/feegrant/filtered_fee.go +++ b/x/feegrant/filtered_fee.go @@ -8,13 +8,10 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/pkg/errors" ) -// TODO: Revisit this once we have propoer gas fee framework. -// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 -const ( - gasCostPerIteration = uint64(10) -) +const allowedMessagesListSizeLimitation = 22 var ( _ FeeAllowanceI = (*AllowedMsgAllowance)(nil) @@ -27,7 +24,7 @@ func (a *AllowedMsgAllowance) UnpackInterfaces(unpacker types.AnyUnpacker) error return unpacker.UnpackAny(a.Allowance, &allowance) } -// NewAllowedMsgFeeAllowance creates new filtered fee allowance. +// NewAllowedMsgAllowance creates new filtered fee allowance. func NewAllowedMsgAllowance(allowance FeeAllowanceI, allowedMsgs []string) (*AllowedMsgAllowance, error) { msg, ok := allowance.(proto.Message) if !ok { @@ -88,7 +85,6 @@ func (a *AllowedMsgAllowance) Accept(ctx sdk.Context, fee sdk.Coins, msgs []sdk. func (a *AllowedMsgAllowance) allowedMsgsToMap(ctx sdk.Context) map[string]bool { msgsMap := make(map[string]bool, len(a.AllowedMessages)) for _, msg := range a.AllowedMessages { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "check msg") msgsMap[msg] = true } @@ -99,7 +95,6 @@ func (a *AllowedMsgAllowance) allMsgTypesAllowed(ctx sdk.Context, msgs []sdk.Msg msgsMap := a.allowedMsgsToMap(ctx) for _, msg := range msgs { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "check msg") if !msgsMap[sdk.MsgTypeURL(msg)] { return false } @@ -111,10 +106,13 @@ func (a *AllowedMsgAllowance) allMsgTypesAllowed(ctx sdk.Context, msgs []sdk.Msg // ValidateBasic implements FeeAllowance and enforces basic sanity checks func (a *AllowedMsgAllowance) ValidateBasic() error { if a.Allowance == nil { - return sdkerrors.Wrap(ErrNoAllowance, "allowance should not be empty") + return errors.Wrap(ErrNoAllowance, "allowance should not be empty") } if len(a.AllowedMessages) == 0 { - return sdkerrors.Wrap(ErrNoMessages, "allowed messages shouldn't be empty") + return errors.Wrap(ErrNoMessages, "allowed messages shouldn't be empty") + } + if len(a.AllowedMessages) > allowedMessagesListSizeLimitation { + return errors.Wrapf(ErrTooManyMessages, "allowed messages number: %d, limit: %d", len(a.AllowedMessages), allowedMessagesListSizeLimitation) } allowance, err := a.GetAllowance() diff --git a/x/gashub/client/cli/query.go b/x/gashub/client/cli/query.go new file mode 100644 index 0000000000..daa29dd7b6 --- /dev/null +++ b/x/gashub/client/cli/query.go @@ -0,0 +1,59 @@ +package cli + +import ( + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// GetQueryCmd returns the transaction commands for this module +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Querying commands for the gashub module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + QueryParamsCmd(), + ) + + return cmd +} + +// QueryParamsCmd returns the command handler for evidence parameter querying. +func QueryParamsCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the current gashub parameters", + Args: cobra.NoArgs, + Long: strings.TrimSpace(`Query the current gashub parameters: + +$ query gashub params +`), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/gashub/keeper/genesis.go b/x/gashub/keeper/genesis.go new file mode 100644 index 0000000000..2ab7dc9146 --- /dev/null +++ b/x/gashub/keeper/genesis.go @@ -0,0 +1,21 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// InitGenesis - Init store state from genesis data +// +// CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through +// a genesis port script to the new fee collector account +func (fhk Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { + fhk.SetParams(ctx, data.Params) +} + +// ExportGenesis returns a GenesisState for a given context and keeper +func (fhk Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { + params := fhk.GetParams(ctx) + + return types.NewGenesisState(params) +} diff --git a/x/gashub/keeper/grpc_query.go b/x/gashub/keeper/grpc_query.go new file mode 100644 index 0000000000..e7957998e9 --- /dev/null +++ b/x/gashub/keeper/grpc_query.go @@ -0,0 +1,24 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +var _ types.QueryServer = Keeper{} + +// Params returns parameters of auth module +func (fhk Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + ctx := sdk.UnwrapSDKContext(c) + params := fhk.GetParams(ctx) + + return &types.QueryParamsResponse{Params: params}, nil +} diff --git a/x/gashub/keeper/grpc_query_test.go b/x/gashub/keeper/grpc_query_test.go new file mode 100644 index 0000000000..b66e73ee50 --- /dev/null +++ b/x/gashub/keeper/grpc_query_test.go @@ -0,0 +1,13 @@ +package keeper_test + +import ( + gocontext "context" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +func (suite *IntegrationTestSuite) TestQueryParams() { + res, err := suite.queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{}) + suite.Require().NoError(err) + suite.Require().NotNil(res) + suite.Require().Equal(suite.app.GashubKeeper.GetParams(suite.ctx), res.GetParams()) +} diff --git a/x/gashub/keeper/keeper.go b/x/gashub/keeper/keeper.go new file mode 100644 index 0000000000..dd6feeb574 --- /dev/null +++ b/x/gashub/keeper/keeper.go @@ -0,0 +1,43 @@ +package keeper + +import ( + "github.com/tendermint/tendermint/libs/log" + + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gashub/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Keeper encodes/decodes accounts using the go-amino (binary) +// encoding/decoding library. +type Keeper struct { + key storetypes.StoreKey + cdc codec.BinaryCodec + paramSubspace paramtypes.Subspace +} + +// NewGashubKeeper returns a new gashub keeper +func NewGashubKeeper( + cdc codec.BinaryCodec, key storetypes.StoreKey, paramstore paramtypes.Subspace, +) Keeper { + // set KeyTable if it has not already been set + if !paramstore.HasKeyTable() { + paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) + } + + return Keeper{ + key: key, + cdc: cdc, + paramSubspace: paramstore, + } +} + +// Logger returns a module-specific logger. +func (fhk Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", "x/"+types.ModuleName) +} + +// GetCodec return codec.Codec object used by the keeper +func (fhk Keeper) GetCodec() codec.BinaryCodec { return fhk.cdc } diff --git a/x/gashub/keeper/keeper_test.go b/x/gashub/keeper/keeper_test.go new file mode 100644 index 0000000000..46bebb7217 --- /dev/null +++ b/x/gashub/keeper/keeper_test.go @@ -0,0 +1,43 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +type IntegrationTestSuite struct { + suite.Suite + + app *simapp.SimApp + ctx sdk.Context + queryClient types.QueryClient +} + +func (suite *IntegrationTestSuite) SetupTest() { + app := simapp.Setup(suite.T(), false) + ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) + + app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) + app.GashubKeeper.SetParams(ctx, types.DefaultParams()) + + queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) + types.RegisterQueryServer(queryHelper, app.GashubKeeper) + queryClient := types.NewQueryClient(queryHelper) + + suite.app = app + suite.ctx = ctx + suite.queryClient = queryClient +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} diff --git a/x/gashub/keeper/params.go b/x/gashub/keeper/params.go new file mode 100644 index 0000000000..9cd3bb10e8 --- /dev/null +++ b/x/gashub/keeper/params.go @@ -0,0 +1,17 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// SetParams sets the auth module's parameters. +func (fhk Keeper) SetParams(ctx sdk.Context, params types.Params) { + fhk.paramSubspace.SetParamSet(ctx, ¶ms) +} + +// GetParams gets the auth module's parameters. +func (fhk Keeper) GetParams(ctx sdk.Context) (params types.Params) { + fhk.paramSubspace.GetParamSet(ctx, ¶ms) + return +} diff --git a/x/gashub/keeper/querier.go b/x/gashub/keeper/querier.go new file mode 100644 index 0000000000..fbe4e5d63f --- /dev/null +++ b/x/gashub/keeper/querier.go @@ -0,0 +1,34 @@ +package keeper + +import ( + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// NewQuerier creates a querier for auth REST endpoints +func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { + switch path[0] { + case types.QueryParams: + return queryParams(ctx, k, legacyQuerierCdc) + + default: + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0]) + } + } +} + +func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) { + params := k.GetParams(ctx) + + res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params) + if err != nil { + return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error()) + } + + return res, nil +} diff --git a/x/gashub/module.go b/x/gashub/module.go new file mode 100644 index 0000000000..c2f08bf9e1 --- /dev/null +++ b/x/gashub/module.go @@ -0,0 +1,164 @@ +package gashub + +import ( + "context" + "encoding/json" + "fmt" + "math/rand" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/client/cli" + "github.com/cosmos/cosmos-sdk/x/gashub/keeper" + "github.com/cosmos/cosmos-sdk/x/gashub/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} +) + +// AppModuleBasic defines the basic application module used by the gashub module. +type AppModuleBasic struct{} + +// Name returns the gashub module's name. +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the gashub module's types for the given codec. +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} + +// DefaultGenesis returns default genesis state as raw bytes for the gashub +// module. +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesisState()) +} + +// ValidateGenesis performs genesis state validation for the gashub module. +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var data types.GenesisState + if err := cdc.UnmarshalJSON(bz, &data); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + + return types.ValidateGenesis(data) +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the gashub module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + panic(err) + } +} + +// GetTxCmd returns the root tx command for the gashub module. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return nil +} + +// GetQueryCmd returns the root query command for the gashub module. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd() +} + +// RegisterInterfaces registers interfaces and implementations of the gashub module. +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + types.RegisterInterfaces(registry) +} + +// AppModule implements an application module for the gashub module. +type AppModule struct { + AppModuleBasic + + gashubKeeper keeper.Keeper +} + +// NewAppModule creates a new AppModule object +func NewAppModule(cdc codec.Codec, gashubKeeper keeper.Keeper) AppModule { + return AppModule{ + AppModuleBasic: AppModuleBasic{}, + gashubKeeper: gashubKeeper, + } +} + +// Name returns the gashub module's name. +func (AppModule) Name() string { + return types.ModuleName +} + +// RegisterInvariants performs a no-op. +func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// Deprecated: Route returns the message routing key for the gashub module. +func (AppModule) Route() sdk.Route { + return sdk.Route{} +} + +// QuerierRoute returns the gashub module's querier route name. +func (AppModule) QuerierRoute() string { + return types.QuerierRoute +} + +// LegacyQuerierHandler returns the gashub module sdk.Querier. +func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { + return keeper.NewQuerier(am.gashubKeeper, legacyQuerierCdc) +} + +// RegisterServices registers a GRPC query service to respond to the +// module-specific GRPC queries. +func (am AppModule) RegisterServices(cfg module.Configurator) {} + +// InitGenesis performs genesis initialization for the gashub module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { + var genesisState types.GenesisState + cdc.MustUnmarshalJSON(data, &genesisState) + am.gashubKeeper.InitGenesis(ctx, genesisState) + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the exported genesis state as raw bytes for the gashub +// module. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + gs := am.gashubKeeper.ExportGenesis(ctx) + return cdc.MustMarshalJSON(gs) +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { return 3 } + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the gashub module +func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals. +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return nil +} + +// RandomizedParams creates randomized gashub param changes for the simulator. +func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange { + return simulation.ParamChanges(r) +} + +// RegisterStoreDecoder registers a decoder for gashub module's types +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {} + +// WeightedOperations doesn't return any gashub module operation. +func (AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/gashub/simulation/genesis.go b/x/gashub/simulation/genesis.go new file mode 100644 index 0000000000..f66a363957 --- /dev/null +++ b/x/gashub/simulation/genesis.go @@ -0,0 +1,67 @@ +package simulation + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// Simulation parameter constants +const ( + MaxTxSize = "max_tx_size" + MinGasPerByte = "min_gas_per_byte" + MsgGas = "msg_gas" +) + +// GenMaxTxSize randomized MaxTxSize +func GenMaxTxSize(r *rand.Rand) uint64 { + return uint64(simulation.RandIntBetween(r, 2500, 5000)) +} + +// GenMinGasPerByte randomized MinGasPerByte +func GenMinGasPerByte(r *rand.Rand) uint64 { + return uint64(simulation.RandIntBetween(r, 2500, 5000)) +} + +// GenMsgGas randomized msg gas consumption +func GenMsgGas(r *rand.Rand) uint64 { + return uint64(simulation.RandIntBetween(r, 1e5, 1e7)) +} + +// RandomizedGenState generates a random GenesisState for auth +func RandomizedGenState(simState *module.SimulationState) { + var maxTxSize uint64 + simState.AppParams.GetOrGenerate( + simState.Cdc, MaxTxSize, &maxTxSize, simState.Rand, + func(r *rand.Rand) { maxTxSize = GenMaxTxSize(r) }, + ) + + var minGasPerByte uint64 + simState.AppParams.GetOrGenerate( + simState.Cdc, MinGasPerByte, &minGasPerByte, simState.Rand, + func(r *rand.Rand) { minGasPerByte = GenMinGasPerByte(r) }, + ) + + var msgGas uint64 + simState.AppParams.GetOrGenerate( + simState.Cdc, MsgGas, &msgGas, simState.Rand, + func(r *rand.Rand) { msgGas = GenMsgGas(r) }, + ) + + params := types.NewParams(maxTxSize, minGasPerByte, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, + msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, + msgGas, msgGas, msgGas) + + gashubGenesis := types.NewGenesisState(params) + + bz, err := json.MarshalIndent(&gashubGenesis.Params, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated gashub parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(gashubGenesis) +} diff --git a/x/gashub/simulation/genesis_test.go b/x/gashub/simulation/genesis_test.go new file mode 100644 index 0000000000..9652a5ef87 --- /dev/null +++ b/x/gashub/simulation/genesis_test.go @@ -0,0 +1,45 @@ +package simulation_test + +import ( + "encoding/json" + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/types" +) + +// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. +// Abonormal scenarios are not tested here. +func TestRandomizedGenState(t *testing.T) { + interfaceRegistry := codectypes.NewInterfaceRegistry() + cdc := codec.NewProtoCodec(interfaceRegistry) + s := rand.NewSource(1) + r := rand.New(s) + + simState := module.SimulationState{ + AppParams: make(simtypes.AppParams), + Cdc: cdc, + Rand: r, + NumBonded: 3, + Accounts: simtypes.RandomAccounts(r, 3), + InitialStake: sdkmath.NewInt(1000), + GenState: make(map[string]json.RawMessage), + } + + simulation.RandomizedGenState(&simState) + + var gashubGenesis types.GenesisState + simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &gashubGenesis) + + require.Equal(t, uint64(2540), gashubGenesis.Params.MaxTxSize) + require.Equal(t, uint64(2956), gashubGenesis.Params.MinGasPerByte) + require.Equal(t, uint64(2803300), gashubGenesis.Params.MsgSendGas) +} diff --git a/x/gashub/simulation/params.go b/x/gashub/simulation/params.go new file mode 100644 index 0000000000..f3bd2911d4 --- /dev/null +++ b/x/gashub/simulation/params.go @@ -0,0 +1,24 @@ +package simulation + +// DONTCOVER + +import ( + "fmt" + "math/rand" + + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/types" + "github.com/cosmos/cosmos-sdk/x/simulation" +) + +// ParamChanges defines the parameters that can be modified by param change proposals +// on the simulation +func ParamChanges(r *rand.Rand) []simtypes.ParamChange { + return []simtypes.ParamChange{ + simulation.NewSimParamChange(types.ModuleName, string(types.KeyMsgSendGas), + func(r *rand.Rand) string { + return fmt.Sprintf("\"%d\"", GenMsgGas(r)) + }, + ), + } +} diff --git a/x/gashub/simulation/params_test.go b/x/gashub/simulation/params_test.go new file mode 100644 index 0000000000..e89d8f4e74 --- /dev/null +++ b/x/gashub/simulation/params_test.go @@ -0,0 +1,35 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/x/gashub/simulation" +) + +func TestParamChanges(t *testing.T) { + s := rand.NewSource(1) + r := rand.New(s) + + expected := []struct { + composedKey string + key string + simValue string + subspace string + }{ + {"gashub/MsgSendGas", "MsgSendGas", "\"1698081\"", "gashub"}, + } + + paramChanges := simulation.ParamChanges(r) + + require.Len(t, paramChanges, 1) + + for i, p := range paramChanges { + require.Equal(t, expected[i].composedKey, p.ComposedKey()) + require.Equal(t, expected[i].key, p.Key()) + require.Equal(t, expected[i].simValue, p.SimValue()(r)) + require.Equal(t, expected[i].subspace, p.Subspace()) + } +} diff --git a/x/gashub/types/codec.go b/x/gashub/types/codec.go new file mode 100644 index 0000000000..da6aced74c --- /dev/null +++ b/x/gashub/types/codec.go @@ -0,0 +1,34 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" +) + +// RegisterLegacyAminoCodec registers the account interfaces and concrete types on the +// provided LegacyAmino codec. These types are used for Amino JSON serialization +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +} + +// RegisterInterfaces associates protoName with AccountI interface +// and creates a registry of it's concrete implementations +func RegisterInterfaces(registry types.InterfaceRegistry) { +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be + // used to properly serialize MsgGrant and MsgExec instances + RegisterLegacyAminoCodec(authzcodec.Amino) +} diff --git a/x/gashub/types/gas_calculator.go b/x/gashub/types/gas_calculator.go new file mode 100644 index 0000000000..19ec416173 --- /dev/null +++ b/x/gashub/types/gas_calculator.go @@ -0,0 +1,204 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" + bank "github.com/cosmos/cosmos-sdk/x/bank/types" + distribution "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + slashing "github.com/cosmos/cosmos-sdk/x/slashing/types" + staking "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +type ( + GasCalculator func(msg types.Msg) (uint64, error) + GasCalculatorGenerator func(params Params) GasCalculator +) + +var calculatorsGen = make(map[string]GasCalculatorGenerator) + +var ErrInvalidMsgGas = fmt.Errorf("msg gas param is invalid") + +func RegisterCalculatorGen(msgType string, feeCalcGen GasCalculatorGenerator) { + calculatorsGen[msgType] = feeCalcGen +} + +func GetGasCalculatorGen(msgType string) GasCalculatorGenerator { + return calculatorsGen[msgType] +} + +func FixedGasCalculator(amount uint64) GasCalculator { + return func(msg types.Msg) (uint64, error) { + if amount == 0 { + return 0, errors.Wrapf(ErrInvalidMsgGas, "msg type: %s", types.MsgTypeURL(msg)) + } + return amount, nil + } +} + +func GrantCalculator(fixedGas, gasPerItem uint64) GasCalculator { + return func(msg types.Msg) (uint64, error) { + if fixedGas == 0 || gasPerItem == 0 { + return 0, errors.Wrapf(ErrInvalidMsgGas, "msg type: %s", types.MsgTypeURL(msg)) + } + + msgGrant := msg.(*authz.MsgGrant) + var num int + authorization, err := msgGrant.GetAuthorization() + if err != nil { + return 0, err + } + if authorization, ok := authorization.(*staking.StakeAuthorization); ok { + allowList := authorization.GetAllowList().GetAddress() + denyList := authorization.GetDenyList().GetAddress() + num = len(allowList) + len(denyList) + } + + totalGas := fixedGas + uint64(num)*gasPerItem + return totalGas, nil + } +} + +func MultiSendCalculator(fixedGas, gasPerItem uint64) GasCalculator { + return func(msg types.Msg) (uint64, error) { + if fixedGas == 0 || gasPerItem == 0 { + return 0, errors.Wrapf(ErrInvalidMsgGas, "msg type: %s", types.MsgTypeURL(msg)) + } + + msgMultiSend := msg.(*bank.MsgMultiSend) + var num int + if len(msgMultiSend.Inputs) > len(msgMultiSend.Outputs) { + num = len(msgMultiSend.Inputs) + } else { + num = len(msgMultiSend.Outputs) + } + totalGas := fixedGas + uint64(num)*gasPerItem + return totalGas, nil + } +} + +func GrantAllowanceCalculator(fixedGas, gasPerItem uint64) GasCalculator { + return func(msg types.Msg) (uint64, error) { + if fixedGas == 0 || gasPerItem == 0 { + return 0, errors.Wrapf(ErrInvalidMsgGas, "msg type: %s", types.MsgTypeURL(msg)) + } + + msgGrantAllowance := msg.(*feegrant.MsgGrantAllowance) + var num int + feeAllowance, err := msgGrantAllowance.GetFeeAllowanceI() + if err != nil { + return 0, err + } + if feeAllowance, ok := feeAllowance.(*feegrant.AllowedMsgAllowance); ok { + num = len(feeAllowance.AllowedMessages) + } + + totalGas := fixedGas + uint64(num)*gasPerItem + return totalGas, nil + } +} + +var msgGrantGasCalculatorGen = func(params Params) GasCalculator { + fixedGas := params.GetMsgGrantFixedGas() + gasPerItem := params.GetMsgGrantPerItemGas() + return GrantCalculator(fixedGas, gasPerItem) +} + +var msgMultiSendGasCalculatorGen = func(params Params) GasCalculator { + fixedGas := params.GetMsgMultiSendFixedGas() + gasPerItem := params.GetMsgMultiSendPerItemGas() + return MultiSendCalculator(fixedGas, gasPerItem) +} + +var msgGrantAllowanceGasCalculatorGen = func(params Params) GasCalculator { + fixedGas := params.GetMsgGrantAllowanceFixedGas() + gasPerItem := params.GetMsgGrantAllowancePerItemGas() + return GrantAllowanceCalculator(fixedGas, gasPerItem) +} + +func init() { + RegisterCalculatorGen(types.MsgTypeURL(&authz.MsgGrant{}), msgGrantGasCalculatorGen) + RegisterCalculatorGen(types.MsgTypeURL(&authz.MsgRevoke{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgRevokeGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&authz.MsgExec{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgExecGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&bank.MsgSend{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgSendGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&bank.MsgMultiSend{}), msgMultiSendGasCalculatorGen) + RegisterCalculatorGen(types.MsgTypeURL(&distribution.MsgWithdrawDelegatorReward{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgWithdrawDelegatorRewardGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&distribution.MsgWithdrawValidatorCommission{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgWithdrawValidatorCommissionGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&distribution.MsgSetWithdrawAddress{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgSetWithdrawAddressGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&distribution.MsgFundCommunityPool{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgFundCommunityPoolGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&feegrant.MsgGrantAllowance{}), msgGrantAllowanceGasCalculatorGen) + RegisterCalculatorGen(types.MsgTypeURL(&feegrant.MsgRevokeAllowance{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgRevokeAllowanceGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&gov.MsgSubmitProposal{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgSubmitProposalGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&gov.MsgVote{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgVoteGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&gov.MsgVoteWeighted{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgVoteWeightedGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&gov.MsgDeposit{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgDepositGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&slashing.MsgUnjail{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgUnjailGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&slashing.MsgImpeach{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgImpeachGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgEditValidator{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgEditValidatorGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgDelegate{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgDelegateGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgUndelegate{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgUndelegateGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgBeginRedelegate{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgBeginRedelegateGas() + return FixedGasCalculator(fixedGas) + }) + RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgCancelUnbondingDelegation{}), func(params Params) GasCalculator { + fixedGas := params.GetMsgCancelUnbondingDelegationGas() + return FixedGasCalculator(fixedGas) + }) +} diff --git a/x/gashub/types/gashub.pb.go b/x/gashub/types/gashub.pb.go new file mode 100644 index 0000000000..a03991d6e6 --- /dev/null +++ b/x/gashub/types/gashub.pb.go @@ -0,0 +1,1389 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/gashub/v1alpha1/gashub.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the parameters for the gashub module. +type Params struct { + MaxTxSize uint64 `protobuf:"varint,1,opt,name=max_tx_size,json=maxTxSize,proto3" json:"max_tx_size,omitempty"` + MinGasPerByte uint64 `protobuf:"varint,2,opt,name=min_gas_per_byte,json=minGasPerByte,proto3" json:"min_gas_per_byte,omitempty"` + MsgGrantFixedGas uint64 `protobuf:"varint,3,opt,name=msg_grant_fixed_gas,json=msgGrantFixedGas,proto3" json:"msg_grant_fixed_gas,omitempty"` + MsgGrantPerItemGas uint64 `protobuf:"varint,4,opt,name=msg_grant_per_item_gas,json=msgGrantPerItemGas,proto3" json:"msg_grant_per_item_gas,omitempty"` + MsgRevokeGas uint64 `protobuf:"varint,5,opt,name=msg_revoke_gas,json=msgRevokeGas,proto3" json:"msg_revoke_gas,omitempty"` + MsgExecGas uint64 `protobuf:"varint,6,opt,name=msg_exec_gas,json=msgExecGas,proto3" json:"msg_exec_gas,omitempty"` + MsgSendGas uint64 `protobuf:"varint,7,opt,name=msg_send_gas,json=msgSendGas,proto3" json:"msg_send_gas,omitempty"` + MsgMultiSendFixedGas uint64 `protobuf:"varint,8,opt,name=msg_multi_send_fixed_gas,json=msgMultiSendFixedGas,proto3" json:"msg_multi_send_fixed_gas,omitempty"` + MsgMultiSendPerItemGas uint64 `protobuf:"varint,9,opt,name=msg_multi_send_per_item_gas,json=msgMultiSendPerItemGas,proto3" json:"msg_multi_send_per_item_gas,omitempty"` + MsgWithdrawDelegatorRewardGas uint64 `protobuf:"varint,10,opt,name=msg_withdraw_delegator_reward_gas,json=msgWithdrawDelegatorRewardGas,proto3" json:"msg_withdraw_delegator_reward_gas,omitempty"` + MsgWithdrawValidatorCommissionGas uint64 `protobuf:"varint,11,opt,name=msg_withdraw_validator_commission_gas,json=msgWithdrawValidatorCommissionGas,proto3" json:"msg_withdraw_validator_commission_gas,omitempty"` + MsgSetWithdrawAddressGas uint64 `protobuf:"varint,12,opt,name=msg_set_withdraw_address_gas,json=msgSetWithdrawAddressGas,proto3" json:"msg_set_withdraw_address_gas,omitempty"` + MsgFundCommunityPoolGas uint64 `protobuf:"varint,13,opt,name=msg_fund_community_pool_gas,json=msgFundCommunityPoolGas,proto3" json:"msg_fund_community_pool_gas,omitempty"` + MsgGrantAllowanceFixedGas uint64 `protobuf:"varint,14,opt,name=msg_grant_allowance_fixed_gas,json=msgGrantAllowanceFixedGas,proto3" json:"msg_grant_allowance_fixed_gas,omitempty"` + MsgGrantAllowancePerItemGas uint64 `protobuf:"varint,15,opt,name=msg_grant_allowance_per_item_gas,json=msgGrantAllowancePerItemGas,proto3" json:"msg_grant_allowance_per_item_gas,omitempty"` + MsgRevokeAllowanceGas uint64 `protobuf:"varint,16,opt,name=msg_revoke_allowance_gas,json=msgRevokeAllowanceGas,proto3" json:"msg_revoke_allowance_gas,omitempty"` + MsgSubmitProposalGas uint64 `protobuf:"varint,17,opt,name=msg_submit_proposal_gas,json=msgSubmitProposalGas,proto3" json:"msg_submit_proposal_gas,omitempty"` + MsgVoteGas uint64 `protobuf:"varint,18,opt,name=msg_vote_gas,json=msgVoteGas,proto3" json:"msg_vote_gas,omitempty"` + MsgVoteWeightedGas uint64 `protobuf:"varint,19,opt,name=msg_vote_weighted_gas,json=msgVoteWeightedGas,proto3" json:"msg_vote_weighted_gas,omitempty"` + MsgDepositGas uint64 `protobuf:"varint,20,opt,name=msg_deposit_gas,json=msgDepositGas,proto3" json:"msg_deposit_gas,omitempty"` + MsgUnjailGas uint64 `protobuf:"varint,21,opt,name=msg_unjail_gas,json=msgUnjailGas,proto3" json:"msg_unjail_gas,omitempty"` + MsgImpeachGas uint64 `protobuf:"varint,22,opt,name=msg_impeach_gas,json=msgImpeachGas,proto3" json:"msg_impeach_gas,omitempty"` + MsgEditValidatorGas uint64 `protobuf:"varint,23,opt,name=msg_edit_validator_gas,json=msgEditValidatorGas,proto3" json:"msg_edit_validator_gas,omitempty"` + MsgDelegateGas uint64 `protobuf:"varint,24,opt,name=msg_delegate_gas,json=msgDelegateGas,proto3" json:"msg_delegate_gas,omitempty"` + MsgUndelegateGas uint64 `protobuf:"varint,25,opt,name=msg_undelegate_gas,json=msgUndelegateGas,proto3" json:"msg_undelegate_gas,omitempty"` + MsgBeginRedelegateGas uint64 `protobuf:"varint,26,opt,name=msg_begin_redelegate_gas,json=msgBeginRedelegateGas,proto3" json:"msg_begin_redelegate_gas,omitempty"` + MsgCancelUnbondingDelegationGas uint64 `protobuf:"varint,27,opt,name=msg_cancel_unbonding_delegation_gas,json=msgCancelUnbondingDelegationGas,proto3" json:"msg_cancel_unbonding_delegation_gas,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_f79bf23b48853a4a, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetMaxTxSize() uint64 { + if m != nil { + return m.MaxTxSize + } + return 0 +} + +func (m *Params) GetMinGasPerByte() uint64 { + if m != nil { + return m.MinGasPerByte + } + return 0 +} + +func (m *Params) GetMsgGrantFixedGas() uint64 { + if m != nil { + return m.MsgGrantFixedGas + } + return 0 +} + +func (m *Params) GetMsgGrantPerItemGas() uint64 { + if m != nil { + return m.MsgGrantPerItemGas + } + return 0 +} + +func (m *Params) GetMsgRevokeGas() uint64 { + if m != nil { + return m.MsgRevokeGas + } + return 0 +} + +func (m *Params) GetMsgExecGas() uint64 { + if m != nil { + return m.MsgExecGas + } + return 0 +} + +func (m *Params) GetMsgSendGas() uint64 { + if m != nil { + return m.MsgSendGas + } + return 0 +} + +func (m *Params) GetMsgMultiSendFixedGas() uint64 { + if m != nil { + return m.MsgMultiSendFixedGas + } + return 0 +} + +func (m *Params) GetMsgMultiSendPerItemGas() uint64 { + if m != nil { + return m.MsgMultiSendPerItemGas + } + return 0 +} + +func (m *Params) GetMsgWithdrawDelegatorRewardGas() uint64 { + if m != nil { + return m.MsgWithdrawDelegatorRewardGas + } + return 0 +} + +func (m *Params) GetMsgWithdrawValidatorCommissionGas() uint64 { + if m != nil { + return m.MsgWithdrawValidatorCommissionGas + } + return 0 +} + +func (m *Params) GetMsgSetWithdrawAddressGas() uint64 { + if m != nil { + return m.MsgSetWithdrawAddressGas + } + return 0 +} + +func (m *Params) GetMsgFundCommunityPoolGas() uint64 { + if m != nil { + return m.MsgFundCommunityPoolGas + } + return 0 +} + +func (m *Params) GetMsgGrantAllowanceFixedGas() uint64 { + if m != nil { + return m.MsgGrantAllowanceFixedGas + } + return 0 +} + +func (m *Params) GetMsgGrantAllowancePerItemGas() uint64 { + if m != nil { + return m.MsgGrantAllowancePerItemGas + } + return 0 +} + +func (m *Params) GetMsgRevokeAllowanceGas() uint64 { + if m != nil { + return m.MsgRevokeAllowanceGas + } + return 0 +} + +func (m *Params) GetMsgSubmitProposalGas() uint64 { + if m != nil { + return m.MsgSubmitProposalGas + } + return 0 +} + +func (m *Params) GetMsgVoteGas() uint64 { + if m != nil { + return m.MsgVoteGas + } + return 0 +} + +func (m *Params) GetMsgVoteWeightedGas() uint64 { + if m != nil { + return m.MsgVoteWeightedGas + } + return 0 +} + +func (m *Params) GetMsgDepositGas() uint64 { + if m != nil { + return m.MsgDepositGas + } + return 0 +} + +func (m *Params) GetMsgUnjailGas() uint64 { + if m != nil { + return m.MsgUnjailGas + } + return 0 +} + +func (m *Params) GetMsgImpeachGas() uint64 { + if m != nil { + return m.MsgImpeachGas + } + return 0 +} + +func (m *Params) GetMsgEditValidatorGas() uint64 { + if m != nil { + return m.MsgEditValidatorGas + } + return 0 +} + +func (m *Params) GetMsgDelegateGas() uint64 { + if m != nil { + return m.MsgDelegateGas + } + return 0 +} + +func (m *Params) GetMsgUndelegateGas() uint64 { + if m != nil { + return m.MsgUndelegateGas + } + return 0 +} + +func (m *Params) GetMsgBeginRedelegateGas() uint64 { + if m != nil { + return m.MsgBeginRedelegateGas + } + return 0 +} + +func (m *Params) GetMsgCancelUnbondingDelegationGas() uint64 { + if m != nil { + return m.MsgCancelUnbondingDelegationGas + } + return 0 +} + +func init() { + proto.RegisterType((*Params)(nil), "cosmos.gashub.v1alpha1.Params") +} + +func init() { + proto.RegisterFile("cosmos/gashub/v1alpha1/gashub.proto", fileDescriptor_f79bf23b48853a4a) +} + +var fileDescriptor_f79bf23b48853a4a = []byte{ + // 986 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x56, 0x4f, 0x6f, 0xdb, 0x36, + 0x14, 0x8f, 0xb7, 0x2e, 0x6b, 0xd8, 0xd8, 0x75, 0x19, 0xc7, 0x76, 0xe2, 0xc6, 0x6c, 0x16, 0x14, + 0x18, 0x30, 0xb4, 0x5e, 0x31, 0x60, 0xc0, 0x8a, 0x5d, 0xea, 0xa4, 0x0d, 0x32, 0x4c, 0x98, 0xe1, + 0x2c, 0x0d, 0x36, 0x0c, 0x10, 0x68, 0x8b, 0x91, 0xb9, 0x98, 0xa2, 0x27, 0xd2, 0xb1, 0xd3, 0x4f, + 0xb1, 0xe3, 0x8e, 0x3d, 0xec, 0xc3, 0xec, 0xd8, 0xe3, 0x4e, 0xc2, 0xc0, 0x5c, 0xf6, 0x31, 0x06, + 0x92, 0xa2, 0x2c, 0x25, 0x4e, 0x76, 0xb2, 0xf8, 0xde, 0xef, 0x8f, 0x49, 0xbe, 0xf7, 0x24, 0xb0, + 0x37, 0xe4, 0x82, 0x71, 0xd1, 0x09, 0xb1, 0x18, 0x4d, 0x07, 0x9d, 0x8b, 0x17, 0x78, 0x3c, 0x19, + 0xe1, 0x17, 0xe9, 0xfa, 0xf9, 0x24, 0xe6, 0x92, 0xc3, 0xba, 0x05, 0x3d, 0x4f, 0x83, 0x0e, 0xb4, + 0x5d, 0x0b, 0x79, 0xc8, 0x0d, 0xa4, 0xa3, 0x9f, 0x2c, 0xfa, 0xb3, 0x3f, 0xab, 0x60, 0xb5, 0x87, + 0x63, 0xcc, 0x04, 0x7c, 0x06, 0x1e, 0x30, 0x3c, 0xf7, 0xe5, 0xdc, 0x17, 0xf4, 0x1d, 0x69, 0x96, + 0x9e, 0x94, 0x3e, 0xbf, 0xd7, 0x2d, 0xab, 0x04, 0xad, 0x79, 0x78, 0xfe, 0xe3, 0xfc, 0x98, 0xbe, + 0x23, 0xfd, 0x35, 0xe6, 0x1e, 0xe1, 0x4b, 0x50, 0x65, 0x34, 0xf2, 0x43, 0x2c, 0xfc, 0x09, 0x89, + 0xfd, 0xc1, 0xa5, 0x24, 0xcd, 0x8f, 0x0c, 0xe7, 0x91, 0x4a, 0x50, 0xd9, 0xa3, 0xd1, 0x21, 0x16, + 0x3d, 0x12, 0x77, 0x2f, 0x25, 0xe9, 0x97, 0x59, 0x7e, 0x09, 0xf7, 0xc1, 0x06, 0x13, 0xa1, 0x1f, + 0xc6, 0x38, 0x92, 0xfe, 0x19, 0x9d, 0x93, 0x40, 0xeb, 0x34, 0x3f, 0x36, 0xf4, 0x9a, 0x4a, 0x50, + 0xd5, 0x13, 0xe1, 0xa1, 0xce, 0xbe, 0xd1, 0xc9, 0x43, 0x2c, 0xfa, 0x55, 0x76, 0x2d, 0x02, 0xbf, + 0x03, 0xf5, 0x85, 0x88, 0xfe, 0x0b, 0x54, 0x12, 0x66, 0x74, 0xee, 0x19, 0x9d, 0xba, 0x4a, 0x10, + 0x74, 0x3a, 0x3d, 0x12, 0x1f, 0x49, 0xc2, 0xb4, 0x12, 0x64, 0x37, 0x62, 0xf0, 0x6b, 0x50, 0xd1, + 0x5a, 0x31, 0xb9, 0xe0, 0xe7, 0xc4, 0x68, 0x7c, 0x62, 0x34, 0xaa, 0x2a, 0x41, 0xeb, 0x9e, 0x08, + 0xfb, 0x26, 0xa1, 0xd9, 0xeb, 0x2c, 0xb7, 0x82, 0x5f, 0x02, 0xbd, 0xf6, 0xc9, 0x9c, 0x0c, 0x0d, + 0x6b, 0xd5, 0xb0, 0x2a, 0x2a, 0x41, 0xc0, 0x13, 0xe1, 0xeb, 0x39, 0x19, 0x6a, 0x0e, 0x60, 0xd9, + 0xb3, 0x63, 0x08, 0x12, 0xd9, 0x3d, 0x7f, 0x5a, 0x60, 0x1c, 0x93, 0x28, 0x70, 0x8c, 0xf4, 0x19, + 0xf6, 0x40, 0x53, 0x33, 0xd8, 0x74, 0x2c, 0xa9, 0xe5, 0x2d, 0x4e, 0xec, 0xbe, 0x61, 0x37, 0x55, + 0x82, 0x6a, 0x9e, 0x08, 0x3d, 0x0d, 0xd1, 0xb4, 0xec, 0xd4, 0x6a, 0x6c, 0x49, 0x14, 0x9e, 0x82, + 0xd6, 0x35, 0xc5, 0xc2, 0xf1, 0xad, 0x19, 0xd1, 0x6d, 0x95, 0xa0, 0x7a, 0x5e, 0x34, 0x77, 0x84, + 0x75, 0xb6, 0x34, 0x0e, 0xcf, 0xc1, 0xae, 0x16, 0x9e, 0x51, 0x39, 0x0a, 0x62, 0x3c, 0xf3, 0x03, + 0x32, 0x26, 0x21, 0x96, 0x3c, 0xf6, 0x63, 0x32, 0xc3, 0xb1, 0xfd, 0xcf, 0xc0, 0xc8, 0xef, 0xaa, + 0x04, 0xed, 0x78, 0x22, 0x3c, 0x4d, 0xb1, 0x07, 0x0e, 0xda, 0x37, 0x48, 0xed, 0xb2, 0xc3, 0xee, + 0x4a, 0xc3, 0x19, 0x78, 0x5a, 0x30, 0xbb, 0xc0, 0x63, 0x1a, 0x18, 0xb3, 0x21, 0x67, 0x8c, 0x0a, + 0x41, 0xb9, 0x29, 0xcf, 0xe6, 0x03, 0x63, 0xf8, 0x54, 0x25, 0x68, 0x37, 0x67, 0xf8, 0xd6, 0xc1, + 0xf7, 0x33, 0xb4, 0x36, 0xdd, 0x65, 0xff, 0x07, 0x81, 0xbf, 0x80, 0xc7, 0xf6, 0x0a, 0xe5, 0xc2, + 0x1c, 0x07, 0x41, 0x4c, 0x84, 0x30, 0x7e, 0xeb, 0xc6, 0xef, 0xb1, 0x4a, 0x50, 0xd3, 0x5c, 0xa9, + 0x74, 0x7a, 0xaf, 0x2c, 0x48, 0xdb, 0x34, 0xd9, 0x2d, 0x19, 0xf8, 0x93, 0xbd, 0x9c, 0xb3, 0x69, + 0x14, 0x98, 0x8d, 0x4c, 0x23, 0x2a, 0x2f, 0xfd, 0x09, 0xe7, 0x63, 0x23, 0x5e, 0x36, 0xe2, 0x2d, + 0x95, 0xa0, 0x86, 0x27, 0xc2, 0x37, 0xd3, 0x28, 0xd8, 0x77, 0xa0, 0x1e, 0xe7, 0x63, 0xad, 0xdd, + 0x60, 0xcb, 0x13, 0xd0, 0x07, 0x3b, 0x8b, 0x8e, 0xc1, 0xe3, 0x31, 0x9f, 0xe1, 0x68, 0x48, 0x72, + 0xe5, 0x54, 0x31, 0xe2, 0x3b, 0x2a, 0x41, 0x5b, 0xae, 0x71, 0x5e, 0x39, 0x58, 0x56, 0x53, 0x5b, + 0xec, 0xb6, 0x14, 0x3c, 0x03, 0x4f, 0x96, 0x19, 0x14, 0xaa, 0xeb, 0xa1, 0xf1, 0x40, 0x2a, 0x41, + 0xad, 0x1b, 0x1e, 0xb9, 0x12, 0x6b, 0xb1, 0xdb, 0x93, 0xb0, 0x6f, 0x5b, 0x22, 0x6d, 0xd7, 0x85, + 0x91, 0xd6, 0xaf, 0x1a, 0xfd, 0x2d, 0x95, 0xa0, 0xcd, 0xac, 0x71, 0x33, 0x0d, 0xad, 0xbc, 0xc9, + 0x96, 0x85, 0xe1, 0x0f, 0xa0, 0x61, 0x6e, 0x75, 0x3a, 0x60, 0x54, 0xfa, 0x93, 0x98, 0x4f, 0xb8, + 0xc0, 0xf6, 0xcc, 0x1f, 0x15, 0xba, 0xec, 0xd8, 0x20, 0x7a, 0x29, 0xc0, 0x75, 0xd9, 0x8d, 0xa8, + 0xeb, 0xf4, 0x0b, 0x2e, 0xed, 0x1f, 0x83, 0x85, 0x4e, 0x7f, 0xcb, 0x25, 0x71, 0x9d, 0x9e, 0x3e, + 0xc3, 0x23, 0xb0, 0x99, 0x31, 0x66, 0x84, 0x86, 0x23, 0x99, 0xde, 0xcb, 0x46, 0x61, 0xa0, 0x69, + 0xf8, 0x69, 0x9a, 0x76, 0x03, 0xed, 0x5a, 0x0c, 0x7e, 0x03, 0x1e, 0x6a, 0xa9, 0x80, 0x4c, 0xb8, + 0xa0, 0xd2, 0x88, 0xd4, 0x72, 0xc3, 0x59, 0x84, 0x07, 0x36, 0xa3, 0xf9, 0x65, 0x96, 0x5f, 0xba, + 0x59, 0x38, 0x8d, 0x7e, 0xc5, 0xd4, 0xee, 0x7f, 0xb3, 0x30, 0x0b, 0x4f, 0x4c, 0xc2, 0xcd, 0xc2, + 0x6c, 0xe5, 0x2c, 0x29, 0x9b, 0x10, 0x3c, 0x1c, 0x19, 0x62, 0xbd, 0x60, 0x79, 0x64, 0x33, 0xce, + 0x72, 0xb1, 0x84, 0xdf, 0xdb, 0x51, 0x4e, 0x02, 0x2a, 0x73, 0x6d, 0xac, 0x15, 0x1a, 0x46, 0xa1, + 0xa1, 0x12, 0xb4, 0xa1, 0x07, 0x6a, 0x40, 0x65, 0xd6, 0x94, 0x5a, 0x47, 0xbf, 0x46, 0xae, 0x07, + 0xe1, 0xb7, 0xa0, 0x6a, 0xf7, 0x6e, 0x46, 0x86, 0x3d, 0xfc, 0xa6, 0xd1, 0x81, 0x2a, 0x41, 0x15, + 0xb3, 0x79, 0x9b, 0xd2, 0x12, 0x15, 0x56, 0x58, 0xc3, 0x2e, 0x80, 0x76, 0xfb, 0x05, 0xfe, 0x56, + 0xe1, 0xd5, 0x74, 0x92, 0x25, 0xdd, 0xab, 0xa9, 0x10, 0x71, 0xf5, 0x39, 0x20, 0x21, 0x8d, 0xfc, + 0x98, 0x14, 0x94, 0xb6, 0x0b, 0xf5, 0xd9, 0xd5, 0x90, 0x3e, 0xc9, 0xcb, 0xe9, 0x1a, 0xb8, 0x19, + 0x86, 0xbf, 0x81, 0x3d, 0xad, 0x39, 0xd4, 0xf5, 0x3a, 0xf6, 0xa7, 0xd1, 0x80, 0x47, 0x01, 0x8d, + 0xb2, 0x6d, 0xba, 0x61, 0xd7, 0x32, 0xf2, 0x7b, 0x2a, 0x41, 0xc8, 0x13, 0xe1, 0xbe, 0x41, 0x9f, + 0x38, 0xf0, 0x41, 0x86, 0xd5, 0x46, 0x88, 0xdd, 0x0d, 0x78, 0x79, 0xff, 0x8f, 0xf7, 0x68, 0xe5, + 0xdf, 0xf7, 0xa8, 0xd4, 0x7d, 0xfd, 0x97, 0x6a, 0x97, 0x3e, 0xa8, 0x76, 0xe9, 0x1f, 0xd5, 0x2e, + 0xfd, 0x7e, 0xd5, 0x5e, 0xf9, 0x70, 0xd5, 0x5e, 0xf9, 0xfb, 0xaa, 0xbd, 0xf2, 0xf3, 0x17, 0x21, + 0x95, 0xfa, 0x3b, 0x63, 0xc8, 0x59, 0x27, 0xfd, 0x3c, 0xb1, 0x3f, 0xcf, 0x44, 0x70, 0xde, 0x99, + 0xbb, 0x6f, 0x15, 0x79, 0x39, 0x21, 0x62, 0xb0, 0x6a, 0x3e, 0x3a, 0xbe, 0xfa, 0x2f, 0x00, 0x00, + 0xff, 0xff, 0x58, 0x22, 0xf1, 0x68, 0xc9, 0x08, 0x00, 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.MaxTxSize != that1.MaxTxSize { + return false + } + if this.MinGasPerByte != that1.MinGasPerByte { + return false + } + if this.MsgGrantFixedGas != that1.MsgGrantFixedGas { + return false + } + if this.MsgGrantPerItemGas != that1.MsgGrantPerItemGas { + return false + } + if this.MsgRevokeGas != that1.MsgRevokeGas { + return false + } + if this.MsgExecGas != that1.MsgExecGas { + return false + } + if this.MsgSendGas != that1.MsgSendGas { + return false + } + if this.MsgMultiSendFixedGas != that1.MsgMultiSendFixedGas { + return false + } + if this.MsgMultiSendPerItemGas != that1.MsgMultiSendPerItemGas { + return false + } + if this.MsgWithdrawDelegatorRewardGas != that1.MsgWithdrawDelegatorRewardGas { + return false + } + if this.MsgWithdrawValidatorCommissionGas != that1.MsgWithdrawValidatorCommissionGas { + return false + } + if this.MsgSetWithdrawAddressGas != that1.MsgSetWithdrawAddressGas { + return false + } + if this.MsgFundCommunityPoolGas != that1.MsgFundCommunityPoolGas { + return false + } + if this.MsgGrantAllowanceFixedGas != that1.MsgGrantAllowanceFixedGas { + return false + } + if this.MsgGrantAllowancePerItemGas != that1.MsgGrantAllowancePerItemGas { + return false + } + if this.MsgRevokeAllowanceGas != that1.MsgRevokeAllowanceGas { + return false + } + if this.MsgSubmitProposalGas != that1.MsgSubmitProposalGas { + return false + } + if this.MsgVoteGas != that1.MsgVoteGas { + return false + } + if this.MsgVoteWeightedGas != that1.MsgVoteWeightedGas { + return false + } + if this.MsgDepositGas != that1.MsgDepositGas { + return false + } + if this.MsgUnjailGas != that1.MsgUnjailGas { + return false + } + if this.MsgImpeachGas != that1.MsgImpeachGas { + return false + } + if this.MsgEditValidatorGas != that1.MsgEditValidatorGas { + return false + } + if this.MsgDelegateGas != that1.MsgDelegateGas { + return false + } + if this.MsgUndelegateGas != that1.MsgUndelegateGas { + return false + } + if this.MsgBeginRedelegateGas != that1.MsgBeginRedelegateGas { + return false + } + if this.MsgCancelUnbondingDelegationGas != that1.MsgCancelUnbondingDelegationGas { + return false + } + return true +} +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MsgCancelUnbondingDelegationGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgCancelUnbondingDelegationGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd8 + } + if m.MsgBeginRedelegateGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgBeginRedelegateGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd0 + } + if m.MsgUndelegateGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgUndelegateGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc8 + } + if m.MsgDelegateGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgDelegateGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc0 + } + if m.MsgEditValidatorGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgEditValidatorGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb8 + } + if m.MsgImpeachGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgImpeachGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb0 + } + if m.MsgUnjailGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgUnjailGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + if m.MsgDepositGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgDepositGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa0 + } + if m.MsgVoteWeightedGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgVoteWeightedGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x98 + } + if m.MsgVoteGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgVoteGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x90 + } + if m.MsgSubmitProposalGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgSubmitProposalGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x88 + } + if m.MsgRevokeAllowanceGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgRevokeAllowanceGas)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x80 + } + if m.MsgGrantAllowancePerItemGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgGrantAllowancePerItemGas)) + i-- + dAtA[i] = 0x78 + } + if m.MsgGrantAllowanceFixedGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgGrantAllowanceFixedGas)) + i-- + dAtA[i] = 0x70 + } + if m.MsgFundCommunityPoolGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgFundCommunityPoolGas)) + i-- + dAtA[i] = 0x68 + } + if m.MsgSetWithdrawAddressGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgSetWithdrawAddressGas)) + i-- + dAtA[i] = 0x60 + } + if m.MsgWithdrawValidatorCommissionGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgWithdrawValidatorCommissionGas)) + i-- + dAtA[i] = 0x58 + } + if m.MsgWithdrawDelegatorRewardGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgWithdrawDelegatorRewardGas)) + i-- + dAtA[i] = 0x50 + } + if m.MsgMultiSendPerItemGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgMultiSendPerItemGas)) + i-- + dAtA[i] = 0x48 + } + if m.MsgMultiSendFixedGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgMultiSendFixedGas)) + i-- + dAtA[i] = 0x40 + } + if m.MsgSendGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgSendGas)) + i-- + dAtA[i] = 0x38 + } + if m.MsgExecGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgExecGas)) + i-- + dAtA[i] = 0x30 + } + if m.MsgRevokeGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgRevokeGas)) + i-- + dAtA[i] = 0x28 + } + if m.MsgGrantPerItemGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgGrantPerItemGas)) + i-- + dAtA[i] = 0x20 + } + if m.MsgGrantFixedGas != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MsgGrantFixedGas)) + i-- + dAtA[i] = 0x18 + } + if m.MinGasPerByte != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MinGasPerByte)) + i-- + dAtA[i] = 0x10 + } + if m.MaxTxSize != 0 { + i = encodeVarintGashub(dAtA, i, uint64(m.MaxTxSize)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintGashub(dAtA []byte, offset int, v uint64) int { + offset -= sovGashub(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxTxSize != 0 { + n += 1 + sovGashub(uint64(m.MaxTxSize)) + } + if m.MinGasPerByte != 0 { + n += 1 + sovGashub(uint64(m.MinGasPerByte)) + } + if m.MsgGrantFixedGas != 0 { + n += 1 + sovGashub(uint64(m.MsgGrantFixedGas)) + } + if m.MsgGrantPerItemGas != 0 { + n += 1 + sovGashub(uint64(m.MsgGrantPerItemGas)) + } + if m.MsgRevokeGas != 0 { + n += 1 + sovGashub(uint64(m.MsgRevokeGas)) + } + if m.MsgExecGas != 0 { + n += 1 + sovGashub(uint64(m.MsgExecGas)) + } + if m.MsgSendGas != 0 { + n += 1 + sovGashub(uint64(m.MsgSendGas)) + } + if m.MsgMultiSendFixedGas != 0 { + n += 1 + sovGashub(uint64(m.MsgMultiSendFixedGas)) + } + if m.MsgMultiSendPerItemGas != 0 { + n += 1 + sovGashub(uint64(m.MsgMultiSendPerItemGas)) + } + if m.MsgWithdrawDelegatorRewardGas != 0 { + n += 1 + sovGashub(uint64(m.MsgWithdrawDelegatorRewardGas)) + } + if m.MsgWithdrawValidatorCommissionGas != 0 { + n += 1 + sovGashub(uint64(m.MsgWithdrawValidatorCommissionGas)) + } + if m.MsgSetWithdrawAddressGas != 0 { + n += 1 + sovGashub(uint64(m.MsgSetWithdrawAddressGas)) + } + if m.MsgFundCommunityPoolGas != 0 { + n += 1 + sovGashub(uint64(m.MsgFundCommunityPoolGas)) + } + if m.MsgGrantAllowanceFixedGas != 0 { + n += 1 + sovGashub(uint64(m.MsgGrantAllowanceFixedGas)) + } + if m.MsgGrantAllowancePerItemGas != 0 { + n += 1 + sovGashub(uint64(m.MsgGrantAllowancePerItemGas)) + } + if m.MsgRevokeAllowanceGas != 0 { + n += 2 + sovGashub(uint64(m.MsgRevokeAllowanceGas)) + } + if m.MsgSubmitProposalGas != 0 { + n += 2 + sovGashub(uint64(m.MsgSubmitProposalGas)) + } + if m.MsgVoteGas != 0 { + n += 2 + sovGashub(uint64(m.MsgVoteGas)) + } + if m.MsgVoteWeightedGas != 0 { + n += 2 + sovGashub(uint64(m.MsgVoteWeightedGas)) + } + if m.MsgDepositGas != 0 { + n += 2 + sovGashub(uint64(m.MsgDepositGas)) + } + if m.MsgUnjailGas != 0 { + n += 2 + sovGashub(uint64(m.MsgUnjailGas)) + } + if m.MsgImpeachGas != 0 { + n += 2 + sovGashub(uint64(m.MsgImpeachGas)) + } + if m.MsgEditValidatorGas != 0 { + n += 2 + sovGashub(uint64(m.MsgEditValidatorGas)) + } + if m.MsgDelegateGas != 0 { + n += 2 + sovGashub(uint64(m.MsgDelegateGas)) + } + if m.MsgUndelegateGas != 0 { + n += 2 + sovGashub(uint64(m.MsgUndelegateGas)) + } + if m.MsgBeginRedelegateGas != 0 { + n += 2 + sovGashub(uint64(m.MsgBeginRedelegateGas)) + } + if m.MsgCancelUnbondingDelegationGas != 0 { + n += 2 + sovGashub(uint64(m.MsgCancelUnbondingDelegationGas)) + } + return n +} + +func sovGashub(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGashub(x uint64) (n int) { + return sovGashub(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxTxSize", wireType) + } + m.MaxTxSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxTxSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MinGasPerByte", wireType) + } + m.MinGasPerByte = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MinGasPerByte |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgGrantFixedGas", wireType) + } + m.MsgGrantFixedGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgGrantFixedGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgGrantPerItemGas", wireType) + } + m.MsgGrantPerItemGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgGrantPerItemGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgRevokeGas", wireType) + } + m.MsgRevokeGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgRevokeGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgExecGas", wireType) + } + m.MsgExecGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgExecGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgSendGas", wireType) + } + m.MsgSendGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgSendGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgMultiSendFixedGas", wireType) + } + m.MsgMultiSendFixedGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgMultiSendFixedGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgMultiSendPerItemGas", wireType) + } + m.MsgMultiSendPerItemGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgMultiSendPerItemGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgWithdrawDelegatorRewardGas", wireType) + } + m.MsgWithdrawDelegatorRewardGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgWithdrawDelegatorRewardGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgWithdrawValidatorCommissionGas", wireType) + } + m.MsgWithdrawValidatorCommissionGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgWithdrawValidatorCommissionGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgSetWithdrawAddressGas", wireType) + } + m.MsgSetWithdrawAddressGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgSetWithdrawAddressGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 13: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgFundCommunityPoolGas", wireType) + } + m.MsgFundCommunityPoolGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgFundCommunityPoolGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgGrantAllowanceFixedGas", wireType) + } + m.MsgGrantAllowanceFixedGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgGrantAllowanceFixedGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgGrantAllowancePerItemGas", wireType) + } + m.MsgGrantAllowancePerItemGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgGrantAllowancePerItemGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 16: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgRevokeAllowanceGas", wireType) + } + m.MsgRevokeAllowanceGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgRevokeAllowanceGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 17: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgSubmitProposalGas", wireType) + } + m.MsgSubmitProposalGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgSubmitProposalGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 18: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgVoteGas", wireType) + } + m.MsgVoteGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgVoteGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 19: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgVoteWeightedGas", wireType) + } + m.MsgVoteWeightedGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgVoteWeightedGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 20: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgDepositGas", wireType) + } + m.MsgDepositGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgDepositGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUnjailGas", wireType) + } + m.MsgUnjailGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgUnjailGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 22: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgImpeachGas", wireType) + } + m.MsgImpeachGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgImpeachGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 23: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgEditValidatorGas", wireType) + } + m.MsgEditValidatorGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgEditValidatorGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 24: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgDelegateGas", wireType) + } + m.MsgDelegateGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgDelegateGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 25: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgUndelegateGas", wireType) + } + m.MsgUndelegateGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgUndelegateGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 26: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgBeginRedelegateGas", wireType) + } + m.MsgBeginRedelegateGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgBeginRedelegateGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 27: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgCancelUnbondingDelegationGas", wireType) + } + m.MsgCancelUnbondingDelegationGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGashub + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MsgCancelUnbondingDelegationGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipGashub(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGashub + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGashub(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGashub + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGashub + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGashub + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGashub + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGashub + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGashub + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGashub = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGashub = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGashub = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/gashub/types/genesis.go b/x/gashub/types/genesis.go new file mode 100644 index 0000000000..572e314035 --- /dev/null +++ b/x/gashub/types/genesis.go @@ -0,0 +1,40 @@ +package types + +import ( + "encoding/json" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// NewGenesisState - Create a new genesis state +func NewGenesisState(params Params) *GenesisState { + return &GenesisState{ + Params: params, + } +} + +// DefaultGenesisState - Return a default genesis state +func DefaultGenesisState() *GenesisState { + return NewGenesisState(DefaultParams()) +} + +// GetGenesisStateFromAppState returns x/gashub GenesisState given raw application +// genesis state. +func GetGenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMessage) GenesisState { + var genesisState GenesisState + + if appState[ModuleName] != nil { + cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) + } + + return genesisState +} + +// ValidateGenesis performs basic validation of gashub genesis data returning an +// error for any failed validation criteria. +func ValidateGenesis(data GenesisState) error { + if err := data.Params.Validate(); err != nil { + return err + } + return nil +} diff --git a/x/gashub/types/genesis.pb.go b/x/gashub/types/genesis.pb.go new file mode 100644 index 0000000000..f115f6d449 --- /dev/null +++ b/x/gashub/types/genesis.pb.go @@ -0,0 +1,324 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/gashub/v1alpha1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// GenesisState defines the gashub module's genesis state. +type GenesisState struct { + // params defines all the paramaters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_650531435e9abeaa, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*GenesisState)(nil), "cosmos.gashub.v1alpha1.GenesisState") +} + +func init() { + proto.RegisterFile("cosmos/gashub/v1alpha1/genesis.proto", fileDescriptor_650531435e9abeaa) +} + +var fileDescriptor_650531435e9abeaa = []byte{ + // 201 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4f, 0x2c, 0xce, 0x28, 0x4d, 0xd2, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, + 0x48, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x83, 0xa8, 0xd2, 0x83, 0xa8, 0xd2, 0x83, 0xa9, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0xa5, 0x94, 0x71, 0x99, 0x09, 0xd1, 0x0d, 0x56, 0xa4, + 0xe4, 0xc3, 0xc5, 0xe3, 0x0e, 0xb1, 0x23, 0xb8, 0x24, 0xb1, 0x24, 0x55, 0xc8, 0x86, 0x8b, 0xad, + 0x20, 0xb1, 0x28, 0x31, 0xb7, 0x58, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x4e, 0x0f, 0xbb, + 0x9d, 0x7a, 0x01, 0x60, 0x55, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0xf5, 0x38, 0xb9, + 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, + 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x76, 0x7a, 0x66, 0x09, 0x48, + 0x7f, 0x72, 0x7e, 0xae, 0x3e, 0xd4, 0x5d, 0x10, 0x4a, 0xb7, 0x38, 0x25, 0x5b, 0xbf, 0x02, 0xe6, + 0xc8, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0xdb, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, + 0xff, 0x6f, 0xdb, 0x25, 0x4b, 0x16, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/gashub/types/genesis_test.go b/x/gashub/types/genesis_test.go new file mode 100644 index 0000000000..e3924555d4 --- /dev/null +++ b/x/gashub/types/genesis_test.go @@ -0,0 +1,46 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGenesisStateValidate(t *testing.T) { + testCases := []struct { + name string + genesisState GenesisState + expErr bool + }{ + { + "valid genesisState", + GenesisState{ + Params: DefaultParams(), + }, + false, + }, + {"empty genesisState", GenesisState{}, true}, + { + "invalid params ", + GenesisState{ + Params: Params{ + MaxTxSize: 0, + }, + }, + true, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + err := ValidateGenesis(tc.genesisState) + + if tc.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/gashub/types/key.go b/x/gashub/types/key.go new file mode 100644 index 0000000000..a1d4bde210 --- /dev/null +++ b/x/gashub/types/key.go @@ -0,0 +1,15 @@ +package types + +const ( + // module name + ModuleName = "gashub" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // QuerierRoute defines the module's query routing key + QuerierRoute = ModuleName +) diff --git a/x/gashub/types/params.go b/x/gashub/types/params.go new file mode 100644 index 0000000000..06e0046756 --- /dev/null +++ b/x/gashub/types/params.go @@ -0,0 +1,292 @@ +package types + +import ( + "fmt" + + "sigs.k8s.io/yaml" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// Default parameter values +const ( + DefaultMaxTxSize uint64 = 1024 + DefaultMinGasPerByte uint64 = 5 + DefaultMsgGrantFixedGas uint64 = 1e5 + DefaultMsgGrantPerItemGas uint64 = 1e5 + DefaultMsgRevokeGas uint64 = 1e5 + DefaultMsgExecGas uint64 = 1e5 + DefaultMsgSendGas uint64 = 1e5 + DefaultMsgMultiSendFixedGas uint64 = 1e5 + DefaultMsgMultiSendPerItemGas uint64 = 1e5 + DefaultMsgWithdrawDelegatorRewardGas uint64 = 1e5 + DefaultMsgWithdrawValidatorCommissionGas uint64 = 1e5 + DefaultMsgSetWithdrawAddressGas uint64 = 1e5 + DefaultMsgFundCommunityPoolGas uint64 = 1e5 + DefaultMsgGrantAllowanceFixedGas uint64 = 1e5 + DefaultMsgGrantAllowancePerItemGas uint64 = 1e5 + DefaultMsgRevokeAllowanceGas uint64 = 1e5 + DefaultMsgSubmitProposalGas uint64 = 1e5 + DefaultMsgVoteGas uint64 = 1e5 + DefaultMsgVoteWeightedGas uint64 = 1e5 + DefaultMsgDepositGas uint64 = 1e5 + DefaultMsgUnjailGas uint64 = 1e5 + DefaultMsgImpeachGas uint64 = 1e5 + DefaultMsgEditValidatorGas uint64 = 1e5 + DefaultMsgDelegateGas uint64 = 1e5 + DefaultMsgUndelegateGas uint64 = 1e5 + DefaultMsgBeginRedelegateGas uint64 = 1e5 + DefaultMsgCancelUnbondingDelegationGas uint64 = 1e5 +) + +// Parameter keys +var ( + KeyMaxTxSize = []byte("MaxTxSize") + KeyMinGasPerByte = []byte("MinGasPerByte") + KeyMsgGrantFixedGas = []byte("MsgGrantFixedGas") + KeyMsgGrantPerItemGas = []byte("MsgGrantPerItemGas") + KeyMsgRevokeGas = []byte("MsgRevokeGas") + KeyMsgExecGas = []byte("MsgExecGas") + KeyMsgSendGas = []byte("MsgSendGas") + KeyMsgMultiSendFixedGas = []byte("MsgMultiSendFixedGas") + KeyMsgMultiSendPerItemGas = []byte("MsgMultiSendPerItemGas") + KeyMsgWithdrawDelegatorRewardGas = []byte("MsgWithdrawDelegatorRewardGas") + KeyMsgWithdrawValidatorCommissionGas = []byte("MsgWithdrawValidatorCommissionGas") + KeyMsgSetWithdrawAddressGas = []byte("MsgSetWithdrawAddressGas") + KeyMsgFundCommunityPoolGas = []byte("MsgFundCommunityPoolGas") + KeyMsgGrantAllowanceFixedGas = []byte("MsgGrantAllowanceFixedGas") + KeyMsgGrantAllowancePerItemGas = []byte("MsgGrantAllowancePerItemGas") + KeyMsgRevokeAllowanceGas = []byte("MsgRevokeAllowanceGas") + KeyMsgSubmitProposalGas = []byte("MsgSubmitProposalGas") + KeyMsgVoteGas = []byte("MsgVoteGas") + KeyMsgVoteWeightedGas = []byte("MsgVoteWeightedGas") + KeyMsgDepositGas = []byte("MsgDepositGas") + KeyMsgUnjailGas = []byte("MsgUnjailGas") + KeyMsgImpeachGas = []byte("MsgImpeachGas") + KeyMsgEditValidatorGas = []byte("MsgEditValidatorGas") + KeyMsgDelegateGas = []byte("MsgDelegateGas") + KeyMsgUndelegateGas = []byte("MsgUndelegateGas") + KeyMsgBeginRedelegateGas = []byte("MsgBeginRedelegateGas") + KeyMsgCancelUnbondingDelegationGas = []byte("MsgCancelUnbondingDelegationGas") +) + +var _ paramtypes.ParamSet = &Params{} + +// NewParams creates a new Params object +func NewParams( + maxTxSize, minGasPerByte, msgGrantFixedGas, msgGrantPerItemGas, msgRevokeGas, msgExecGas, msgSendGas, msgMultiSendFixedGas, + msgMultiSendPerItemGas, msgWithdrawDelegatorRewardGas, msgWithdrawValidatorCommissionGas, msgSetWithdrawAddressGas, + msgFundCommunityPoolGas, msgGrantAllowanceFixedGas, msgGrantAllowancePerItemGas, msgRevokeAllowanceGas, msgSubmitProposalGas, + msgVoteGas, msgVoteWeightedGas, msgDepositGas, msgUnjailGas, msgImpeachGas, msgEditValidatorGas, msgDelegateGas, + msgUndelegateGas, msgBeginRedelegateGas, msgCancelUnbondingDelegationGas uint64, +) Params { + return Params{ + MaxTxSize: maxTxSize, + MinGasPerByte: minGasPerByte, + MsgGrantFixedGas: msgGrantFixedGas, + MsgGrantPerItemGas: msgGrantPerItemGas, + MsgRevokeGas: msgRevokeGas, + MsgExecGas: msgExecGas, + MsgSendGas: msgSendGas, + MsgMultiSendFixedGas: msgMultiSendFixedGas, + MsgMultiSendPerItemGas: msgMultiSendPerItemGas, + MsgWithdrawDelegatorRewardGas: msgWithdrawDelegatorRewardGas, + MsgWithdrawValidatorCommissionGas: msgWithdrawValidatorCommissionGas, + MsgSetWithdrawAddressGas: msgSetWithdrawAddressGas, + MsgFundCommunityPoolGas: msgFundCommunityPoolGas, + MsgGrantAllowanceFixedGas: msgGrantAllowanceFixedGas, + MsgGrantAllowancePerItemGas: msgGrantAllowancePerItemGas, + MsgRevokeAllowanceGas: msgRevokeAllowanceGas, + MsgSubmitProposalGas: msgSubmitProposalGas, + MsgVoteGas: msgVoteGas, + MsgVoteWeightedGas: msgVoteWeightedGas, + MsgDepositGas: msgDepositGas, + MsgUnjailGas: msgUnjailGas, + MsgImpeachGas: msgImpeachGas, + MsgEditValidatorGas: msgEditValidatorGas, + MsgDelegateGas: msgDelegateGas, + MsgUndelegateGas: msgUndelegateGas, + MsgBeginRedelegateGas: msgBeginRedelegateGas, + MsgCancelUnbondingDelegationGas: msgCancelUnbondingDelegationGas, + } +} + +// ParamKeyTable for gashub module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// ParamSetPairs implements the ParamSet interface and returns all the key/value +// pairs of gashub's parameters. +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyMaxTxSize, &p.MaxTxSize, validateMaxTxSize), + paramtypes.NewParamSetPair(KeyMinGasPerByte, &p.MinGasPerByte, validateMinGasPerByte), + paramtypes.NewParamSetPair(KeyMsgGrantFixedGas, &p.MsgGrantFixedGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgGrantPerItemGas, &p.MsgGrantPerItemGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgRevokeGas, &p.MsgRevokeGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgExecGas, &p.MsgExecGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgSendGas, &p.MsgSendGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgMultiSendFixedGas, &p.MsgMultiSendFixedGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgMultiSendPerItemGas, &p.MsgMultiSendPerItemGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgWithdrawDelegatorRewardGas, &p.MsgWithdrawDelegatorRewardGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgWithdrawValidatorCommissionGas, &p.MsgWithdrawValidatorCommissionGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgSetWithdrawAddressGas, &p.MsgSetWithdrawAddressGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgFundCommunityPoolGas, &p.MsgFundCommunityPoolGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgGrantAllowanceFixedGas, &p.MsgGrantAllowanceFixedGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgGrantAllowancePerItemGas, &p.MsgGrantAllowancePerItemGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgRevokeAllowanceGas, &p.MsgRevokeAllowanceGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgSubmitProposalGas, &p.MsgSubmitProposalGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgVoteGas, &p.MsgVoteGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgVoteWeightedGas, &p.MsgVoteWeightedGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgDepositGas, &p.MsgDepositGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgUnjailGas, &p.MsgUnjailGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgImpeachGas, &p.MsgImpeachGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgEditValidatorGas, &p.MsgEditValidatorGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgDelegateGas, &p.MsgDelegateGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgUndelegateGas, &p.MsgUndelegateGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgBeginRedelegateGas, &p.MsgBeginRedelegateGas, validateMsgGas), + paramtypes.NewParamSetPair(KeyMsgCancelUnbondingDelegationGas, &p.MsgCancelUnbondingDelegationGas, validateMsgGas), + } +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return Params{ + MaxTxSize: DefaultMaxTxSize, + MinGasPerByte: DefaultMinGasPerByte, + MsgGrantFixedGas: DefaultMsgGrantFixedGas, + MsgGrantPerItemGas: DefaultMsgGrantPerItemGas, + MsgRevokeGas: DefaultMsgRevokeGas, + MsgExecGas: DefaultMsgExecGas, + MsgSendGas: DefaultMsgSendGas, + MsgMultiSendFixedGas: DefaultMsgMultiSendFixedGas, + MsgMultiSendPerItemGas: DefaultMsgMultiSendPerItemGas, + MsgWithdrawDelegatorRewardGas: DefaultMsgWithdrawDelegatorRewardGas, + MsgWithdrawValidatorCommissionGas: DefaultMsgWithdrawValidatorCommissionGas, + MsgSetWithdrawAddressGas: DefaultMsgSetWithdrawAddressGas, + MsgFundCommunityPoolGas: DefaultMsgFundCommunityPoolGas, + MsgGrantAllowanceFixedGas: DefaultMsgGrantAllowanceFixedGas, + MsgGrantAllowancePerItemGas: DefaultMsgGrantAllowancePerItemGas, + MsgRevokeAllowanceGas: DefaultMsgRevokeAllowanceGas, + MsgSubmitProposalGas: DefaultMsgSubmitProposalGas, + MsgVoteGas: DefaultMsgVoteGas, + MsgVoteWeightedGas: DefaultMsgVoteWeightedGas, + MsgDepositGas: DefaultMsgDepositGas, + MsgUnjailGas: DefaultMsgUnjailGas, + MsgImpeachGas: DefaultMsgImpeachGas, + MsgEditValidatorGas: DefaultMsgEditValidatorGas, + MsgDelegateGas: DefaultMsgDelegateGas, + MsgUndelegateGas: DefaultMsgUndelegateGas, + MsgBeginRedelegateGas: DefaultMsgBeginRedelegateGas, + MsgCancelUnbondingDelegationGas: DefaultMsgCancelUnbondingDelegationGas, + } +} + +// String implements the stringer interface. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +func validateMaxTxSize(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("invalid max tx size: %d", v) + } + + return nil +} + +func validateMinGasPerByte(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("invalid min gas per byte: %d", v) + } + + return nil +} + +func validateMsgGas(i interface{}) error { + v, ok := i.(uint64) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + if v == 0 { + return fmt.Errorf("invalid msg gas: %d", v) + } + + return nil +} + +// Validate checks that the parameters have valid values. +func (p Params) Validate() error { + if err := validateMaxTxSize(p.MaxTxSize); err != nil { + return err + } + if err := validateMinGasPerByte(p.MinGasPerByte); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantFixedGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantPerItemGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgRevokeGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgExecGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgSendGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgMultiSendFixedGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgMultiSendPerItemGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgWithdrawDelegatorRewardGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgWithdrawValidatorCommissionGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgSetWithdrawAddressGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgFundCommunityPoolGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantAllowanceFixedGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantAllowancePerItemGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgRevokeAllowanceGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantPerItemGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgMultiSendPerItemGas); err != nil { + return err + } + if err := validateMsgGas(p.MsgGrantAllowancePerItemGas); err != nil { + return err + } + + return nil +} diff --git a/x/gashub/types/querier.go b/x/gashub/types/querier.go new file mode 100644 index 0000000000..4dde5ac364 --- /dev/null +++ b/x/gashub/types/querier.go @@ -0,0 +1,6 @@ +package types + +// query endpoints supported by the gashub Querier +const ( + QueryParams = "params" +) diff --git a/x/gashub/types/query.pb.go b/x/gashub/types/query.pb.go new file mode 100644 index 0000000000..47cd53b5ab --- /dev/null +++ b/x/gashub/types/query.pb.go @@ -0,0 +1,537 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: cosmos/gashub/v1alpha1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is the request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f928c856cebbb195, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is the response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params defines the parameters of the module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f928c856cebbb195, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "cosmos.gashub.v1alpha1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "cosmos.gashub.v1alpha1.QueryParamsResponse") +} + +func init() { + proto.RegisterFile("cosmos/gashub/v1alpha1/query.proto", fileDescriptor_f928c856cebbb195) +} + +var fileDescriptor_f928c856cebbb195 = []byte{ + // 283 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4a, 0xce, 0x2f, 0xce, + 0xcd, 0x2f, 0xd6, 0x4f, 0x4f, 0x2c, 0xce, 0x28, 0x4d, 0xd2, 0x2f, 0x33, 0x4c, 0xcc, 0x29, 0xc8, + 0x48, 0x34, 0xd4, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, + 0x83, 0xa8, 0xd1, 0x83, 0xa8, 0xd1, 0x83, 0xa9, 0x91, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, + 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, + 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0xa1, 0xb2, 0xca, + 0x38, 0xec, 0x83, 0x9a, 0x0d, 0x56, 0xa4, 0x24, 0xc2, 0x25, 0x14, 0x08, 0xb2, 0x3f, 0x20, 0xb1, + 0x28, 0x31, 0xb7, 0x38, 0x28, 0xb5, 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0x29, 0x98, 0x4b, 0x18, 0x45, + 0xb4, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0xc8, 0x86, 0x8b, 0xad, 0x00, 0x2c, 0x22, 0xc1, 0xa8, + 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa7, 0x87, 0xdd, 0xb9, 0x7a, 0x10, 0x7d, 0x4e, 0x2c, 0x27, 0xee, + 0xc9, 0x33, 0x04, 0x41, 0xf5, 0x18, 0x4d, 0x66, 0xe4, 0x62, 0x05, 0x9b, 0x2a, 0xd4, 0xc9, 0xc8, + 0xc5, 0x06, 0x51, 0x22, 0xa4, 0x85, 0xcb, 0x08, 0x4c, 0x57, 0x49, 0x69, 0x13, 0xa5, 0x16, 0xe2, + 0x56, 0x25, 0xb5, 0xa6, 0xcb, 0x4f, 0x26, 0x33, 0x29, 0x08, 0xc9, 0xe9, 0xe3, 0x08, 0x06, 0x88, + 0xab, 0x9c, 0x5c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, + 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x3b, 0x3d, + 0xb3, 0x04, 0x64, 0x4d, 0x72, 0x7e, 0x2e, 0xcc, 0x0c, 0x08, 0xa5, 0x5b, 0x9c, 0x92, 0xad, 0x5f, + 0x01, 0x33, 0xb0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x9c, 0xc6, 0x80, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0x7d, 0xea, 0x23, 0xe5, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Params queries all parameters. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/cosmos.gashub.v1alpha1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Params queries all parameters. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cosmos.gashub.v1alpha1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cosmos.gashub.v1alpha1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cosmos/gashub/v1alpha1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/gashub/types/query.pb.gw.go b/x/gashub/types/query.pb.gw.go new file mode 100644 index 0000000000..3d7971279f --- /dev/null +++ b/x/gashub/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: cosmos/gashub/v1alpha1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"cosmos", "gashub", "v1alpha1", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/genutil/client/cli/validate_genesis.go b/x/genutil/client/cli/validate_genesis.go index 519a5ae01f..beb94dde52 100644 --- a/x/genutil/client/cli/validate_genesis.go +++ b/x/genutil/client/cli/validate_genesis.go @@ -19,7 +19,7 @@ func ValidateGenesisCmd(mbm module.BasicManager) *cobra.Command { return &cobra.Command{ Use: "validate-genesis [file]", Args: cobra.RangeArgs(0, 1), - Short: "validates the genesis file at the default location or at the location passed as an arg", + Short: "Validates the genesis file at the default location or at the location passed as an arg", RunE: func(cmd *cobra.Command, args []string) (err error) { serverCtx := server.GetServerContextFromCmd(cmd) clientCtx := client.GetClientContextFromCmd(cmd) diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 27c8f7105f..a76ba1f262 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -7,7 +7,6 @@ import ( "github.com/armon/go-metrics" - storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -41,16 +40,16 @@ func (k msgServer) SubmitProposal(goCtx context.Context, msg *v1.MsgSubmitPropos return nil, err } - bytes, err := proposal.Marshal() - if err != nil { - return nil, err - } - - // ref: https://github.com/cosmos/cosmos-sdk/issues/9683 - ctx.GasMeter().ConsumeGas( - 3*storetypes.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), - "submit proposal", - ) + // bytes, err := proposal.Marshal() + // if err != nil { + // return nil, err + // } + // + // // ref: https://github.com/cosmos/cosmos-sdk/issues/9683 + // ctx.GasMeter().ConsumeGas( + // 3*storetypes.KVGasConfig().WriteCostPerByte*uint64(len(bytes)), + // "submit proposal", + // ) defer telemetry.IncrCounter(1, types.ModuleName, "proposal") diff --git a/x/group/internal/orm/testsupport.go b/x/group/internal/orm/testsupport.go index 1b4a684789..fd2d05f4cb 100644 --- a/x/group/internal/orm/testsupport.go +++ b/x/group/internal/orm/testsupport.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/cosmos/cosmos-sdk/store" - "github.com/cosmos/cosmos-sdk/store/gaskv" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" dbm "github.com/tendermint/tm-db" @@ -86,7 +85,8 @@ func NewGasCountingMockContext() *GasCountingMockContext { } func (g GasCountingMockContext) KVStore(store sdk.KVStore) sdk.KVStore { - return gaskv.NewStore(store, g.GasMeter, storetypes.KVGasConfig()) + // return gaskv.NewStore(store, g.GasMeter, storetypes.KVGasConfig()) + return store } func (g GasCountingMockContext) GasConsumed() storetypes.Gas { diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index f9cb6f0145..55f052edcc 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -17,9 +17,9 @@ import ( var _ group.MsgServer = Keeper{} -// TODO: Revisit this once we have proper gas fee framework. -// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 -const gasCostPerIteration = uint64(20) +// // TODO: Revisit this once we have proper gas fee framework. +// // Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 +// const gasCostPerIteration = uint64(20) func (k Keeper) CreateGroup(goCtx context.Context, req *group.MsgCreateGroup) (*group.MsgCreateGroupResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) @@ -536,7 +536,7 @@ func (k Keeper) SubmitProposal(goCtx context.Context, req *group.MsgSubmitPropos if req.Exec == group.Exec_EXEC_TRY { // Consider proposers as Yes votes for i := range proposers { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "vote on proposal") + // ctx.GasMeter().ConsumeGas(gasCostPerIteration, "vote on proposal") _, err = k.Vote(sdk.WrapSDKContext(ctx), &group.MsgVote{ ProposalId: id, Voter: proposers[i], diff --git a/x/nft/client/cli/tx.go b/x/nft/client/cli/tx.go index 45320a97a4..b83f9c50c4 100644 --- a/x/nft/client/cli/tx.go +++ b/x/nft/client/cli/tx.go @@ -35,7 +35,7 @@ func NewCmdSend() *cobra.Command { cmd := &cobra.Command{ Use: "send [class-id] [nft-id] [receiver] --from [sender]", Args: cobra.ExactArgs(3), - Short: "transfer ownership of nft", + Short: "Transfer ownership of nft", Long: strings.TrimSpace(fmt.Sprintf(` $ %s tx %s send --from --chain-id `, version.AppName, nft.ModuleName), ), diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 339b42fa79..2c7e227c71 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -55,7 +55,7 @@ func NewTxCmd() *cobra.Command { func NewEditValidatorCmd() *cobra.Command { cmd := &cobra.Command{ Use: "edit-validator", - Short: "edit an existing validator account", + Short: "Edit an existing validator account", RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) if err != nil { diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index 1f9016cdbb..1e68e31c1f 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -1,14 +1,14 @@ package types import ( + "github.com/pkg/errors" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" ) -// TODO: Revisit this once we have propoer gas fee framework. -// Tracking issues https://github.com/cosmos/cosmos-sdk/issues/9054, https://github.com/cosmos/cosmos-sdk/discussions/9072 -const gasCostPerIteration = uint64(10) +const authListSizeLimitation = 41 var _ authz.Authorization = &StakeAuthorization{} @@ -45,11 +45,21 @@ func (a StakeAuthorization) MsgTypeURL() string { func (a StakeAuthorization) ValidateBasic() error { if a.MaxTokens != nil && a.MaxTokens.IsNegative() { - return sdkerrors.Wrapf(authz.ErrNegativeMaxTokens, "negative coin amount: %v", a.MaxTokens) + return errors.Wrapf(authz.ErrNegativeMaxTokens, "negative coin amount: %v", a.MaxTokens) } if a.AuthorizationType == AuthorizationType_AUTHORIZATION_TYPE_UNSPECIFIED { return authz.ErrUnknownAuthorizationType } + if allowList := a.GetAllowList().GetAddress(); allowList != nil { + if len(allowList) > authListSizeLimitation { + return errors.Wrapf(authz.ErrTooManyValidators, "allow list number: %d, limit: %d", len(allowList), authListSizeLimitation) + } + } + if denyList := a.GetDenyList().GetAddress(); denyList != nil { + if len(denyList) > authListSizeLimitation { + return errors.Wrapf(authz.ErrTooManyValidators, "deny list number: %d, limit: %d", len(denyList), authListSizeLimitation) + } + } return nil } @@ -76,7 +86,6 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe isValidatorExists := false allowedList := a.GetAllowList().GetAddress() for _, validator := range allowedList { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization") if validator == validatorAddress { isValidatorExists = true break @@ -85,7 +94,6 @@ func (a StakeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRe denyList := a.GetDenyList().GetAddress() for _, validator := range denyList { - ctx.GasMeter().ConsumeGas(gasCostPerIteration, "stake authorization") if validator == validatorAddress { return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrapf("cannot delegate/undelegate to %s validator", validator) } diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index aebb5795b2..8c8cb43cbe 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -31,7 +31,7 @@ func GetQueryCmd() *cobra.Command { func GetCurrentPlanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "plan", - Short: "get upgrade plan (if one exists)", + Short: "Get upgrade plan (if one exists)", Long: "Gets the currently scheduled upgrade plan, if one exists", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { @@ -65,7 +65,7 @@ func GetCurrentPlanCmd() *cobra.Command { func GetAppliedPlanCmd() *cobra.Command { cmd := &cobra.Command{ Use: "applied [upgrade-name]", - Short: "block header for height at which a completed upgrade was applied", + Short: "Block header for height at which a completed upgrade was applied", Long: "If upgrade-name was previously executed on the chain, this returns the header for the block at which it was applied.\n" + "This helps a client determine which binary was valid over a given range of blocks, as well as more context to understand past migrations.", Args: cobra.ExactArgs(1), @@ -117,7 +117,7 @@ func GetAppliedPlanCmd() *cobra.Command { func GetModuleVersionsCmd() *cobra.Command { cmd := &cobra.Command{ Use: "module_versions [optional module_name]", - Short: "get the list of module versions", + Short: "Get the list of module versions", Long: "Gets a list of module names and their respective consensus versions.\n" + "Following the command with a specific module name will return only\n" + "that module's information.",