From c291fa0b1e7e54a1fac67a78cc2da0c89c3897cd Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Mon, 19 Aug 2024 18:52:16 +0200 Subject: [PATCH] chore: remove globalfee module --- ante/ante.go | 17 +- app/app.go | 11 +- app/keepers/keepers.go | 4 +- app/modules.go | 15 +- tests/e2e/e2e_globalfee_proposal_test.go | 123 --- tests/e2e/e2e_globalfee_test.go | 335 -------- tests/e2e/e2e_test.go | 9 - tests/e2e/genesis.go | 15 - tests/e2e/query.go | 34 - x/globalfee/README.md | 5 - x/globalfee/alias.go | 9 - x/globalfee/ante/antetest/fee_test.go | 798 ------------------ x/globalfee/ante/antetest/fee_test_setup.go | 121 --- x/globalfee/ante/fee.go | 267 ------ x/globalfee/ante/fee_utils.go | 116 --- x/globalfee/ante/fee_utils_test.go | 299 ------- x/globalfee/client/cli/query.go | 48 -- x/globalfee/genesis_test.go | 164 ---- x/globalfee/keeper/migrations.go | 23 - x/globalfee/migrations/v2/migration.go | 38 - .../migrations/v2/v2_test/migration_test.go | 110 --- x/globalfee/module.go | 137 --- x/globalfee/querier.go | 52 -- x/globalfee/types/genesis.go | 41 - x/globalfee/types/genesis.pb.go | 622 -------------- x/globalfee/types/keys.go | 8 - x/globalfee/types/params.go | 158 ---- x/globalfee/types/params_test.go | 157 ---- x/globalfee/types/query.pb.go | 536 ------------ x/globalfee/types/query.pb.gw.go | 153 ---- 30 files changed, 10 insertions(+), 4415 deletions(-) delete mode 100644 tests/e2e/e2e_globalfee_proposal_test.go delete mode 100644 tests/e2e/e2e_globalfee_test.go delete mode 100644 x/globalfee/README.md delete mode 100644 x/globalfee/alias.go delete mode 100644 x/globalfee/ante/antetest/fee_test.go delete mode 100644 x/globalfee/ante/antetest/fee_test_setup.go delete mode 100644 x/globalfee/ante/fee.go delete mode 100644 x/globalfee/ante/fee_utils.go delete mode 100644 x/globalfee/ante/fee_utils_test.go delete mode 100644 x/globalfee/client/cli/query.go delete mode 100644 x/globalfee/genesis_test.go delete mode 100644 x/globalfee/keeper/migrations.go delete mode 100644 x/globalfee/migrations/v2/migration.go delete mode 100644 x/globalfee/migrations/v2/v2_test/migration_test.go delete mode 100644 x/globalfee/module.go delete mode 100644 x/globalfee/querier.go delete mode 100644 x/globalfee/types/genesis.go delete mode 100644 x/globalfee/types/genesis.pb.go delete mode 100644 x/globalfee/types/keys.go delete mode 100644 x/globalfee/types/params.go delete mode 100644 x/globalfee/types/params_test.go delete mode 100644 x/globalfee/types/query.pb.go delete mode 100644 x/globalfee/types/query.pb.gw.go diff --git a/ante/ante.go b/ante/ante.go index cc445578..5696b989 100644 --- a/ante/ante.go +++ b/ante/ante.go @@ -9,22 +9,19 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" atomoneerrors "github.com/atomone-hub/atomone/types/errors" - atomonefeeante "github.com/atomone-hub/atomone/x/globalfee/ante" ) // HandlerOptions extend the SDK's AnteHandler options by requiring the IBC // channel keeper. type HandlerOptions struct { ante.HandlerOptions - Codec codec.BinaryCodec - IBCkeeper *ibckeeper.Keeper - GlobalFeeSubspace paramtypes.Subspace - StakingKeeper *stakingkeeper.Keeper - TxFeeChecker ante.TxFeeChecker + Codec codec.BinaryCodec + IBCkeeper *ibckeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + TxFeeChecker ante.TxFeeChecker } func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { @@ -41,10 +38,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { return nil, errorsmod.Wrap(atomoneerrors.ErrLogic, "IBC keeper is required for AnteHandler") } - if opts.GlobalFeeSubspace.Name() == "" { - return nil, errorsmod.Wrap(atomoneerrors.ErrNotFound, "globalfee param store is required for AnteHandler") - } - if opts.StakingKeeper == nil { return nil, errorsmod.Wrap(atomoneerrors.ErrNotFound, "staking param store is required for AnteHandler") } @@ -53,7 +46,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { if sigGasConsumer == nil { sigGasConsumer = ante.DefaultSigVerificationGasConsumer } - anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker), @@ -62,7 +54,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { ante.NewValidateMemoDecorator(opts.AccountKeeper), ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), NewGovVoteDecorator(opts.Codec, opts.StakingKeeper), - atomonefeeante.NewFeeDecorator(opts.GlobalFeeSubspace, opts.StakingKeeper), ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(opts.AccountKeeper), diff --git a/app/app.go b/app/app.go index 947a2f5d..ce526ef9 100644 --- a/app/app.go +++ b/app/app.go @@ -55,7 +55,6 @@ import ( "github.com/atomone-hub/atomone/app/keepers" "github.com/atomone-hub/atomone/app/params" "github.com/atomone-hub/atomone/app/upgrades" - "github.com/atomone-hub/atomone/x/globalfee" ) var ( @@ -222,13 +221,11 @@ func NewAtomOneApp( SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, - Codec: appCodec, - IBCkeeper: app.IBCKeeper, - GlobalFeeSubspace: app.GetSubspace(globalfee.ModuleName), - StakingKeeper: app.StakingKeeper, + Codec: appCodec, + IBCkeeper: app.IBCKeeper, + StakingKeeper: app.StakingKeeper, // If TxFeeChecker is nil the default ante TxFeeChecker is used - // so we use this no-op to keep the global fee module behaviour unchanged - TxFeeChecker: noOpTxFeeChecker, + TxFeeChecker: nil, }, ) if err != nil { diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 3bbd2b18..a642e98e 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -11,6 +11,7 @@ import ( pfmrouter "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward" pfmrouterkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper" pfmroutertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" @@ -67,8 +68,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/atomone-hub/atomone/x/globalfee" ) type AppKeepers struct { @@ -444,7 +443,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(pfmroutertypes.ModuleName).WithKeyTable(pfmroutertypes.ParamKeyTable()) - paramsKeeper.Subspace(globalfee.ModuleName) paramsKeeper.Subspace(providertypes.ModuleName) return paramsKeeper diff --git a/app/modules.go b/app/modules.go index 04fad902..40e74be3 100644 --- a/app/modules.go +++ b/app/modules.go @@ -3,6 +3,7 @@ package atomone import ( pfmrouter "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward" pfmroutertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types" + ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" "github.com/cosmos/ibc-go/v7/modules/apps/transfer" @@ -56,7 +57,6 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" atomoneappparams "github.com/atomone-hub/atomone/app/params" - "github.com/atomone-hub/atomone/x/globalfee" "github.com/atomone-hub/atomone/x/metaprotocols" metaprotocolstypes "github.com/atomone-hub/atomone/x/metaprotocols/types" ) @@ -110,7 +110,6 @@ var ModuleBasics = module.NewBasicManager( vesting.AppModuleBasic{}, pfmrouter.AppModuleBasic{}, ica.AppModuleBasic{}, - globalfee.AppModule{}, icsprovider.AppModuleBasic{}, consensus.AppModuleBasic{}, metaprotocols.AppModuleBasic{}, @@ -146,7 +145,6 @@ func appModules( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), sdkparams.NewAppModule(app.ParamsKeeper), - globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), app.TransferModule, app.ICAModule, @@ -220,7 +218,6 @@ func orderBeginBlockers() []string { feegrant.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, - globalfee.ModuleName, providertypes.ModuleName, consensusparamtypes.ModuleName, metaprotocolstypes.ModuleName, @@ -257,7 +254,6 @@ func orderEndBlockers() []string { paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - globalfee.ModuleName, providertypes.ModuleName, consensusparamtypes.ModuleName, metaprotocolstypes.ModuleName, @@ -294,15 +290,6 @@ func orderInitBlockers() []string { paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, - // The globalfee module should ideally be initialized before the genutil module in theory: - // The globalfee antehandler performs checks in DeliverTx, which is called by gentx. - // When the global fee > 0, gentx needs to pay the fee. However, this is not expected, - // (in our case, the global fee is initialized with an empty value, which might not be a problem - // if the globalfee in genesis is not changed.) - // To resolve this issue, we should initialize the globalfee module after genutil, ensuring that the global - // min fee is empty when gentx is called. - // For more details, please refer to the following link: https://github.com/cosmos/gaia/issues/2489 - globalfee.ModuleName, providertypes.ModuleName, consensusparamtypes.ModuleName, metaprotocolstypes.ModuleName, diff --git a/tests/e2e/e2e_globalfee_proposal_test.go b/tests/e2e/e2e_globalfee_proposal_test.go deleted file mode 100644 index 58fe2197..00000000 --- a/tests/e2e/e2e_globalfee_proposal_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package e2e - -import ( - "fmt" - "strconv" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" -) - -func (s *IntegrationTestSuite) govProposeNewGlobalfee(newGlobalfee sdk.DecCoins, proposalCounter int, submitter string, _ string) { - s.writeGovParamChangeProposalGlobalFees(s.chainA, newGlobalfee) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) - submitGovFlags := []string{"param-change", configFile(proposalGlobalFeeFilename)} - depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()} - voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"} - - // gov proposing new fees - s.T().Logf("Proposal number: %d", proposalCounter) - s.T().Logf("Submitting, deposit and vote legacy Gov Proposal: change global fee to %s", newGlobalfee.String()) - s.submitLegacyGovProposal(chainAAPIEndpoint, submitter, proposalCounter, paramtypes.ProposalTypeChange, submitGovFlags, depositGovFlags, voteGovFlags, "vote", false) - - // query the proposal status and new fee - s.Require().Eventually( - func() bool { - proposal, err := queryGovProposal(chainAAPIEndpoint, proposalCounter) - s.Require().NoError(err) - return proposal.GetProposal().Status == govv1beta1.StatusPassed - }, - 15*time.Second, - 5*time.Second, - ) - - s.Require().Eventually( - func() bool { - globalFees, err := queryGlobalFees(chainAAPIEndpoint) - s.T().Logf("After gov new global fee proposal: %s", globalFees.String()) - s.Require().NoError(err) - - // attention: if global fee is empty, when query globalfee, it shows empty rather than default ante.DefaultZeroGlobalFee() = 0uatom. - return globalFees.IsEqual(newGlobalfee) - }, - 15*time.Second, - 5*time.Second, - ) -} - -func (s *IntegrationTestSuite) govProposeNewBypassMsgs(newBypassMsgs []string, proposalCounter int, submitter string, fees string) { //nolint:unparam - s.writeGovParamChangeProposalBypassMsgs(s.chainA, newBypassMsgs) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) - submitGovFlags := []string{"param-change", configFile(proposalBypassMsgFilename)} - depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()} - voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"} - - // gov proposing new fees - s.T().Logf("Proposal number: %d", proposalCounter) - s.T().Logf("Submitting, deposit and vote legacy Gov Proposal: change bypass min fee msg types to %s", newBypassMsgs) - s.submitLegacyGovProposal(chainAAPIEndpoint, submitter, proposalCounter, paramtypes.ProposalTypeChange, submitGovFlags, depositGovFlags, voteGovFlags, "vote", false) - - // query the proposal status and new fee - s.Require().Eventually( - func() bool { - proposal, err := queryGovProposal(chainAAPIEndpoint, proposalCounter) - s.Require().NoError(err) - return proposal.GetProposal().Status == govv1beta1.StatusPassed - }, - 15*time.Second, - 5*time.Second, - ) - - s.Require().Eventually( - func() bool { - bypassMsgs, err := queryBypassMsgs(chainAAPIEndpoint) - s.T().Logf("After gov new global fee proposal: %s", newBypassMsgs) - s.Require().NoError(err) - - // attention: if global fee is empty, when query globalfee, it shows empty rather than default ante.DefaultZeroGlobalFee() = 0uatom. - s.Require().Equal(newBypassMsgs, bypassMsgs) - return true - }, - 15*time.Second, - 5*time.Second, - ) -} - -func (s *IntegrationTestSuite) govProposeNewMaxTotalBypassMinFeeMsgGasUsage(newGas uint64, proposalCounter int, submitter string) { - s.writeGovParamChangeProposalMaxTotalBypass(s.chainA, newGas) - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) - submitGovFlags := []string{"param-change", configFile(proposalMaxTotalBypassFilename)} - depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()} - voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"} - - // gov proposing new max gas usage for bypass msgs - s.T().Logf("Proposal number: %d", proposalCounter) - s.T().Logf("Submitting, deposit and vote legacy Gov Proposal: change maxTotalBypassMinFeeMsgGasUsage to %d", newGas) - s.submitLegacyGovProposal(chainAAPIEndpoint, submitter, proposalCounter, paramtypes.ProposalTypeChange, submitGovFlags, depositGovFlags, voteGovFlags, "vote", false) - - // query the proposal status and max gas usage for bypass msgs - s.Require().Eventually( - func() bool { - proposal, err := queryGovProposal(chainAAPIEndpoint, proposalCounter) - s.Require().NoError(err) - return proposal.GetProposal().Status == govv1beta1.StatusPassed - }, - 15*time.Second, - 5*time.Second, - ) - - s.Require().Eventually( - func() bool { - gas, err := queryMaxTotalBypassMinFeeMsgGasUsage(chainAAPIEndpoint) - s.T().Logf("After gov new global fee proposal: %d", gas) - s.Require().NoError(err) - - s.Require().Equal(newGas, gas) - return true - }, - 15*time.Second, - 5*time.Second, - ) -} diff --git a/tests/e2e/e2e_globalfee_test.go b/tests/e2e/e2e_globalfee_test.go deleted file mode 100644 index 9de4cdea..00000000 --- a/tests/e2e/e2e_globalfee_test.go +++ /dev/null @@ -1,335 +0,0 @@ -package e2e - -import ( - "fmt" - "time" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// globalfee in genesis is set to be "0.00001uatom" -func (s *IntegrationTestSuite) testQueryGlobalFeesInGenesis() { - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) - feeInGenesis, err := sdk.ParseDecCoins(initialGlobalFeeAmt + uatomDenom) - s.Require().NoError(err) - s.Require().Eventually( - func() bool { - fees, err := queryGlobalFees(chainAAPIEndpoint) - s.T().Logf("Global Fees in Genesis: %s", fees.String()) - s.Require().NoError(err) - - return fees.IsEqual(feeInGenesis) - }, - 15*time.Second, - 5*time.Second, - ) -} - -/* -global fee e2e tests: -initial setup: initial globalfee = 0.00001uatom, min_gas_price = 0.00001uatom -(This initial value setup is to pass other e2e tests) - -test1: gov proposal globalfee = [], min_gas_price=0.00001uatom, query globalfee still get empty -- tx with fee denom photon, fail -- tx with zero fee denom photon, fail -- tx with fee denom uatom, pass -- tx with fee empty, fail - -test2: gov propose globalfee = 0.000001uatom(lower than min_gas_price) -- tx with fee higher than 0.000001uatom but lower than 0.00001uatom, fail -- tx with fee higher than/equal to 0.00001uatom, pass -- tx with fee photon fail - -test3: gov propose globalfee = 0.0001uatom (higher than min_gas_price) -- tx with fee equal to 0.0001uatom, pass -- tx with fee equal to 0.00001uatom, fail - -test4: gov propose globalfee = 0.000001uatom (lower than min_gas_price), 0photon -- tx with fee 0.0000001photon, fail -- tx with fee 0.000001photon, pass -- tx with empty fee, pass -- tx with fee photon pass -- tx with fee 0photon, 0.000005uatom fail -- tx with fee 0photon, 0.00001uatom pass -test5: check balance correct: all the successful bank sent tokens are received -test6: gov propose change back to initial globalfee = 0.00001photon, This is for not influence other e2e tests. -*/ -func (s *IntegrationTestSuite) testGlobalFees() { - chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) - - submitterAddr, _ := s.chainA.validators[0].keyInfo.GetAddress() - submitter := submitterAddr.String() - recipientAddress, _ := s.chainA.validators[1].keyInfo.GetAddress() - recipient := recipientAddress.String() - - var beforeRecipientPhotonBalance sdk.Coin - s.Require().Eventually( - func() bool { - var err error - beforeRecipientPhotonBalance, err = getSpecificBalance(chainAAPIEndpoint, recipient, photonDenom) - s.Require().NoError(err) - - return beforeRecipientPhotonBalance.IsValid() - }, - 10*time.Second, - 5*time.Second, - ) - if beforeRecipientPhotonBalance.Equal(sdk.Coin{}) { - beforeRecipientPhotonBalance = sdk.NewCoin(photonDenom, sdk.ZeroInt()) - } - - sendAmt := int64(1000) - token := sdk.NewInt64Coin(photonDenom, sendAmt) // send 1000photon each time - sucessBankSendCount := 0 - - // ---------------------------- test1: globalfee empty -------------------------------------------- - // prepare gov globalfee proposal - emptyGlobalFee := sdk.DecCoins{} - proposalCounter++ - s.govProposeNewGlobalfee(emptyGlobalFee, proposalCounter, submitter, standardFees.String()) - paidFeeAmt := math.LegacyMustNewDecFromStr(minGasPrice).Mul(math.LegacyNewDec(gas)).String() - - s.T().Logf("test case: empty global fee, globalfee=%s, min_gas_price=%s", emptyGlobalFee.String(), minGasPrice+uatomDenom) - txBankSends := []txBankSend{ - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + uatomDenom, - log: "Tx fee is zero coin with correct denom: uatom, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "", - log: "Tx fee is empty, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "4" + photonDenom, - log: "Tx with wrong denom: photon, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + photonDenom, - log: "Tx fee is zero coins of wrong denom: photon, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmt + uatomDenom, - log: "Tx fee is higher than min_gas_price, pass", - expectErr: false, - }, - } - sucessBankSendCount += s.execBankSendBatch(s.chainA, 0, txBankSends...) - - // ------------------ test2: globalfee lower than min_gas_price ----------------------------------- - // prepare gov globalfee proposal - lowGlobalFee := sdk.DecCoins{sdk.NewDecCoinFromDec(uatomDenom, sdk.MustNewDecFromStr(lowGlobalFeesAmt))} - proposalCounter++ - s.govProposeNewGlobalfee(lowGlobalFee, proposalCounter, submitter, standardFees.String()) - - paidFeeAmt = math.LegacyMustNewDecFromStr(minGasPrice).Mul(math.LegacyNewDec(gas)).String() - paidFeeAmtLowMinGasHighGlobalFee := math.LegacyMustNewDecFromStr(lowGlobalFeesAmt). - Mul(math.LegacyNewDec(2)). - Mul(math.LegacyNewDec(gas)). - String() - paidFeeAmtLowGlobalFee := math.LegacyMustNewDecFromStr(lowGlobalFeesAmt).Quo(math.LegacyNewDec(2)).String() - - s.T().Logf("test case: global fee is lower than min_gas_price, globalfee=%s, min_gas_price=%s", lowGlobalFee.String(), minGasPrice+uatomDenom) - txBankSends = []txBankSend{ - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmt + uatomDenom, - log: "Tx fee higher than/equal to min_gas_price and global fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmtLowGlobalFee + uatomDenom, - log: "Tx fee lower than/equal to min_gas_price and global fee, pass", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmtLowMinGasHighGlobalFee + uatomDenom, - log: "Tx fee lower than/equal global fee and lower than min_gas_price, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmt + photonDenom, - log: "Tx fee has wrong denom, fail", - expectErr: true, - }, - } - sucessBankSendCount += s.execBankSendBatch(s.chainA, 0, txBankSends...) - - // ------------------ test3: globalfee higher than min_gas_price ---------------------------------- - // prepare gov globalfee proposal - highGlobalFee := sdk.DecCoins{sdk.NewDecCoinFromDec(uatomDenom, sdk.MustNewDecFromStr(highGlobalFeeAmt))} - proposalCounter++ - s.govProposeNewGlobalfee(highGlobalFee, proposalCounter, submitter, paidFeeAmt+uatomDenom) - - paidFeeAmt = math.LegacyMustNewDecFromStr(highGlobalFeeAmt).Mul(math.LegacyNewDec(gas)).String() - paidFeeAmtHigherMinGasLowerGalobalFee := math.LegacyMustNewDecFromStr(minGasPrice). - Quo(math.LegacyNewDec(2)).String() - - s.T().Logf("test case: global fee is higher than min_gas_price, globalfee=%s, min_gas_price=%s", highGlobalFee.String(), minGasPrice+uatomDenom) - txBankSends = []txBankSend{ - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmt + uatomDenom, - log: "Tx fee is higher than/equal to global fee and min_gas_price, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmtHigherMinGasLowerGalobalFee + uatomDenom, - log: "Tx fee is higher than/equal to min_gas_price but lower than global fee, fail", - expectErr: true, - }, - } - sucessBankSendCount += s.execBankSendBatch(s.chainA, 0, txBankSends...) - - // ---------------------------- test4: global fee with two denoms ----------------------------------- - // prepare gov globalfee proposal - mixGlobalFee := sdk.DecCoins{ - sdk.NewDecCoinFromDec(photonDenom, sdk.NewDec(0)), - sdk.NewDecCoinFromDec(uatomDenom, sdk.MustNewDecFromStr(lowGlobalFeesAmt)), - }.Sort() - proposalCounter++ - s.govProposeNewGlobalfee(mixGlobalFee, proposalCounter, submitter, paidFeeAmt+uatomDenom) - - // equal to min_gas_price - paidFeeAmt = math.LegacyMustNewDecFromStr(minGasPrice).Mul(math.LegacyNewDec(gas)).String() - paidFeeAmtLow := math.LegacyMustNewDecFromStr(lowGlobalFeesAmt). - Quo(math.LegacyNewDec(2)). - Mul(math.LegacyNewDec(gas)). - String() - - s.T().Logf("test case: global fees contain multiple denoms: one zero coin, one non-zero coin, globalfee=%s, min_gas_price=%s", mixGlobalFee.String(), minGasPrice+uatomDenom) - txBankSends = []txBankSend{ - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmt + uatomDenom, - log: "Tx with fee higher than/equal to one of denom's amount the global fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: paidFeeAmtLow + uatomDenom, - log: "Tx with fee lower than one of denom's amount the global fee, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "", - log: "Tx with fee empty fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + photonDenom, - log: "Tx with zero coin in the denom of zero coin of global fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + photonDenom, - log: "Tx with zero coin in the denom of zero coin of global fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "2" + photonDenom, - log: "Tx with non-zero coin in the denom of zero coin of global fee, pass", - expectErr: false, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + photonDenom + "," + paidFeeAmtLow + uatomDenom, - log: "Tx with multiple fee coins, zero coin and low fee, fail", - expectErr: true, - }, - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "0" + photonDenom + "," + paidFeeAmt + uatomDenom, - log: "Tx with multiple fee coins, zero coin and high fee, pass", - expectErr: false, - }, - - { - from: submitter, - to: recipient, - amt: token.String(), - fees: "2" + photonDenom + "," + paidFeeAmt + uatomDenom, - log: "Tx with multiple fee coins, all higher than global fee and min_gas_price", - expectErr: false, - }, - } - sucessBankSendCount += s.execBankSendBatch(s.chainA, 0, txBankSends...) - - // --------------------------------------------------------------------------- - // check the balance is correct after previous txs - s.Require().Eventually( - func() bool { - afterRecipientPhotonBalance, err := getSpecificBalance(chainAAPIEndpoint, recipient, photonDenom) - s.Require().NoError(err) - IncrementedPhoton := afterRecipientPhotonBalance.Sub(beforeRecipientPhotonBalance) - photonSent := sdk.NewInt64Coin(photonDenom, sendAmt*int64(sucessBankSendCount)) - return IncrementedPhoton.IsEqual(photonSent) - }, - time.Minute, - 5*time.Second, - ) - - // gov proposing to change back to original global fee - s.T().Logf("Propose to change back to original global fees: %s", initialGlobalFeeAmt+uatomDenom) - oldfees, err := sdk.ParseDecCoins(initialGlobalFeeAmt + uatomDenom) - s.Require().NoError(err) - proposalCounter++ - s.govProposeNewGlobalfee(oldfees, proposalCounter, submitter, paidFeeAmt+photonDenom) -} diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 86e3641c..f4361a7c 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -8,7 +8,6 @@ var ( runEncodeTest = true runEvidenceTest = true runFeeGrantTest = true - runGlobalFeesTest = true runGovTest = true runSlashingTest = true runStakingAndDistributionTest = true @@ -54,14 +53,6 @@ func (s *IntegrationTestSuite) TestFeeGrant() { s.testFeeGrant() } -func (s *IntegrationTestSuite) TestGlobalFees() { - if !runGlobalFeesTest { - s.T().Skip() - } - s.testGlobalFees() - s.testQueryGlobalFeesInGenesis() -} - func (s *IntegrationTestSuite) TestGov() { if !runGovTest { s.T().Skip() diff --git a/tests/e2e/genesis.go b/tests/e2e/genesis.go index fa31a96b..74a4b85b 100644 --- a/tests/e2e/genesis.go +++ b/tests/e2e/genesis.go @@ -22,8 +22,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govlegacytypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - globfeetypes "github.com/atomone-hub/atomone/x/globalfee/types" ) func getGenDoc(path string) (*tmtypes.GenesisDoc, error) { @@ -160,19 +158,6 @@ func modifyGenesis(path, moniker, amountStr string, addrAll []sdk.AccAddress, gl } appState[icatypes.ModuleName] = icaGenesisStateBz - // setup global fee in genesis - globfeeState := globfeetypes.GetGenesisStateFromAppState(cdc, appState) - minGases, err := sdk.ParseDecCoins(globfees) - if err != nil { - return fmt.Errorf("failed to parse fee coins: %w", err) - } - globfeeState.Params.MinimumGasPrices = minGases - globFeeStateBz, err := cdc.MarshalJSON(globfeeState) - if err != nil { - return fmt.Errorf("failed to marshal global fee genesis state: %w", err) - } - appState[globfeetypes.ModuleName] = globFeeStateBz - stakingGenState := stakingtypes.GetGenesisStateFromAppState(cdc, appState) stakingGenState.Params.BondDenom = denom stakingGenStateBz, err := cdc.MarshalJSON(stakingGenState) diff --git a/tests/e2e/query.go b/tests/e2e/query.go index c6081277..a75063a5 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -15,8 +15,6 @@ import ( evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - "github.com/atomone-hub/atomone/x/globalfee/types" ) func queryAtomOneTx(endpoint, txHash string) error { @@ -87,38 +85,6 @@ func queryStakingParams(endpoint string) (stakingtypes.QueryParamsResponse, erro return params, nil } -func queryGlobalFeeParams(endpoint string) (types.QueryParamsResponse, error) { - body, err := httpGet(fmt.Sprintf("%s/atomone/globalfee/v1beta1/params", endpoint)) - if err != nil { - return types.QueryParamsResponse{}, fmt.Errorf("failed to execute HTTP request: %w", err) - } - - var params types.QueryParamsResponse - if err := cdc.UnmarshalJSON(body, ¶ms); err != nil { - return types.QueryParamsResponse{}, err - } - - return params, nil -} - -func queryGlobalFees(endpoint string) (sdk.DecCoins, error) { - p, err := queryGlobalFeeParams(endpoint) - - return p.Params.MinimumGasPrices, err -} - -func queryBypassMsgs(endpoint string) ([]string, error) { - p, err := queryGlobalFeeParams(endpoint) - - return p.Params.BypassMinFeeMsgTypes, err -} - -func queryMaxTotalBypassMinFeeMsgGasUsage(endpoint string) (uint64, error) { - p, err := queryGlobalFeeParams(endpoint) - - return p.Params.MaxTotalBypassMinFeeMsgGasUsage, err -} - func queryDelegation(endpoint string, validatorAddr string, delegatorAddr string) (stakingtypes.QueryDelegationResponse, error) { var res stakingtypes.QueryDelegationResponse diff --git a/x/globalfee/README.md b/x/globalfee/README.md deleted file mode 100644 index 746d5c14..00000000 --- a/x/globalfee/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Global fee module - -The Global fee module was supplied by the great folks at [TGrade](https://github.com/confio/tgrade) 👋, with minor modifications. All credits and big thanks go to the original authors. - -More information about Cosmoshub fee system please check [here](../../docs/modules/globalfee.md). diff --git a/x/globalfee/alias.go b/x/globalfee/alias.go deleted file mode 100644 index d51ee809..00000000 --- a/x/globalfee/alias.go +++ /dev/null @@ -1,9 +0,0 @@ -package globalfee - -import ( - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -const ( - ModuleName = types.ModuleName -) diff --git a/x/globalfee/ante/antetest/fee_test.go b/x/globalfee/ante/antetest/fee_test.go deleted file mode 100644 index 0d52b45b..00000000 --- a/x/globalfee/ante/antetest/fee_test.go +++ /dev/null @@ -1,798 +0,0 @@ -package antetest - -import ( - "testing" - - "github.com/stretchr/testify/suite" - - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - - atomonefeeante "github.com/atomone-hub/atomone/x/globalfee/ante" - globfeetypes "github.com/atomone-hub/atomone/x/globalfee/types" -) - -var testGasLimit uint64 = 200_000 - -func TestIntegrationTestSuite(t *testing.T) { - suite.Run(t, new(IntegrationTestSuite)) -} - -func (s *IntegrationTestSuite) TestGetDefaultGlobalFees() { - // set globalfees and min gas price - feeDecorator, _ := s.SetupTestGlobalFeeStoreAndMinGasPrice([]sdk.DecCoin{}, &globfeetypes.Params{}) - defaultGlobalFees, err := feeDecorator.DefaultZeroGlobalFee(s.ctx) - s.Require().NoError(err) - s.Require().Greater(len(defaultGlobalFees), 0) - - if defaultGlobalFees[0].Denom != testBondDenom { - s.T().Fatalf("bond denom: %s, default global fee denom: %s", testBondDenom, defaultGlobalFees[0].Denom) - } -} - -// Test global fees and min_gas_price with bypass msg types. -// Please note even globalfee=0, min_gas_price=0, we do not let fee=0random_denom pass. -// Paid fees are already sanitized by removing zero coins(through feeFlag parsing), so use sdk.NewCoins() to create it. -func (s *IntegrationTestSuite) TestGlobalFeeMinimumGasFeeAnteHandler() { - s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder() - priv1, _, addr1 := testdata.KeyTestPubAddr() - privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - - denominator := int64(100000) - high := sdk.NewDec(400).Quo(sdk.NewDec(denominator)) // 0.004 - med := sdk.NewDec(200).Quo(sdk.NewDec(denominator)) // 0.002 - low := sdk.NewDec(100).Quo(sdk.NewDec(denominator)) // 0.001 - - highFeeAmt := sdk.NewInt(high.MulInt64(int64(2) * denominator).RoundInt64()) - medFeeAmt := sdk.NewInt(med.MulInt64(int64(2) * denominator).RoundInt64()) - lowFeeAmt := sdk.NewInt(low.MulInt64(int64(2) * denominator).RoundInt64()) - - globalfeeParamsEmpty := []sdk.DecCoin{} - minGasPriceEmpty := []sdk.DecCoin{} - globalfeeParams0 := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("photon", sdk.NewDec(0)), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(0)), - } - globalfeeParamsContain0 := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("photon", med), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(0)), - } - minGasPrice0 := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("stake", sdk.NewDec(0)), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(0)), - } - globalfeeParamsHigh := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("uatom", high), - } - minGasPrice := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("uatom", med), - sdk.NewDecCoinFromDec("stake", med), - } - globalfeeParamsLow := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("uatom", low), - } - // global fee must be sorted in denom - globalfeeParamsNewDenom := []sdk.DecCoin{ - sdk.NewDecCoinFromDec("photon", high), - sdk.NewDecCoinFromDec("quark", high), - } - - testCases := map[string]struct { - minGasPrice []sdk.DecCoin - globalFee []sdk.DecCoin - gasPrice sdk.Coins - gasLimit sdk.Gas - txMsg sdk.Msg - txCheck bool - expErr bool - }{ - // test fees - // empty min_gas_price or empty global fee - "empty min_gas_price, nonempty global fee, fee higher/equal than global_fee": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParamsHigh, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "empty min_gas_price, nonempty global fee, fee lower than global_fee": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParamsHigh, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "nonempty min_gas_price with defaultGlobalFee denom, empty global fee, fee higher/equal than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsEmpty, // default 0uatom - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", medFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "nonempty min_gas_price with defaultGlobalFee denom, empty global fee, fee lower than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "empty min_gas_price, empty global fee, empty fee": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.Coins{}, - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - // zero min_gas_price or zero global fee - "zero min_gas_price, zero global fee, zero fee in global fee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt()), sdk.NewCoin("photon", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, zero global fee, empty fee": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParams0, - gasPrice: sdk.Coins{}, - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - // zero global fee - "zero min_gas_price, zero global fee, zero fee not in globalfee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, zero global fee, zero fees one in, one not in globalfee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins( - sdk.NewCoin("stake", sdk.ZeroInt()), - sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - // zero min_gas_price and empty global fee - "zero min_gas_price, empty global fee, zero fee in min_gas_price_denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, empty global fee, zero fee not in min_gas_price denom, not in defaultZeroGlobalFee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("quark", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, empty global fee, zero fee in defaultZeroGlobalFee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, empty global fee, nonzero fee in defaultZeroGlobalFee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "zero min_gas_price, empty global fee, nonzero fee not in defaultZeroGlobalFee denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsEmpty, - gasPrice: sdk.NewCoins(sdk.NewCoin("quark", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - // empty min_gas_price, zero global fee - "empty min_gas_price, zero global fee, zero fee in global fee denom": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "empty min_gas_price, zero global fee, zero fee not in global fee denom": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "empty min_gas_price, zero global fee, nonzero fee in global fee denom": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "empty min_gas_price, zero global fee, nonzero fee not in global fee denom": { - minGasPrice: minGasPriceEmpty, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - // zero min_gas_price, nonzero global fee - "zero min_gas_price, nonzero global fee, fee is higher than global fee": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - // nonzero min_gas_price, nonzero global fee - "fee higher/equal than globalfee and min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsHigh, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "fee lower than globalfee and min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsHigh, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "fee with one denom higher/equal, one denom lower than globalfee and min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsNewDenom, - gasPrice: sdk.NewCoins( - sdk.NewCoin("photon", lowFeeAmt), - sdk.NewCoin("quark", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "globalfee > min_gas_price, fee higher/equal than min_gas_price, lower than globalfee": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsHigh, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", medFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "globalfee < min_gas_price, fee higher/equal than globalfee and lower than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - // nonzero min_gas_price, zero global fee - "nonzero min_gas_price, zero global fee, fee is in global fee denom and lower than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "nonzero min_gas_price, zero global fee, fee is in global fee denom and higher/equal than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", medFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "nonzero min_gas_price, zero global fee, fee is in min_gas_price denom which is not in global fee default, but higher/equal than min_gas_price": { - minGasPrice: minGasPrice, - globalFee: globalfeeParams0, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - // fee denom tests - "min_gas_price denom is not subset of global fee denom , fee paying in global fee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsNewDenom, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "min_gas_price denom is not subset of global fee denom, fee paying in min_gas_price denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsNewDenom, - gasPrice: sdk.NewCoins(sdk.NewCoin("stake", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "fees contain denom not in globalfee": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins( - sdk.NewCoin("uatom", highFeeAmt), - sdk.NewCoin("quark", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "fees contain denom not in globalfee with zero amount": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", highFeeAmt), - sdk.NewCoin("quark", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - // cases from https://github.com/cosmos/gaia/pull/1570#issuecomment-1190524402 - // note: this is kind of a silly scenario but technically correct - // if there is a zero coin in the globalfee, the user could pay 0fees - // if the user includes any fee at all in the non-zero denom, it must be higher than that non-zero fee - // unlikely we will ever see zero and non-zero together but technically possible - "globalfee contains zero coin and non-zero coin, fee is lower than the nonzero coin": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "globalfee contains zero coin, fee contains zero coins of the same denom and a lower fee of the other denom in global fee": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.NewCoins( - sdk.NewCoin("photon", lowFeeAmt), - sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "globalfee contains zero coin, fee is empty": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.Coins{}, - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "globalfee contains zero coin, fee contains lower fee of zero coins's denom, globalfee also contains nonzero coin,fee contains higher fee of nonzero coins's denom, ": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.NewCoins( - sdk.NewCoin("photon", lowFeeAmt), - sdk.NewCoin("uatom", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "globalfee contains zero coin, fee is all zero coins but in global fee's denom": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.NewCoins( - sdk.NewCoin("photon", sdk.ZeroInt()), - sdk.NewCoin("uatom", sdk.ZeroInt()), - ), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "globalfee contains zero coin, fee is higher than the nonzero coin": { - minGasPrice: minGasPrice0, - globalFee: globalfeeParamsContain0, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "bypass msg type: ibc.core.channel.v1.MsgRecvPacket": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgRecvPacket( - ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "bypass msg type: ibc.core.channel.v1.MsgTimeout": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgTimeout( - // todo check here - ibcchanneltypes.Packet{}, 1, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "bypass msg type: ibc.core.channel.v1.MsgTimeoutOnClose": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgTimeout( - ibcchanneltypes.Packet{}, 2, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "bypass msg gas usage exceeds maxTotalBypassMinFeeMsgGasUsage": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: 2 * globfeetypes.DefaultmaxTotalBypassMinFeeMsgGasUsage, - txMsg: ibcchanneltypes.NewMsgTimeout( - ibcchanneltypes.Packet{}, 2, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: true, - }, - "bypass msg gas usage equals to maxTotalBypassMinFeeMsgGasUsage": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: globfeetypes.DefaultmaxTotalBypassMinFeeMsgGasUsage, - txMsg: ibcchanneltypes.NewMsgTimeout( - ibcchanneltypes.Packet{}, 3, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "msg type ibc, zero fee not in globalfee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgRecvPacket( - ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "msg type ibc, nonzero fee in globalfee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgRecvPacket( - ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "msg type ibc, nonzero fee not in globalfee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgRecvPacket( - ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: true, - }, - "msg type ibc, empty fee": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.Coins{}, - gasLimit: testGasLimit, - txMsg: ibcchanneltypes.NewMsgRecvPacket( - ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - txCheck: true, - expErr: false, - }, - "msg type non-ibc, nonzero fee in globalfee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: false, - }, - "msg type non-ibc, empty fee": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.Coins{}, - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "msg type non-ibc, nonzero fee not in globalfee denom": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("photon", highFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: true, - expErr: true, - }, - "disable checkTx: min_gas_price is medium, global fee is low, tx fee is low": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", lowFeeAmt)), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: false, - expErr: false, - }, - "disable checkTx: min_gas_price is medium, global fee is low, tx is zero": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: false, - expErr: true, - }, - "disable checkTx: min_gas_price is low, global fee is low, tx fee's denom is not in global fees denoms set": { - minGasPrice: minGasPrice, - globalFee: globalfeeParamsLow, - gasPrice: sdk.NewCoins(sdk.NewCoin("quark", sdk.ZeroInt())), - gasLimit: testGasLimit, - txMsg: testdata.NewTestMsg(addr1), - txCheck: false, - expErr: true, - }, - } - - globalfeeParams := &globfeetypes.Params{ - BypassMinFeeMsgTypes: globfeetypes.DefaultBypassMinFeeMsgTypes, - MaxTotalBypassMinFeeMsgGasUsage: globfeetypes.DefaultmaxTotalBypassMinFeeMsgGasUsage, - } - - for name, tc := range testCases { - s.Run(name, func() { - // set globalfees and min gas price - globalfeeParams.MinimumGasPrices = tc.globalFee - _, antehandler := s.SetupTestGlobalFeeStoreAndMinGasPrice(tc.minGasPrice, globalfeeParams) - - // set fee decorator to ante handler - - s.Require().NoError(s.txBuilder.SetMsgs(tc.txMsg)) - s.txBuilder.SetFeeAmount(tc.gasPrice) - s.txBuilder.SetGasLimit(tc.gasLimit) - tx, err := s.CreateTestTx(privs, accNums, accSeqs, s.ctx.ChainID()) - s.Require().NoError(err) - - s.ctx = s.ctx.WithIsCheckTx(tc.txCheck) - _, err = antehandler(s.ctx, tx, false) - if !tc.expErr { - s.Require().NoError(err) - } else { - s.Require().Error(err) - } - }) - } -} - -// Test how the operator fees are determined using various min gas prices. -// -// Note that in a real Gaia deployment all zero coins can be removed from minGasPrice. -// This sanitizing happens when the minGasPrice is set into the context. -// (see baseapp.SetMinGasPrices in gaia/cmd/root.go line 221) -func (s *IntegrationTestSuite) TestGetMinGasPrice() { - expCoins := sdk.Coins{ - sdk.NewCoin("photon", sdk.NewInt(2000)), - sdk.NewCoin("uatom", sdk.NewInt(3000)), - } - - testCases := []struct { - name string - minGasPrice []sdk.DecCoin - feeTxGasLimit uint64 - expCoins sdk.Coins - }{ - { - "empty min gas price should return empty coins", - []sdk.DecCoin{}, - uint64(1000), - sdk.Coins{}, - }, - { - "zero coins min gas price should return empty coins", - []sdk.DecCoin{ - sdk.NewDecCoinFromDec("stake", sdk.NewDec(0)), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(0)), - }, - uint64(1000), - sdk.Coins{}, - }, - { - "zero coins, non-zero coins mix should return zero coin and non-zero coins", - []sdk.DecCoin{ - sdk.NewDecCoinFromDec("stake", sdk.NewDec(0)), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(1)), - }, - uint64(1000), - sdk.Coins{ - sdk.NewCoin("stake", sdk.NewInt(0)), - sdk.NewCoin("uatom", sdk.NewInt(1000)), - }, - }, - - { - "unsorted min gas price should return sorted coins", - []sdk.DecCoin{ - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(3)), - sdk.NewDecCoinFromDec("photon", sdk.NewDec(2)), - }, - uint64(1000), - expCoins, - }, - { - "sorted min gas price should return same conins", - []sdk.DecCoin{ - sdk.NewDecCoinFromDec("photon", sdk.NewDec(2)), - sdk.NewDecCoinFromDec("uatom", sdk.NewDec(3)), - }, - uint64(1000), - expCoins, - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - s.SetupTestGlobalFeeStoreAndMinGasPrice(tc.minGasPrice, &globfeetypes.Params{}) - - fees := atomonefeeante.GetMinGasPrice(s.ctx, int64(tc.feeTxGasLimit)) - s.Require().True(tc.expCoins.Sort().IsEqual(fees)) - }) - } -} - -func (s *IntegrationTestSuite) TestContainsOnlyBypassMinFeeMsgs() { - // set globalfees params and min gas price - globalfeeParams := &globfeetypes.Params{ - BypassMinFeeMsgTypes: globfeetypes.DefaultBypassMinFeeMsgTypes, - MaxTotalBypassMinFeeMsgGasUsage: globfeetypes.DefaultmaxTotalBypassMinFeeMsgGasUsage, - } - feeDecorator, _ := s.SetupTestGlobalFeeStoreAndMinGasPrice([]sdk.DecCoin{}, globalfeeParams) - testCases := []struct { - name string - msgs []sdk.Msg - expPass bool - }{ - { - "expect empty msgs to pass", - []sdk.Msg{}, - true, - }, - { - "expect default bypass msg to pass", - []sdk.Msg{ - ibcchanneltypes.NewMsgRecvPacket(ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - ibcchanneltypes.NewMsgAcknowledgement(ibcchanneltypes.Packet{}, []byte{1}, []byte{1}, ibcclienttypes.Height{}, ""), - }, - true, - }, - { - "msgs contain not only bypass msg - should not pass", - []sdk.Msg{ - ibcchanneltypes.NewMsgRecvPacket(ibcchanneltypes.Packet{}, nil, ibcclienttypes.Height{}, ""), - stakingtypes.NewMsgDelegate(sdk.AccAddress{}, sdk.ValAddress{}, sdk.Coin{}), - }, - false, - }, - { - "msgs contain only non-bypass msgs - should not pass", - []sdk.Msg{ - stakingtypes.NewMsgDelegate(sdk.AccAddress{}, sdk.ValAddress{}, sdk.Coin{}), - }, - false, - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - res := feeDecorator.ContainsOnlyBypassMinFeeMsgs(s.ctx, tc.msgs) - s.Require().True(tc.expPass == res) - }) - } -} - -func (s *IntegrationTestSuite) TestGetTxFeeRequired() { - // create global fee params - globalfeeParamsEmpty := &globfeetypes.Params{MinimumGasPrices: []sdk.DecCoin{}} - - // set non-zero local min gas prices - localMinGasPrices := sdk.NewCoins(sdk.NewCoin("uatom", sdk.NewInt(1))) - - // setup tests with non-empty local min gas prices - feeDecorator, _ := s.SetupTestGlobalFeeStoreAndMinGasPrice( - sdk.NewDecCoinsFromCoins(localMinGasPrices...), - globalfeeParamsEmpty, - ) - - // mock tx data - s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder() - priv1, _, addr1 := testdata.KeyTestPubAddr() - privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0} - - s.Require().NoError(s.txBuilder.SetMsgs(testdata.NewTestMsg(addr1))) - s.txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("uatom", sdk.ZeroInt()))) - - s.txBuilder.SetGasLimit(uint64(1)) - tx, err := s.CreateTestTx(privs, accNums, accSeqs, s.ctx.ChainID()) - s.Require().NoError(err) - - // check that the required fees returned in CheckTx mode are equal to - // local min gas prices since they're greater than the default global fee values. - s.Require().True(s.ctx.IsCheckTx()) - res, err := feeDecorator.GetTxFeeRequired(s.ctx, tx) - s.Require().True(res.IsEqual(localMinGasPrices)) - s.Require().NoError(err) - - // check that the global fee is returned in DeliverTx mode. - globalFee, err := feeDecorator.GetGlobalFee(s.ctx, tx) - s.Require().NoError(err) - - ctx := s.ctx.WithIsCheckTx(false) - res, err = feeDecorator.GetTxFeeRequired(ctx, tx) - s.Require().NoError(err) - s.Require().True(res.IsEqual(globalFee)) -} diff --git a/x/globalfee/ante/antetest/fee_test_setup.go b/x/globalfee/ante/antetest/fee_test_setup.go deleted file mode 100644 index ac399563..00000000 --- a/x/globalfee/ante/antetest/fee_test_setup.go +++ /dev/null @@ -1,121 +0,0 @@ -package antetest - -import ( - "fmt" - - "github.com/stretchr/testify/suite" - - tmrand "github.com/cometbft/cometbft/libs/rand" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - - gaiaapp "github.com/atomone-hub/atomone/app" - atomonehelpers "github.com/atomone-hub/atomone/app/helpers" - gaiaparams "github.com/atomone-hub/atomone/app/params" - "github.com/atomone-hub/atomone/x/globalfee" - atomonefeeante "github.com/atomone-hub/atomone/x/globalfee/ante" - globfeetypes "github.com/atomone-hub/atomone/x/globalfee/types" -) - -type IntegrationTestSuite struct { - suite.Suite - - app *gaiaapp.AtomOneApp - ctx sdk.Context - clientCtx client.Context - txBuilder client.TxBuilder -} - -var testBondDenom = "uatom" - -func (s *IntegrationTestSuite) SetupTest() { - app := atomonehelpers.Setup(s.T()) - ctx := app.BaseApp.NewContext(false, tmproto.Header{ - ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), - Height: 1, - }) - - encodingConfig := gaiaparams.MakeEncodingConfig() - encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) - testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry) - - s.app = app - s.ctx = ctx - s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig) -} - -func (s *IntegrationTestSuite) SetupTestGlobalFeeStoreAndMinGasPrice(minGasPrice []sdk.DecCoin, globalFeeParams *globfeetypes.Params) (atomonefeeante.FeeDecorator, sdk.AnteHandler) { - subspace := s.app.GetSubspace(globalfee.ModuleName) - subspace.SetParamSet(s.ctx, globalFeeParams) - s.ctx = s.ctx.WithMinGasPrices(minGasPrice).WithIsCheckTx(true) - - // setup staking bond denom to "uatom" - // since it's "stake" per default - params := s.app.StakingKeeper.GetParams(s.ctx) - params.BondDenom = testBondDenom - err := s.app.StakingKeeper.SetParams(s.ctx, params) - s.Require().NoError(err) - - // build fee decorator - feeDecorator := atomonefeeante.NewFeeDecorator(subspace, s.app.StakingKeeper) - - // chain fee decorator to antehandler - antehandler := sdk.ChainAnteDecorators(feeDecorator) - - return feeDecorator, antehandler -} - -func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) { - var sigsV2 []signing.SignatureV2 - for i, priv := range privs { - sigV2 := signing.SignatureV2{ - PubKey: priv.PubKey(), - Data: &signing.SingleSignatureData{ - SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), - Signature: nil, - }, - Sequence: accSeqs[i], - } - - sigsV2 = append(sigsV2, sigV2) - } - - if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { - return nil, err - } - - sigsV2 = []signing.SignatureV2{} - for i, priv := range privs { - signerData := xauthsigning.SignerData{ - ChainID: chainID, - AccountNumber: accNums[i], - Sequence: accSeqs[i], - } - sigV2, err := tx.SignWithPrivKey( - s.clientCtx.TxConfig.SignModeHandler().DefaultMode(), - signerData, - s.txBuilder, - priv, - s.clientCtx.TxConfig, - accSeqs[i], - ) - if err != nil { - return nil, err - } - - sigsV2 = append(sigsV2, sigV2) - } - - if err := s.txBuilder.SetSignatures(sigsV2...); err != nil { - return nil, err - } - - return s.txBuilder.GetTx(), nil -} diff --git a/x/globalfee/ante/fee.go b/x/globalfee/ante/fee.go deleted file mode 100644 index 132069a0..00000000 --- a/x/globalfee/ante/fee.go +++ /dev/null @@ -1,267 +0,0 @@ -package ante - -import ( - "errors" - "fmt" - - tmstrings "github.com/cometbft/cometbft/libs/strings" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - - atomoneerrors "github.com/atomone-hub/atomone/types/errors" - "github.com/atomone-hub/atomone/x/globalfee" - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -// FeeWithBypassDecorator checks if the transaction's fee is at least as large -// as the local validator's minimum gasFee (defined in validator config) and global fee, and the fee denom should be in the global fees' denoms. -// -// -// CONTRACT: Tx must implement FeeTx to use FeeDecorator -// If the tx msg type is one of the bypass msg types, the tx is valid even if the min fee is lower than normally required. -// If the bypass tx still carries fees, the fee denom should be the same as global fee required. - -var _ sdk.AnteDecorator = FeeDecorator{} - -type FeeDecorator struct { - GlobalMinFeeParamSource globalfee.ParamSource - StakingKeeper *stakingkeeper.Keeper -} - -func NewFeeDecorator(globalfeeSubspace paramtypes.Subspace, sk *stakingkeeper.Keeper) FeeDecorator { - if !globalfeeSubspace.HasKeyTable() { - panic("global fee paramspace was not set up via module") - } - - return FeeDecorator{ - GlobalMinFeeParamSource: globalfeeSubspace, - StakingKeeper: sk, - } -} - -// AnteHandle implements the AnteDecorator interface -func (mfd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - feeTx, ok := tx.(sdk.FeeTx) - if !ok { - return ctx, errorsmod.Wrap(atomoneerrors.ErrTxDecode, "Tx must implement the sdk.FeeTx interface") - } - - // Do not check minimum-gas-prices and global fees during simulations - if simulate { - return next(ctx, tx, simulate) - } - - // Get the required fees according to the CheckTx or DeliverTx modes - feeRequired, err := mfd.GetTxFeeRequired(ctx, feeTx) - if err != nil { - return ctx, err - } - - // reject the transaction early if the feeCoins have more denoms than the fee requirement - - // feeRequired cannot be empty - if feeTx.GetFee().Len() > feeRequired.Len() { - return ctx, errorsmod.Wrapf(atomoneerrors.ErrInvalidCoins, "fee is not a subset of required fees; got %s, required: %s", feeTx.GetFee().String(), feeRequired.String()) - } - - // Sort fee tx's coins, zero coins in feeCoins are already removed - feeCoins := feeTx.GetFee().Sort() - gas := feeTx.GetGas() - msgs := feeTx.GetMsgs() - - // split feeRequired into zero and non-zero coins(nonZeroCoinFeesReq, zeroCoinFeesDenomReq), split feeCoins according to - // nonZeroCoinFeesReq, zeroCoinFeesDenomReq, - // so that feeCoins can be checked separately against them. - nonZeroCoinFeesReq, zeroCoinFeesDenomReq := getNonZeroFees(feeRequired) - - // feeCoinsNonZeroDenom contains non-zero denominations from the feeRequired - // feeCoinsNonZeroDenom is used to check if the fees meets the requirement imposed by nonZeroCoinFeesReq - // when feeCoins does not contain zero coins' denoms in feeRequired - feeCoinsNonZeroDenom, feeCoinsZeroDenom := splitCoinsByDenoms(feeCoins, zeroCoinFeesDenomReq) - - // Check that the fees are in expected denominations. - // according to splitCoinsByDenoms(), feeCoinsZeroDenom must be in denom subset of zeroCoinFeesDenomReq. - // check if feeCoinsNonZeroDenom is a subset of nonZeroCoinFeesReq. - // special case: if feeCoinsNonZeroDenom=[], DenomsSubsetOf returns true - // special case: if feeCoinsNonZeroDenom is not empty, but nonZeroCoinFeesReq empty, return false - if !feeCoinsNonZeroDenom.DenomsSubsetOf(nonZeroCoinFeesReq) { - return ctx, errorsmod.Wrapf(atomoneerrors.ErrInsufficientFee, "fee is not a subset of required fees; got %s, required: %s", feeCoins.String(), feeRequired.String()) - } - - // If the feeCoins pass the denoms check, check they are bypass-msg types. - // - // Bypass min fee requires: - // - the tx contains only message types that can bypass the minimum fee, - // see BypassMinFeeMsgTypes; - // - the total gas limit per message does not exceed MaxTotalBypassMinFeeMsgGasUsage, - // i.e., totalGas <= MaxTotalBypassMinFeeMsgGasUsage - // Otherwise, minimum fees and global fees are checked to prevent spam. - maxTotalBypassMinFeeMsgGasUsage := mfd.GetMaxTotalBypassMinFeeMsgGasUsage(ctx) - doesNotExceedMaxGasUsage := gas <= maxTotalBypassMinFeeMsgGasUsage - allBypassMsgs := mfd.ContainsOnlyBypassMinFeeMsgs(ctx, msgs) - allowedToBypassMinFee := allBypassMsgs && doesNotExceedMaxGasUsage - - if allowedToBypassMinFee { - return next(ctx, tx, simulate) - } - - // if the msg does not satisfy bypass condition and the feeCoins denoms are subset of feeRequired, - // check the feeCoins amount against feeRequired - - // when feeCoins=[] - // special case: and there is zero coin in fee requirement, pass, - // otherwise, err - if len(feeCoins) == 0 { - if len(zeroCoinFeesDenomReq) != 0 { - return next(ctx, tx, simulate) - } - return ctx, errorsmod.Wrapf(atomoneerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins.String(), feeRequired.String()) - } - - // when feeCoins != [] - // special case: if TX has at least one of the zeroCoinFeesDenomReq, then it should pass - if len(feeCoinsZeroDenom) > 0 { - return next(ctx, tx, simulate) - } - - // After all the checks, the tx is confirmed: - // feeCoins denoms subset off feeRequired - // Not bypass - // feeCoins != [] - // Not contain zeroCoinFeesDenomReq's denoms - // - // check if the feeCoins's feeCoinsNonZeroDenom part has coins' amount higher/equal to nonZeroCoinFeesReq - if !feeCoinsNonZeroDenom.IsAnyGTE(nonZeroCoinFeesReq) { - errMsg := fmt.Sprintf("Insufficient fees; got: %s required: %s", feeCoins.String(), feeRequired.String()) - if allBypassMsgs && !doesNotExceedMaxGasUsage { - errMsg = fmt.Sprintf("Insufficient fees; bypass-min-fee-msg-types with gas consumption %v exceeds the maximum allowed gas value of %v.", gas, maxTotalBypassMinFeeMsgGasUsage) - } - - return ctx, errorsmod.Wrap(atomoneerrors.ErrInsufficientFee, errMsg) - } - - return next(ctx, tx, simulate) -} - -// GetTxFeeRequired returns the required fees for the given FeeTx. -// In case the FeeTx's mode is CheckTx, it returns the combined requirements -// of local min gas prices and global fees. Otherwise, in DeliverTx, it returns the global fee. -func (mfd FeeDecorator) GetTxFeeRequired(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coins, error) { - // Get required global fee min gas prices - // Note that it should never be empty since its default value is set to coin={"StakingBondDenom", 0} - globalFees, err := mfd.GetGlobalFee(ctx, tx) - if err != nil { - return sdk.Coins{}, err - } - - // In DeliverTx, the global fee min gas prices are the only tx fee requirements. - if !ctx.IsCheckTx() { - return globalFees, nil - } - - // In CheckTx mode, the local and global fee min gas prices are combined - // to form the tx fee requirements - - // Get local minimum-gas-prices - localFees := GetMinGasPrice(ctx, int64(tx.GetGas())) - c, err := CombinedFeeRequirement(globalFees, localFees) - - // Return combined fee requirements - return c, err -} - -// GetGlobalFee returns the global fees for a given fee tx's gas -// (might also return 0denom if globalMinGasPrice is 0) -// sorted in ascending order. -// Note that ParamStoreKeyMinGasPrices type requires coins sorted. -func (mfd FeeDecorator) GetGlobalFee(ctx sdk.Context, feeTx sdk.FeeTx) (sdk.Coins, error) { - var ( - globalMinGasPrices sdk.DecCoins - err error - ) - - if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyMinGasPrices) { - mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyMinGasPrices, &globalMinGasPrices) - } - // global fee is empty set, set global fee to 0uatom - if len(globalMinGasPrices) == 0 { - globalMinGasPrices, err = mfd.DefaultZeroGlobalFee(ctx) - if err != nil { - return sdk.Coins{}, err - } - } - requiredGlobalFees := make(sdk.Coins, len(globalMinGasPrices)) - // Determine the required fees by multiplying each required minimum gas - // price by the gas limit, where fee = ceil(minGasPrice * gasLimit). - glDec := sdk.NewDec(int64(feeTx.GetGas())) - for i, gp := range globalMinGasPrices { - fee := gp.Amount.Mul(glDec) - requiredGlobalFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) - } - - return requiredGlobalFees.Sort(), nil -} - -// DefaultZeroGlobalFee returns a zero coin with the staking module bond denom -func (mfd FeeDecorator) DefaultZeroGlobalFee(ctx sdk.Context) ([]sdk.DecCoin, error) { - bondDenom := mfd.StakingKeeper.BondDenom(ctx) - if bondDenom == "" { - return nil, errors.New("empty staking bond denomination") - } - - return []sdk.DecCoin{sdk.NewDecCoinFromDec(bondDenom, sdk.NewDec(0))}, nil -} - -func (mfd FeeDecorator) ContainsOnlyBypassMinFeeMsgs(ctx sdk.Context, msgs []sdk.Msg) bool { - bypassMsgTypes := mfd.GetBypassMsgTypes(ctx) - - for _, msg := range msgs { - if tmstrings.StringInSlice(sdk.MsgTypeURL(msg), bypassMsgTypes) { - continue - } - return false - } - - return true -} - -func (mfd FeeDecorator) GetBypassMsgTypes(ctx sdk.Context) (res []string) { - if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { - mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &res) - } - - return -} - -func (mfd FeeDecorator) GetMaxTotalBypassMinFeeMsgGasUsage(ctx sdk.Context) (res uint64) { - if mfd.GlobalMinFeeParamSource.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { - mfd.GlobalMinFeeParamSource.Get(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &res) - } - - return -} - -// GetMinGasPrice returns a nodes's local minimum gas prices -// fees given a gas limit -func GetMinGasPrice(ctx sdk.Context, gasLimit int64) sdk.Coins { - minGasPrices := ctx.MinGasPrices() - // special case: if minGasPrices=[], requiredFees=[] - if minGasPrices.IsZero() { - return sdk.Coins{} - } - - requiredFees := make(sdk.Coins, len(minGasPrices)) - // Determine the required fees by multiplying each required minimum gas - // price by the gas limit, where fee = ceil(minGasPrice * gasLimit). - glDec := sdk.NewDec(gasLimit) - for i, gp := range minGasPrices { - fee := gp.Amount.Mul(glDec) - requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) - } - - return requiredFees.Sort() -} diff --git a/x/globalfee/ante/fee_utils.go b/x/globalfee/ante/fee_utils.go deleted file mode 100644 index b0eabb86..00000000 --- a/x/globalfee/ante/fee_utils.go +++ /dev/null @@ -1,116 +0,0 @@ -package ante - -import ( - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - - atomoneerrors "github.com/atomone-hub/atomone/types/errors" -) - -// ContainZeroCoins returns true if the given coins are empty or contain zero coins, -// Note that the coins denoms must be validated, see sdk.ValidateDenom -func ContainZeroCoins(coins sdk.Coins) bool { - if len(coins) == 0 { - return true - } - for _, coin := range coins { - if coin.IsZero() { - return true - } - } - - return false -} - -// CombinedFeeRequirement returns the global fee and min_gas_price combined and sorted. -// Both globalFees and minGasPrices must be valid, but CombinedFeeRequirement -// does not validate them, so it may return 0denom. -// if globalfee is empty, CombinedFeeRequirement return sdk.Coins{} -func CombinedFeeRequirement(globalFees, minGasPrices sdk.Coins) (sdk.Coins, error) { - // global fees should never be empty - // since it has a default value using the staking module's bond denom - if len(globalFees) == 0 { - return sdk.Coins{}, errorsmod.Wrapf(atomoneerrors.ErrNotFound, "global fee cannot be empty") - } - - // empty min_gas_price - if len(minGasPrices) == 0 { - return globalFees, nil - } - - // if min_gas_price denom is in globalfee, and the amount is higher than globalfee, add min_gas_price to allFees - var allFees sdk.Coins - for _, fee := range globalFees { - // min_gas_price denom in global fee - ok, c := Find(minGasPrices, fee.Denom) - if ok && c.Amount.GT(fee.Amount) { - allFees = append(allFees, c) - } else { - allFees = append(allFees, fee) - } - } - - return allFees.Sort(), nil -} - -// Find replaces the functionality of Coins.Find from SDK v0.46.x -func Find(coins sdk.Coins, denom string) (bool, sdk.Coin) { - switch len(coins) { - case 0: - return false, sdk.Coin{} - - case 1: - coin := coins[0] - if coin.Denom == denom { - return true, coin - } - return false, sdk.Coin{} - - default: - midIdx := len(coins) / 2 // 2:1, 3:1, 4:2 - coin := coins[midIdx] - switch { - case denom < coin.Denom: - return Find(coins[:midIdx], denom) - case denom == coin.Denom: - return true, coin - default: - return Find(coins[midIdx+1:], denom) - } - } -} - -// splitCoinsByDenoms returns the given coins split in two whether -// their demon is or isn't found in the given denom map. -func splitCoinsByDenoms(feeCoins sdk.Coins, denomMap map[string]struct{}) (sdk.Coins, sdk.Coins) { - feeCoinsNonZeroDenom, feeCoinsZeroDenom := sdk.Coins{}, sdk.Coins{} - - for _, fc := range feeCoins { - _, found := denomMap[fc.Denom] - if found { - feeCoinsZeroDenom = append(feeCoinsZeroDenom, fc) - } else { - feeCoinsNonZeroDenom = append(feeCoinsNonZeroDenom, fc) - } - } - - return feeCoinsNonZeroDenom.Sort(), feeCoinsZeroDenom.Sort() -} - -// getNonZeroFees returns the given fees nonzero coins -// and a map storing the zero coins's denoms -func getNonZeroFees(fees sdk.Coins) (sdk.Coins, map[string]struct{}) { - requiredFeesNonZero := sdk.Coins{} - requiredFeesZeroDenom := map[string]struct{}{} - - for _, gf := range fees { - if gf.IsZero() { - requiredFeesZeroDenom[gf.Denom] = struct{}{} - } else { - requiredFeesNonZero = append(requiredFeesNonZero, gf) - } - } - - return requiredFeesNonZero.Sort(), requiredFeesZeroDenom -} diff --git a/x/globalfee/ante/fee_utils_test.go b/x/globalfee/ante/fee_utils_test.go deleted file mode 100644 index 7bf9e914..00000000 --- a/x/globalfee/ante/fee_utils_test.go +++ /dev/null @@ -1,299 +0,0 @@ -package ante - -import ( - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestContainZeroCoins(t *testing.T) { - zeroCoin1 := sdk.NewCoin("photon", sdk.ZeroInt()) - zeroCoin2 := sdk.NewCoin("stake", sdk.ZeroInt()) - coin1 := sdk.NewCoin("photon", sdk.NewInt(1)) - coin2 := sdk.NewCoin("stake", sdk.NewInt(2)) - coin3 := sdk.NewCoin("quark", sdk.NewInt(3)) - // coins must be valid !!! - coinsEmpty := sdk.Coins{} - coinsNonEmpty := sdk.Coins{coin1, coin2} - coinsCointainZero := sdk.Coins{coin1, zeroCoin2} - coinsCointainTwoZero := sdk.Coins{zeroCoin1, zeroCoin2, coin3} - coinsAllZero := sdk.Coins{zeroCoin1, zeroCoin2} - - tests := []struct { - c sdk.Coins - ok bool - }{ - { - coinsEmpty, - true, - }, - { - coinsNonEmpty, - false, - }, - { - coinsCointainZero, - true, - }, - { - coinsCointainTwoZero, - true, - }, - { - coinsAllZero, - true, - }, - } - - for _, test := range tests { - ok := ContainZeroCoins(test.c) - require.Equal(t, test.ok, ok) - } -} - -// Note that in a real Gaia deployment all zero coins can be removed from minGasPrice. -// This sanitizing happens when the minGasPrice is set into the context. -// (see baseapp.SetMinGasPrices in gaia/cmd/root.go line 221) -func TestCombinedFeeRequirement(t *testing.T) { - zeroCoin1 := sdk.NewCoin("photon", sdk.ZeroInt()) - zeroCoin2 := sdk.NewCoin("stake", sdk.ZeroInt()) - zeroCoin3 := sdk.NewCoin("quark", sdk.ZeroInt()) - coin1 := sdk.NewCoin("photon", sdk.NewInt(1)) - coin2 := sdk.NewCoin("stake", sdk.NewInt(2)) - coin1High := sdk.NewCoin("photon", sdk.NewInt(10)) - coin2High := sdk.NewCoin("stake", sdk.NewInt(20)) - coinNewDenom1 := sdk.NewCoin("Newphoton", sdk.NewInt(1)) - coinNewDenom2 := sdk.NewCoin("Newstake", sdk.NewInt(1)) - // coins must be valid !!! and sorted!!! - coinsEmpty := sdk.Coins{} - coinsNonEmpty := sdk.Coins{coin1, coin2}.Sort() - coinsNonEmptyHigh := sdk.Coins{coin1High, coin2High}.Sort() - coinsNonEmptyOneHigh := sdk.Coins{coin1High, coin2}.Sort() - coinsNewDenom := sdk.Coins{coinNewDenom1, coinNewDenom2}.Sort() - coinsNewOldDenom := sdk.Coins{coin1, coinNewDenom1}.Sort() - coinsNewOldDenomHigh := sdk.Coins{coin1High, coinNewDenom1}.Sort() - coinsCointainZero := sdk.Coins{coin1, zeroCoin2}.Sort() - coinsCointainZeroNewDenom := sdk.Coins{coin1, zeroCoin3}.Sort() - coinsAllZero := sdk.Coins{zeroCoin1, zeroCoin2}.Sort() - tests := map[string]struct { - cGlobal sdk.Coins - c sdk.Coins - combined sdk.Coins - }{ - "global fee invalid, return combined fee empty and non-nil error": { - cGlobal: coinsEmpty, - c: coinsEmpty, - combined: coinsEmpty, - }, - "global fee nonempty, min fee empty, combined fee = global fee": { - cGlobal: coinsNonEmpty, - c: coinsNonEmpty, - combined: coinsNonEmpty, - }, - "global fee and min fee have overlapping denom, min fees amounts are all higher": { - cGlobal: coinsNonEmpty, - c: coinsNonEmptyHigh, - combined: coinsNonEmptyHigh, - }, - "global fee and min fee have overlapping denom, one of min fees amounts is higher": { - cGlobal: coinsNonEmpty, - c: coinsNonEmptyOneHigh, - combined: coinsNonEmptyOneHigh, - }, - "global fee and min fee have no overlapping denom, combined fee = global fee": { - cGlobal: coinsNonEmpty, - c: coinsNewDenom, - combined: coinsNonEmpty, - }, - "global fees and min fees have partial overlapping denom, min fee amount <= global fee amount, combined fees = global fees": { - cGlobal: coinsNonEmpty, - c: coinsNewOldDenom, - combined: coinsNonEmpty, - }, - "global fees and min fees have partial overlapping denom, one min fee amount > global fee amount, combined fee = overlapping highest": { - cGlobal: coinsNonEmpty, - c: coinsNewOldDenomHigh, - combined: sdk.Coins{coin1High, coin2}, - }, - "global fees have zero fees, min fees have overlapping non-zero fees, combined fees = overlapping highest": { - cGlobal: coinsCointainZero, - c: coinsNonEmpty, - combined: sdk.Coins{coin1, coin2}, - }, - "global fees have zero fees, min fees have overlapping zero fees": { - cGlobal: coinsCointainZero, - c: coinsCointainZero, - combined: coinsCointainZero, - }, - "global fees have zero fees, min fees have non-overlapping zero fees": { - cGlobal: coinsCointainZero, - c: coinsCointainZeroNewDenom, - combined: coinsCointainZero, - }, - "global fees are all zero fees, min fees have overlapping zero fees": { - cGlobal: coinsAllZero, - c: coinsAllZero, - combined: coinsAllZero, - }, - "global fees are all zero fees, min fees have overlapping non-zero fees, combined fee = overlapping highest": { - cGlobal: coinsAllZero, - c: coinsCointainZeroNewDenom, - combined: sdk.Coins{coin1, zeroCoin2}, - }, - "global fees are all zero fees, fees have one overlapping non-zero fee": { - cGlobal: coinsAllZero, - c: coinsCointainZero, - combined: coinsCointainZero, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - allFees, err := CombinedFeeRequirement(test.cGlobal, test.c) - if len(test.cGlobal) == 0 { - require.Error(t, err) - } else { - require.NoError(t, err) - } - require.Equal(t, test.combined, allFees) - }) - } -} - -func TestSplitCoinsByDenoms(t *testing.T) { - zeroGlobalFeesDenom0 := map[string]struct{}{} - zeroGlobalFeesDenom1 := map[string]struct{}{ - "uatom": {}, - "photon": {}, - } - zeroGlobalFeesDenom2 := map[string]struct{}{ - "uatom": {}, - } - zeroGlobalFeesDenom3 := map[string]struct{}{ - "stake": {}, - } - - photon := sdk.NewCoin("photon", sdk.OneInt()) - uatom := sdk.NewCoin("uatom", sdk.OneInt()) - feeCoins := sdk.NewCoins(photon, uatom) - - tests := map[string]struct { - feeCoins sdk.Coins - zeroGlobalFeesDenom map[string]struct{} - expectedNonZeroCoins sdk.Coins - expectedZeroCoins sdk.Coins - }{ - "no zero coins in global fees": { - feeCoins: feeCoins, - zeroGlobalFeesDenom: zeroGlobalFeesDenom0, - expectedNonZeroCoins: feeCoins, - expectedZeroCoins: sdk.Coins{}, - }, - "no split of fee coins": { - feeCoins: feeCoins, - zeroGlobalFeesDenom: zeroGlobalFeesDenom3, - expectedNonZeroCoins: feeCoins, - expectedZeroCoins: sdk.Coins{}, - }, - "split the fee coins": { - feeCoins: feeCoins, - zeroGlobalFeesDenom: zeroGlobalFeesDenom2, - expectedNonZeroCoins: sdk.NewCoins(photon), - expectedZeroCoins: sdk.NewCoins(uatom), - }, - "remove all of the fee coins": { - feeCoins: feeCoins, - zeroGlobalFeesDenom: zeroGlobalFeesDenom1, - expectedNonZeroCoins: sdk.Coins{}, - expectedZeroCoins: feeCoins, - }, - "fee coins are empty": { - feeCoins: sdk.Coins{}, - zeroGlobalFeesDenom: zeroGlobalFeesDenom1, - expectedNonZeroCoins: sdk.Coins{}, - expectedZeroCoins: sdk.Coins{}, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - feeCoinsNoZeroDenoms, feeCoinsZeroDenoms := splitCoinsByDenoms(test.feeCoins, test.zeroGlobalFeesDenom) - require.Equal(t, test.expectedNonZeroCoins, feeCoinsNoZeroDenoms) - require.Equal(t, test.expectedZeroCoins, feeCoinsZeroDenoms) - }) - } -} - -func TestSplitGlobalFees(t *testing.T) { - photon0 := sdk.NewCoin("photon", sdk.ZeroInt()) - uatom0 := sdk.NewCoin("uatom", sdk.ZeroInt()) - photon1 := sdk.NewCoin("photon", sdk.OneInt()) - uatom1 := sdk.NewCoin("uatom", sdk.OneInt()) - - globalFeesEmpty := sdk.Coins{} - globalFees := sdk.Coins{photon1, uatom1}.Sort() - globalFeesZeroCoins := sdk.Coins{photon0, uatom0}.Sort() - globalFeesMix := sdk.Coins{photon0, uatom1}.Sort() - - tests := map[string]struct { - globalfees sdk.Coins - zeroGlobalFeesDenom map[string]struct{} - globalfeesNonZero sdk.Coins - }{ - "empty global fees": { - globalfees: globalFeesEmpty, - zeroGlobalFeesDenom: map[string]struct{}{}, - globalfeesNonZero: sdk.Coins{}, - }, - "nonzero coins global fees": { - globalfees: globalFees, - zeroGlobalFeesDenom: map[string]struct{}{}, - globalfeesNonZero: globalFees, - }, - "zero coins global fees": { - globalfees: globalFeesZeroCoins, - zeroGlobalFeesDenom: map[string]struct{}{ - "photon": {}, - "uatom": {}, - }, - globalfeesNonZero: sdk.Coins{}, - }, - "mix zero, nonzero coins global fees": { - globalfees: globalFeesMix, - zeroGlobalFeesDenom: map[string]struct{}{ - "photon": {}, - }, - globalfeesNonZero: sdk.NewCoins(uatom1), - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - nonZeroCoins, zeroCoinsMap := getNonZeroFees(test.globalfees) - require.True(t, nonZeroCoins.IsEqual(test.globalfeesNonZero)) - require.True(t, equalMap(zeroCoinsMap, test.zeroGlobalFeesDenom)) - }) - } -} - -func equalMap(a, b map[string]struct{}) bool { - if len(a) != len(b) { - return false - } - if len(a) == 0 && len(b) == 0 { - return true - } - if len(a) == 0 { - return false - } - - for k := range a { - if _, ok := b[k]; !ok { - return false - } - } - - return true -} diff --git a/x/globalfee/client/cli/query.go b/x/globalfee/client/cli/query.go deleted file mode 100644 index 9ba8a8a3..00000000 --- a/x/globalfee/client/cli/query.go +++ /dev/null @@ -1,48 +0,0 @@ -package cli - -import ( - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" - - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -func GetQueryCmd() *cobra.Command { - queryCmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the global fee module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - queryCmd.AddCommand( - GetCmdShowGlobalFeeParams(), - ) - return queryCmd -} - -func GetCmdShowGlobalFeeParams() *cobra.Command { - cmd := &cobra.Command{ - Use: "params", - Short: "Show globalfee params", - Long: "Show globalfee requirement: minimum_gas_prices, bypass_min_fee_msg_types, max_total_bypass_minFee_msg_gas_usage", - Args: cobra.ExactArgs(0), - 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/globalfee/genesis_test.go b/x/globalfee/genesis_test.go deleted file mode 100644 index d8cf166a..00000000 --- a/x/globalfee/genesis_test.go +++ /dev/null @@ -1,164 +0,0 @@ -package globalfee - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - dbm "github.com/cometbft/cometbft-db" - "github.com/cometbft/cometbft/libs/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - - gaiaparams "github.com/atomone-hub/atomone/app/params" - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -func TestDefaultGenesis(t *testing.T) { - encCfg := gaiaparams.MakeEncodingConfig() - gotJSON := AppModuleBasic{}.DefaultGenesis(encCfg.Marshaler) - assert.JSONEq(t, - `{"params":{"minimum_gas_prices":[],"bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgAcknowledgement","/ibc.core.client.v1.MsgUpdateClient","/ibc.core.channel.v1.MsgTimeout","/ibc.core.channel.v1.MsgTimeoutOnClose"], "max_total_bypass_min_fee_msg_gas_usage":"1000000"}}`, - string(gotJSON), string(gotJSON)) -} - -func TestValidateGenesis(t *testing.T) { - encCfg := gaiaparams.MakeEncodingConfig() - specs := map[string]struct { - src string - expErr bool - }{ - "all good": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, - expErr: false, - }, - "empty minimum": { - src: `{"params":{"minimum_gas_prices":[], "bypass_min_fee_msg_types":[]}}`, - expErr: false, - }, - "minimum and bypass not set": { - src: `{"params":{}}`, - expErr: false, - }, - "minimum not set": { - src: `{"params":{"bypass_min_fee_msg_types":[]}}`, - expErr: false, - }, - "bypass not set": { - src: `{"params":{"minimum_gas_prices":[]}}`, - expErr: false, - }, - "zero amount allowed": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"0"}]}}`, - expErr: false, - }, - "duplicate denoms not allowed": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, - expErr: true, - }, - "negative amounts not allowed": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"-1"}]}}`, - expErr: true, - }, - "denom must be sorted": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ZLX", "amount":"1"},{"denom":"ALX", "amount":"2"}]}}`, - expErr: true, - }, - "empty bypass msg types not allowed": { - src: `{"params":{"bypass_min_fee_msg_types":[""]}}`, - expErr: true, - }, - "sorted denoms is allowed": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"},{"denom":"ZLX", "amount":"2"}]}}`, - expErr: false, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - gotErr := AppModuleBasic{}.ValidateGenesis(encCfg.Marshaler, nil, []byte(spec.src)) - if spec.expErr { - require.Error(t, gotErr) - return - } - require.NoError(t, gotErr) - }) - } -} - -func TestInitExportGenesis(t *testing.T) { - specs := map[string]struct { - src string - exp types.GenesisState - }{ - "single fee": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket"]}}`, - exp: types.GenesisState{ - Params: types.Params{ - MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1))), - BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket"}, - }, - }, - }, - "multiple fee options": { - src: `{"params":{"minimum_gas_prices":[{"denom":"ALX", "amount":"1"}, {"denom":"BLX", "amount":"0.001"}], "bypass_min_fee_msg_types":["/ibc.core.channel.v1.MsgRecvPacket","/ibc.core.channel.v1.MsgTimeoutOnClose"]}}`, - exp: types.GenesisState{ - Params: types.Params{ - MinimumGasPrices: sdk.NewDecCoins(sdk.NewDecCoin("ALX", sdk.NewInt(1)), - sdk.NewDecCoinFromDec("BLX", sdk.NewDecWithPrec(1, 3))), - BypassMinFeeMsgTypes: []string{"/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgTimeoutOnClose"}, - }, - }, - }, - "no fee set": { - src: `{"params":{}}`, - exp: types.GenesisState{ - Params: types.Params{ - MinimumGasPrices: sdk.DecCoins{}, - BypassMinFeeMsgTypes: []string{}, - }, - }, - }, - } - for name, spec := range specs { - t.Run(name, func(t *testing.T) { - ctx, encCfg, subspace := setupTestStore(t) - m := NewAppModule(subspace) - m.InitGenesis(ctx, encCfg.Marshaler, []byte(spec.src)) - gotJSON := m.ExportGenesis(ctx, encCfg.Marshaler) - var got types.GenesisState - require.NoError(t, encCfg.Marshaler.UnmarshalJSON(gotJSON, &got)) - assert.Equal(t, spec.exp, got, string(gotJSON)) - }) - } -} - -func setupTestStore(t *testing.T) (sdk.Context, gaiaparams.EncodingConfig, paramstypes.Subspace) { - t.Helper() - db := dbm.NewMemDB() - ms := store.NewCommitMultiStore(db) - encCfg := gaiaparams.MakeEncodingConfig() - keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) - tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) - ms.MountStoreWithDB(keyParams, storetypes.StoreTypeIAVL, db) - ms.MountStoreWithDB(tkeyParams, storetypes.StoreTypeTransient, db) - require.NoError(t, ms.LoadLatestVersion()) - - ctx := sdk.NewContext(ms, tmproto.Header{ - Height: 1234567, - Time: time.Date(2020, time.April, 22, 12, 0, 0, 0, time.UTC), - }, false, log.NewNopLogger()) - - subspace := paramstypes.NewSubspace(encCfg.Marshaler, - encCfg.Amino, - keyParams, - tkeyParams, - paramstypes.ModuleName, - ) - return ctx, encCfg, subspace -} diff --git a/x/globalfee/keeper/migrations.go b/x/globalfee/keeper/migrations.go deleted file mode 100644 index 61ece2ef..00000000 --- a/x/globalfee/keeper/migrations.go +++ /dev/null @@ -1,23 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - v2 "github.com/atomone-hub/atomone/x/globalfee/migrations/v2" -) - -// Migrator is a struct for handling in-place store migrations. -type Migrator struct { - globalfeeSubspace paramtypes.Subspace -} - -// NewMigrator returns a new Migrator. -func NewMigrator(globalfeeSubspace paramtypes.Subspace) Migrator { - return Migrator{globalfeeSubspace: globalfeeSubspace} -} - -// Migrate1to2 migrates from version 1 to 2. -func (m Migrator) Migrate1to2(ctx sdk.Context) error { - return v2.MigrateStore(ctx, m.globalfeeSubspace) -} diff --git a/x/globalfee/migrations/v2/migration.go b/x/globalfee/migrations/v2/migration.go deleted file mode 100644 index 8318eb60..00000000 --- a/x/globalfee/migrations/v2/migration.go +++ /dev/null @@ -1,38 +0,0 @@ -package v2 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -// MigrateStore performs in-place params migrations of -// BypassMinFeeMsgTypes and MaxTotalBypassMinFeeMsgGasUsage -// from app.toml to globalfee params. -// The migration includes: -// Add bypass-min-fee-msg-types params that are set -// ["/ibc.core.channel.v1.MsgRecvPacket", -// "/ibc.core.channel.v1.MsgAcknowledgement", -// "/ibc.core.client.v1.MsgUpdateClient", -// "/ibc.core.channel.v1.MsgTimeout", -// "/ibc.core.channel.v1.MsgTimeoutOnClose"] as default and -// add MaxTotalBypassMinFeeMsgGasUsage that is set 1_000_000 as default. -func MigrateStore(ctx sdk.Context, globalfeeSubspace paramtypes.Subspace) error { - var oldGlobalMinGasPrices sdk.DecCoins - globalfeeSubspace.Get(ctx, types.ParamStoreKeyMinGasPrices, &oldGlobalMinGasPrices) - defaultParams := types.DefaultParams() - params := types.Params{ - MinimumGasPrices: oldGlobalMinGasPrices, - BypassMinFeeMsgTypes: defaultParams.BypassMinFeeMsgTypes, - MaxTotalBypassMinFeeMsgGasUsage: defaultParams.MaxTotalBypassMinFeeMsgGasUsage, - } - - if !globalfeeSubspace.HasKeyTable() { - globalfeeSubspace = globalfeeSubspace.WithKeyTable(types.ParamKeyTable()) - } - - globalfeeSubspace.SetParamSet(ctx, ¶ms) - - return nil -} diff --git a/x/globalfee/migrations/v2/v2_test/migration_test.go b/x/globalfee/migrations/v2/v2_test/migration_test.go deleted file mode 100644 index 7f121fe5..00000000 --- a/x/globalfee/migrations/v2/v2_test/migration_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package v2_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - cmdb "github.com/cometbft/cometbft-db" - "github.com/cometbft/cometbft/libs/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/store" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - v2 "github.com/atomone-hub/atomone/x/globalfee/migrations/v2" - globalfeetypes "github.com/atomone-hub/atomone/x/globalfee/types" -) - -func TestMigrateStore(t *testing.T) { - db := cmdb.NewMemDB() - stateStore := store.NewCommitMultiStore(db) - - storeKey := sdk.NewKVStoreKey(paramtypes.StoreKey) - memStoreKey := storetypes.NewMemoryStoreKey("mem_key") - - stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) - stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) - - registry := codectypes.NewInterfaceRegistry() - cdc := codec.NewProtoCodec(registry) - ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - - require.NoError(t, stateStore.LoadLatestVersion()) - - // Create new empty subspace - newSubspace := paramtypes.NewSubspace(cdc, - codec.NewLegacyAmino(), - storeKey, - memStoreKey, - paramtypes.ModuleName, - ) - - // register the subspace with the v11 paramKeyTable - newSubspace = newSubspace.WithKeyTable(globalfeetypes.ParamKeyTable()) - - // check MinGasPrices isn't set - _, ok := getMinGasPrice(newSubspace, ctx) - require.Equal(t, ok, false) - - // set a minGasPrice different that default value - minGasPrices := sdk.NewDecCoins(sdk.NewDecCoin("uatom", sdk.OneInt())) - newSubspace.Set(ctx, globalfeetypes.ParamStoreKeyMinGasPrices, minGasPrices) - require.False(t, minGasPrices.IsEqual(globalfeetypes.DefaultMinGasPrices)) - - // check that the new parameters aren't set - _, ok = getBypassMsgTypes(newSubspace, ctx) - require.Equal(t, ok, false) - _, ok = getMaxTotalBypassMinFeeMsgGasUsage(newSubspace, ctx) - require.Equal(t, ok, false) - - // run global fee migration - err := v2.MigrateStore(ctx, newSubspace) - require.NoError(t, err) - - newMinGasPrices, _ := getMinGasPrice(newSubspace, ctx) - bypassMsgTypes, _ := getBypassMsgTypes(newSubspace, ctx) - maxGas, _ := getMaxTotalBypassMinFeeMsgGasUsage(newSubspace, ctx) - - require.Equal(t, bypassMsgTypes, globalfeetypes.DefaultBypassMinFeeMsgTypes) - require.Equal(t, maxGas, globalfeetypes.DefaultmaxTotalBypassMinFeeMsgGasUsage) - require.Equal(t, minGasPrices, newMinGasPrices) -} - -func getBypassMsgTypes(globalfeeSubspace paramtypes.Subspace, ctx sdk.Context) ([]string, bool) { - bypassMsgs := []string{} - if globalfeeSubspace.Has(ctx, globalfeetypes.ParamStoreKeyBypassMinFeeMsgTypes) { - globalfeeSubspace.Get(ctx, globalfeetypes.ParamStoreKeyBypassMinFeeMsgTypes, &bypassMsgs) - } else { - return bypassMsgs, false - } - - return bypassMsgs, true -} - -func getMaxTotalBypassMinFeeMsgGasUsage(globalfeeSubspace paramtypes.Subspace, ctx sdk.Context) (uint64, bool) { - var maxTotalBypassMinFeeMsgGasUsage uint64 - if globalfeeSubspace.Has(ctx, globalfeetypes.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { - globalfeeSubspace.Get(ctx, globalfeetypes.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &maxTotalBypassMinFeeMsgGasUsage) - } else { - return maxTotalBypassMinFeeMsgGasUsage, false - } - - return maxTotalBypassMinFeeMsgGasUsage, true -} - -func getMinGasPrice(globalfeeSubspace paramtypes.Subspace, ctx sdk.Context) (sdk.DecCoins, bool) { - var globalMinGasPrices sdk.DecCoins - if globalfeeSubspace.Has(ctx, globalfeetypes.ParamStoreKeyMinGasPrices) { - globalfeeSubspace.Get(ctx, globalfeetypes.ParamStoreKeyMinGasPrices, &globalMinGasPrices) - } else { - return globalMinGasPrices, false - } - - return globalMinGasPrices, true -} diff --git a/x/globalfee/module.go b/x/globalfee/module.go deleted file mode 100644 index 0f9843c0..00000000 --- a/x/globalfee/module.go +++ /dev/null @@ -1,137 +0,0 @@ -package globalfee - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - - abci "github.com/cometbft/cometbft/abci/types" - - errorsmod "cosmossdk.io/errors" - - "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" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - - "github.com/atomone-hub/atomone/x/globalfee/client/cli" - "github.com/atomone-hub/atomone/x/globalfee/keeper" - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -var ( - _ module.AppModuleBasic = AppModuleBasic{} - _ module.AppModuleGenesis = AppModule{} - _ module.AppModule = AppModule{} -) - -// AppModuleBasic defines the basic application module used by the wasm module. -type AppModuleBasic struct{} - -func (a AppModuleBasic) Name() string { - return types.ModuleName -} - -func (a AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(&types.GenesisState{ - Params: types.DefaultParams(), - }) -} - -func (a AppModuleBasic) ValidateGenesis(marshaler codec.JSONCodec, _ client.TxEncodingConfig, message json.RawMessage) error { - var data types.GenesisState - err := marshaler.UnmarshalJSON(message, &data) - if err != nil { - return err - } - if err := data.Params.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "params") - } - return nil -} - -func (a AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) { -} - -func (a AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) { -} - -func (a AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - if err != nil { - // same behavior as in cosmos-sdk - panic(err) - } -} - -func (a AppModuleBasic) GetTxCmd() *cobra.Command { - return nil -} - -func (a AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - -func (a AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) { -} - -type AppModule struct { - AppModuleBasic - paramSpace paramstypes.Subspace -} - -// NewAppModule constructor -func NewAppModule(paramSpace paramstypes.Subspace) *AppModule { - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) - } - - return &AppModule{paramSpace: paramSpace} -} - -func (a AppModule) InitGenesis(ctx sdk.Context, marshaler codec.JSONCodec, message json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState - marshaler.MustUnmarshalJSON(message, &genesisState) - - a.paramSpace.SetParamSet(ctx, &genesisState.Params) - return nil -} - -func (a AppModule) ExportGenesis(ctx sdk.Context, marshaler codec.JSONCodec) json.RawMessage { - var genState types.GenesisState - a.paramSpace.GetParamSet(ctx, &genState.Params) - return marshaler.MustMarshalJSON(&genState) -} - -func (a AppModule) RegisterInvariants(_ sdk.InvariantRegistry) { -} - -func (a AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterQueryServer(cfg.QueryServer(), NewGrpcQuerier(a.paramSpace)) - - m := keeper.NewMigrator(a.paramSpace) - if err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2); err != nil { - panic(fmt.Sprintf("failed to migrate x/globalfee from version 1 to 2: %v", err)) - } -} - -func (a AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) { -} - -func (a AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return nil -} - -// ConsensusVersion is a sequence number for state-breaking change of the -// module. It should be incremented on each consensus-breaking change -// introduced by the module. To avoid wrong/empty versions, the initial version -// should be set to 1. -func (a AppModule) ConsensusVersion() uint64 { - return 2 -} diff --git a/x/globalfee/querier.go b/x/globalfee/querier.go deleted file mode 100644 index 72a53601..00000000 --- a/x/globalfee/querier.go +++ /dev/null @@ -1,52 +0,0 @@ -package globalfee - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/atomone-hub/atomone/x/globalfee/types" -) - -var _ types.QueryServer = &GrpcQuerier{} - -// ParamSource is a read only subset of paramtypes.Subspace -type ParamSource interface { - Get(ctx sdk.Context, key []byte, ptr interface{}) - Has(ctx sdk.Context, key []byte) bool -} - -type GrpcQuerier struct { - paramSource ParamSource -} - -func NewGrpcQuerier(paramSource ParamSource) GrpcQuerier { - return GrpcQuerier{paramSource: paramSource} -} - -// MinimumGasPrices return minimum gas prices -func (g GrpcQuerier) Params(stdCtx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { - var minGasPrices sdk.DecCoins - var bypassMinFeeMsgTypes []string - var maxTotalBypassMinFeeMsgGasUsage uint64 - ctx := sdk.UnwrapSDKContext(stdCtx) - - // todo: if return err if not exist? - if g.paramSource.Has(ctx, types.ParamStoreKeyMinGasPrices) { - g.paramSource.Get(ctx, types.ParamStoreKeyMinGasPrices, &minGasPrices) - } - if g.paramSource.Has(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes) { - g.paramSource.Get(ctx, types.ParamStoreKeyBypassMinFeeMsgTypes, &bypassMinFeeMsgTypes) - } - if g.paramSource.Has(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage) { - g.paramSource.Get(ctx, types.ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &maxTotalBypassMinFeeMsgGasUsage) - } - - return &types.QueryParamsResponse{ - Params: types.Params{ - MinimumGasPrices: minGasPrices, - BypassMinFeeMsgTypes: bypassMinFeeMsgTypes, - MaxTotalBypassMinFeeMsgGasUsage: maxTotalBypassMinFeeMsgGasUsage, - }, - }, nil -} diff --git a/x/globalfee/types/genesis.go b/x/globalfee/types/genesis.go deleted file mode 100644 index b0e94687..00000000 --- a/x/globalfee/types/genesis.go +++ /dev/null @@ -1,41 +0,0 @@ -package types - -import ( - "encoding/json" - - errorsmod "cosmossdk.io/errors" - - "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/auth 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 -} - -func ValidateGenesis(data GenesisState) error { - if err := data.Params.ValidateBasic(); err != nil { - return errorsmod.Wrap(err, "globalfee params") - } - - return nil -} diff --git a/x/globalfee/types/genesis.pb.go b/x/globalfee/types/genesis.pb.go deleted file mode 100644 index a5f48d07..00000000 --- a/x/globalfee/types/genesis.pb.go +++ /dev/null @@ -1,622 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: gaia/globalfee/v1beta1/genesis.proto - -package types - -import ( - fmt "fmt" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" - types "github.com/cosmos/cosmos-sdk/types" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/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 - initial state of module -type GenesisState struct { - // Params of this module - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` -} - -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_015b3e8b7a7c65c5, []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{} -} - -// Params defines the set of module parameters. -type Params struct { - // minimum_gas_prices stores the minimum gas price(s) for all TX on the chain. - // When multiple coins are defined then they are accepted alternatively. - // The list must be sorted by denoms asc. No duplicate denoms or zero amount - // values allowed. For more information see - // https://docs.cosmos.network/main/modules/auth#concepts - MinimumGasPrices github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=minimum_gas_prices,json=minimumGasPrices,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"minimum_gas_prices,omitempty" yaml:"minimum_gas_prices"` - // bypass_min_fee_msg_types defines a list of message type urls - // that are free of fee charge. - BypassMinFeeMsgTypes []string `protobuf:"bytes,2,rep,name=bypass_min_fee_msg_types,json=bypassMinFeeMsgTypes,proto3" json:"bypass_min_fee_msg_types,omitempty" yaml:"bypass_min_fee_msg_types"` - // max_total_bypass_min_fee_msg_gas_usage defines the total maximum gas usage - // allowed for a transaction containing only messages of types in bypass_min_fee_msg_types - // to bypass fee charge. - MaxTotalBypassMinFeeMsgGasUsage uint64 `protobuf:"varint,3,opt,name=max_total_bypass_min_fee_msg_gas_usage,json=maxTotalBypassMinFeeMsgGasUsage,proto3" json:"max_total_bypass_min_fee_msg_gas_usage,omitempty"` -} - -func (m *Params) Reset() { *m = Params{} } -func (m *Params) String() string { return proto.CompactTextString(m) } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_015b3e8b7a7c65c5, []int{1} -} -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) GetMinimumGasPrices() github_com_cosmos_cosmos_sdk_types.DecCoins { - if m != nil { - return m.MinimumGasPrices - } - return nil -} - -func (m *Params) GetBypassMinFeeMsgTypes() []string { - if m != nil { - return m.BypassMinFeeMsgTypes - } - return nil -} - -func (m *Params) GetMaxTotalBypassMinFeeMsgGasUsage() uint64 { - if m != nil { - return m.MaxTotalBypassMinFeeMsgGasUsage - } - return 0 -} - -func init() { - proto.RegisterType((*GenesisState)(nil), "gaia.globalfee.v1beta1.GenesisState") - proto.RegisterType((*Params)(nil), "gaia.globalfee.v1beta1.Params") -} - -func init() { - proto.RegisterFile("gaia/globalfee/v1beta1/genesis.proto", fileDescriptor_015b3e8b7a7c65c5) -} - -var fileDescriptor_015b3e8b7a7c65c5 = []byte{ - // 428 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x4d, 0x6e, 0xd3, 0x40, - 0x14, 0xc7, 0x33, 0x04, 0x45, 0xc2, 0x65, 0x51, 0x59, 0x15, 0x32, 0x55, 0x35, 0x8e, 0x2c, 0x84, - 0x2c, 0x01, 0x63, 0xb5, 0xec, 0x58, 0x1a, 0x44, 0xc4, 0xa2, 0x22, 0x0a, 0x65, 0xc3, 0x66, 0x78, - 0x36, 0xd3, 0x61, 0x44, 0xc6, 0x63, 0xe5, 0x4d, 0x50, 0xb2, 0xe4, 0x06, 0x1c, 0x80, 0x13, 0x70, - 0x06, 0x0e, 0xd0, 0x65, 0x97, 0xac, 0x0c, 0x4a, 0x76, 0x5d, 0x72, 0x02, 0x34, 0x1e, 0xd3, 0x52, - 0xa5, 0x59, 0xd9, 0xf2, 0xfb, 0xfd, 0x3f, 0xfc, 0xf4, 0x82, 0x07, 0x12, 0x14, 0x64, 0x72, 0x6a, - 0x0a, 0x98, 0x9e, 0x0a, 0x91, 0x7d, 0x3e, 0x2c, 0x84, 0x85, 0xc3, 0x4c, 0x8a, 0x4a, 0xa0, 0x42, - 0x56, 0xcf, 0x8c, 0x35, 0xe1, 0x3d, 0x47, 0xb1, 0x4b, 0x8a, 0x75, 0xd4, 0xfe, 0x9e, 0x34, 0xd2, - 0xb4, 0x48, 0xe6, 0xde, 0x3c, 0xbd, 0x4f, 0x4b, 0x83, 0xda, 0x60, 0x56, 0x00, 0x5e, 0x19, 0x96, - 0x46, 0x55, 0x7e, 0x9e, 0xbc, 0x0f, 0xee, 0x8e, 0xbc, 0xfd, 0x1b, 0x0b, 0x56, 0x84, 0xe3, 0x60, - 0x50, 0xc3, 0x0c, 0x34, 0x46, 0x64, 0x48, 0xd2, 0x9d, 0x23, 0xca, 0x6e, 0x8e, 0x63, 0xe3, 0x96, - 0xca, 0xa3, 0xb3, 0x26, 0xee, 0x5d, 0x34, 0xf1, 0xae, 0x57, 0x3d, 0x36, 0x5a, 0x59, 0xa1, 0x6b, - 0xbb, 0x9c, 0x74, 0x3e, 0xc9, 0xb7, 0x7e, 0x30, 0xf0, 0x70, 0xf8, 0x83, 0x04, 0xa1, 0x56, 0x95, - 0xd2, 0x73, 0xcd, 0x25, 0x20, 0xaf, 0x67, 0xaa, 0x14, 0x2e, 0xa9, 0x9f, 0xee, 0x1c, 0x1d, 0x30, - 0x5f, 0x95, 0xb9, 0xaa, 0x97, 0x31, 0x2f, 0x44, 0xf9, 0xdc, 0xa8, 0x2a, 0xaf, 0xbb, 0x9c, 0x83, - 0x4d, 0xfd, 0x55, 0xe6, 0x9f, 0x26, 0xbe, 0xbf, 0x04, 0x3d, 0x7d, 0x96, 0x6c, 0x52, 0xc9, 0xf7, - 0x5f, 0xf1, 0x23, 0xa9, 0xec, 0xc7, 0x79, 0xc1, 0x4a, 0xa3, 0xb3, 0x6e, 0x2f, 0xfe, 0xf1, 0x04, - 0x3f, 0x7c, 0xca, 0xec, 0xb2, 0x16, 0xf8, 0x2f, 0x10, 0x27, 0xbb, 0x9d, 0xc7, 0x08, 0x70, 0xdc, - 0x3a, 0x84, 0x5f, 0x48, 0x10, 0x15, 0xcb, 0x1a, 0x10, 0xb9, 0x56, 0x15, 0x3f, 0x15, 0x82, 0x6b, - 0x94, 0xbc, 0xd5, 0x45, 0xb7, 0x86, 0xfd, 0xf4, 0x4e, 0xfe, 0xea, 0xa2, 0x89, 0x93, 0x6d, 0xcc, - 0xb5, 0xa2, 0xb1, 0x2f, 0xba, 0x8d, 0x4d, 0x26, 0x7b, 0x7e, 0x74, 0xac, 0xaa, 0x97, 0x42, 0x1c, - 0xa3, 0x3c, 0x71, 0x9f, 0xc3, 0xd7, 0xc1, 0x43, 0x0d, 0x0b, 0x6e, 0x8d, 0x85, 0x29, 0xbf, 0x41, - 0xec, 0x7e, 0x78, 0x8e, 0x20, 0x45, 0xd4, 0x1f, 0x92, 0xf4, 0xf6, 0x24, 0xd6, 0xb0, 0x38, 0x71, - 0x70, 0x7e, 0xdd, 0x6d, 0x04, 0xf8, 0xd6, 0x61, 0x79, 0x7e, 0xb6, 0xa2, 0xe4, 0x7c, 0x45, 0xc9, - 0xef, 0x15, 0x25, 0x5f, 0xd7, 0xb4, 0x77, 0xbe, 0xa6, 0xbd, 0x9f, 0x6b, 0xda, 0x7b, 0x97, 0x6e, - 0x6e, 0xab, 0x3d, 0xd0, 0xc5, 0x7f, 0x27, 0xda, 0x76, 0x2d, 0x06, 0xed, 0x2d, 0x3d, 0xfd, 0x1b, - 0x00, 0x00, 0xff, 0xff, 0x90, 0xb9, 0xb2, 0x8a, 0xc1, 0x02, 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 (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.MaxTotalBypassMinFeeMsgGasUsage != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.MaxTotalBypassMinFeeMsgGasUsage)) - i-- - dAtA[i] = 0x18 - } - if len(m.BypassMinFeeMsgTypes) > 0 { - for iNdEx := len(m.BypassMinFeeMsgTypes) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.BypassMinFeeMsgTypes[iNdEx]) - copy(dAtA[i:], m.BypassMinFeeMsgTypes[iNdEx]) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.BypassMinFeeMsgTypes[iNdEx]))) - i-- - dAtA[i] = 0x12 - } - } - if len(m.MinimumGasPrices) > 0 { - for iNdEx := len(m.MinimumGasPrices) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.MinimumGasPrices[iNdEx].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 (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.MinimumGasPrices) > 0 { - for _, e := range m.MinimumGasPrices { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } - if len(m.BypassMinFeeMsgTypes) > 0 { - for _, s := range m.BypassMinFeeMsgTypes { - l = len(s) - n += 1 + l + sovGenesis(uint64(l)) - } - } - if m.MaxTotalBypassMinFeeMsgGasUsage != 0 { - n += 1 + sovGenesis(uint64(m.MaxTotalBypassMinFeeMsgGasUsage)) - } - 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 (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 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: 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 != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field MinimumGasPrices", 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 - } - m.MinimumGasPrices = append(m.MinimumGasPrices, types.DecCoin{}) - if err := m.MinimumGasPrices[len(m.MinimumGasPrices)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BypassMinFeeMsgTypes", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.BypassMinFeeMsgTypes = append(m.BypassMinFeeMsgTypes, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxTotalBypassMinFeeMsgGasUsage", wireType) - } - m.MaxTotalBypassMinFeeMsgGasUsage = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxTotalBypassMinFeeMsgGasUsage |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - 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/globalfee/types/keys.go b/x/globalfee/types/keys.go deleted file mode 100644 index 71b43267..00000000 --- a/x/globalfee/types/keys.go +++ /dev/null @@ -1,8 +0,0 @@ -package types - -const ( - // ModuleName is the name of the this module - ModuleName = "globalfee" - - QuerierRoute = ModuleName -) diff --git a/x/globalfee/types/params.go b/x/globalfee/types/params.go deleted file mode 100644 index 4c3ea647..00000000 --- a/x/globalfee/types/params.go +++ /dev/null @@ -1,158 +0,0 @@ -package types - -import ( - "fmt" - "strings" - - ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - - errorsmod "cosmossdk.io/errors" - - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - atomoneerrors "github.com/atomone-hub/atomone/types/errors" -) - -var ( - // ParamStoreKeyMinGasPrices store key - ParamStoreKeyMinGasPrices = []byte("MinimumGasPricesParam") - ParamStoreKeyBypassMinFeeMsgTypes = []byte("BypassMinFeeMsgTypes") - ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage = []byte("MaxTotalBypassMinFeeMsgGasUsage") - - // DefaultMinGasPrices is set at runtime to the staking token with zero amount i.e. "0uatom" - // see DefaultZeroGlobalFee method in gaia/x/globalfee/ante/fee.go. - DefaultMinGasPrices = sdk.DecCoins{} - DefaultBypassMinFeeMsgTypes = []string{ - sdk.MsgTypeURL(&ibcchanneltypes.MsgRecvPacket{}), - sdk.MsgTypeURL(&ibcchanneltypes.MsgAcknowledgement{}), - sdk.MsgTypeURL(&ibcclienttypes.MsgUpdateClient{}), - sdk.MsgTypeURL(&ibcchanneltypes.MsgTimeout{}), - sdk.MsgTypeURL(&ibcchanneltypes.MsgTimeoutOnClose{}), - } - - // maxTotalBypassMinFeeMsgGasUsage is the allowed maximum gas usage - // for all the bypass msgs in a transactions. - // A transaction that contains only bypass message types and the gas usage does not - // exceed maxTotalBypassMinFeeMsgGasUsage can be accepted with a zero fee. - // For details, see atomonefeeante.NewFeeDecorator() - DefaultmaxTotalBypassMinFeeMsgGasUsage uint64 = 1_000_000 -) - -// DefaultParams returns default parameters -func DefaultParams() Params { - return Params{ - MinimumGasPrices: DefaultMinGasPrices, - BypassMinFeeMsgTypes: DefaultBypassMinFeeMsgTypes, - MaxTotalBypassMinFeeMsgGasUsage: DefaultmaxTotalBypassMinFeeMsgGasUsage, - } -} - -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// ValidateBasic performs basic validation. -func (p Params) ValidateBasic() error { - if err := validateMinimumGasPrices(p.MinimumGasPrices); err != nil { - return err - } - - if err := validateBypassMinFeeMsgTypes(p.BypassMinFeeMsgTypes); err != nil { - return err - } - - return validateMaxTotalBypassMinFeeMsgGasUsage(p.MaxTotalBypassMinFeeMsgGasUsage) -} - -// ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair( - ParamStoreKeyMinGasPrices, &p.MinimumGasPrices, validateMinimumGasPrices, - ), - paramtypes.NewParamSetPair( - ParamStoreKeyBypassMinFeeMsgTypes, &p.BypassMinFeeMsgTypes, validateBypassMinFeeMsgTypes, - ), - paramtypes.NewParamSetPair( - ParamStoreKeyMaxTotalBypassMinFeeMsgGasUsage, &p.MaxTotalBypassMinFeeMsgGasUsage, validateMaxTotalBypassMinFeeMsgGasUsage, - ), - } -} - -func validateMinimumGasPrices(i interface{}) error { - v, ok := i.(sdk.DecCoins) - if !ok { - return errorsmod.Wrapf(atomoneerrors.ErrInvalidType, "type: %T, expected sdk.DecCoins", i) - } - - dec := DecCoins(v) - return dec.Validate() -} - -type BypassMinFeeMsgTypes []string - -// validateBypassMinFeeMsgTypes checks that bypass msg types aren't empty -func validateBypassMinFeeMsgTypes(i interface{}) error { - bypassMinFeeMsgTypes, ok := i.([]string) - if !ok { - return errorsmod.Wrapf(atomoneerrors.ErrInvalidType, "type: %T, expected []sdk.Msg", i) - } - - for _, msgType := range bypassMinFeeMsgTypes { - if msgType == "" { - return fmt.Errorf("invalid empty bypass msg type") - } - - if !strings.HasPrefix(msgType, sdk.MsgTypeURL(nil)) { - return fmt.Errorf("invalid bypass msg type name %s", msgType) - } - } - - return nil -} - -func validateMaxTotalBypassMinFeeMsgGasUsage(i interface{}) error { - _, ok := i.(uint64) - if !ok { - return errorsmod.Wrapf(atomoneerrors.ErrInvalidType, "type: %T, expected uint64", i) - } - - return nil -} - -type DecCoins sdk.DecCoins - -// Validate checks that the DecCoins are sorted, have nonnegtive amount, with a valid and unique -// denomination (i.e no duplicates). Otherwise, it returns an error. -func (coins DecCoins) Validate() error { - if len(coins) == 0 { - return nil - } - - lowDenom := "" - seenDenoms := make(map[string]bool) - - for i, coin := range coins { - if seenDenoms[coin.Denom] { - return fmt.Errorf("duplicate denomination %s", coin.Denom) - } - if err := sdk.ValidateDenom(coin.Denom); err != nil { - return err - } - // skip the denom order check for the first denom in the coins list - if i != 0 && coin.Denom <= lowDenom { - return fmt.Errorf("denomination %s is not sorted", coin.Denom) - } - if coin.IsNegative() { - return fmt.Errorf("coin %s amount is negative", coin.Amount) - } - - // we compare each coin against the last denom - lowDenom = coin.Denom - seenDenoms[coin.Denom] = true - } - - return nil -} diff --git a/x/globalfee/types/params_test.go b/x/globalfee/types/params_test.go deleted file mode 100644 index 78d17ba8..00000000 --- a/x/globalfee/types/params_test.go +++ /dev/null @@ -1,157 +0,0 @@ -package types - -import ( - "testing" - - "github.com/stretchr/testify/require" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func TestDefaultParams(t *testing.T) { - p := DefaultParams() - require.EqualValues(t, p.MinimumGasPrices, sdk.DecCoins{}) - require.EqualValues(t, p.BypassMinFeeMsgTypes, DefaultBypassMinFeeMsgTypes) - require.EqualValues(t, p.MaxTotalBypassMinFeeMsgGasUsage, DefaultmaxTotalBypassMinFeeMsgGasUsage) -} - -func Test_validateMinGasPrices(t *testing.T) { - tests := map[string]struct { - coins interface{} - expectErr bool - }{ - "DefaultParams, pass": { - DefaultParams().MinimumGasPrices, - false, - }, - "DecCoins conversion fails, fail": { - sdk.Coins{sdk.NewCoin("photon", sdk.OneInt())}, - true, - }, - "coins amounts are zero, pass": { - sdk.DecCoins{ - sdk.NewDecCoin("atom", sdk.ZeroInt()), - sdk.NewDecCoin("photon", sdk.ZeroInt()), - }, - false, - }, - "duplicate coins denoms, fail": { - sdk.DecCoins{ - sdk.NewDecCoin("photon", sdk.OneInt()), - sdk.NewDecCoin("photon", sdk.OneInt()), - }, - true, - }, - "coins are not sorted by denom alphabetically, fail": { - sdk.DecCoins{ - sdk.NewDecCoin("photon", sdk.OneInt()), - sdk.NewDecCoin("atom", sdk.OneInt()), - }, - true, - }, - "negative amount, fail": { - sdk.DecCoins{ - sdk.DecCoin{Denom: "photon", Amount: sdk.OneDec().Neg()}, - }, - true, - }, - "invalid denom, fail": { - sdk.DecCoins{ - sdk.DecCoin{Denom: "photon!", Amount: sdk.OneDec().Neg()}, - }, - true, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - err := validateMinimumGasPrices(test.coins) - if test.expectErr { - require.Error(t, err) - return - } - require.NoError(t, err) - }) - } -} - -func Test_validateBypassMinFeeMsgTypes(t *testing.T) { - tests := map[string]struct { - msgTypes interface{} - expectErr bool - }{ - "DefaultParams, pass": { - DefaultParams().BypassMinFeeMsgTypes, - false, - }, - "wrong msg type should make conversion fail, fail": { - []int{0, 1, 2, 3}, - true, - }, - "empty msg types, pass": { - []string{}, - false, - }, - "empty msg type, fail": { - []string{""}, - true, - }, - "invalid msg type name, fail": { - []string{"ibc.core.channel.v1.MsgRecvPacket"}, - true, - }, - "mixed valid and invalid msgs, fail": { - []string{ - "/ibc.core.channel.v1.MsgRecvPacket", - "", - }, - true, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - err := validateBypassMinFeeMsgTypes(test.msgTypes) - if test.expectErr { - require.Error(t, err) - return - } - require.NoError(t, err) - }) - } -} - -func Test_validateMaxTotalBypassMinFeeMsgGasUsage(t *testing.T) { - tests := map[string]struct { - msgTypes interface{} - expectErr bool - }{ - "DefaultParams, pass": { - DefaultParams().MaxTotalBypassMinFeeMsgGasUsage, - false, - }, - "zero value, pass": { - uint64(0), - false, - }, - "negative value, fail": { - -1, - true, - }, - "invalid type, fail": { - "5", - true, - }, - } - - for name, test := range tests { - t.Run(name, func(t *testing.T) { - err := validateMaxTotalBypassMinFeeMsgGasUsage(test.msgTypes) - if test.expectErr { - require.Error(t, err) - return - } - require.NoError(t, err) - }) - } -} diff --git a/x/globalfee/types/query.pb.go b/x/globalfee/types/query.pb.go deleted file mode 100644 index fbf9ed45..00000000 --- a/x/globalfee/types/query.pb.go +++ /dev/null @@ -1,536 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: gaia/globalfee/v1beta1/query.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/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 - -// QueryMinimumGasPricesRequest is the request type for the -// Query/MinimumGasPrices 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_12a736cede25d10a, []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 - -// QueryMinimumGasPricesResponse is the response type for the -// Query/MinimumGasPrices RPC method. -type QueryParamsResponse struct { - 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_12a736cede25d10a, []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), "gaia.globalfee.v1beta1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "gaia.globalfee.v1beta1.QueryParamsResponse") -} - -func init() { - proto.RegisterFile("gaia/globalfee/v1beta1/query.proto", fileDescriptor_12a736cede25d10a) -} - -var fileDescriptor_12a736cede25d10a = []byte{ - // 286 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x90, 0x31, 0x4b, 0xc3, 0x40, - 0x14, 0xc7, 0x73, 0xa2, 0x1d, 0xce, 0xed, 0x2c, 0x22, 0x41, 0xce, 0x12, 0x44, 0x8a, 0xc2, 0x1d, - 0xad, 0xab, 0x53, 0x3e, 0x81, 0xd6, 0xcd, 0xed, 0x52, 0x9e, 0x67, 0x20, 0xc9, 0x4b, 0x73, 0x17, - 0xb1, 0xab, 0x9b, 0x9b, 0xd0, 0x2f, 0xd5, 0xb1, 0xe0, 0xe2, 0x24, 0x92, 0xf8, 0x41, 0x24, 0xb9, - 0x20, 0x8a, 0x06, 0xdc, 0x8e, 0x77, 0xbf, 0xf7, 0x7f, 0x3f, 0xfe, 0x34, 0xd0, 0x2a, 0x56, 0x52, - 0x27, 0x18, 0xa9, 0xe4, 0x16, 0x40, 0xde, 0x4f, 0x22, 0xb0, 0x6a, 0x22, 0x17, 0x25, 0x14, 0x4b, - 0x91, 0x17, 0x68, 0x91, 0xed, 0x37, 0x8c, 0xf8, 0x62, 0x44, 0xc7, 0xf8, 0x43, 0x8d, 0x1a, 0x5b, - 0x44, 0x36, 0x2f, 0x47, 0xfb, 0x87, 0x1a, 0x51, 0x27, 0x20, 0x55, 0x1e, 0x4b, 0x95, 0x65, 0x68, - 0x95, 0x8d, 0x31, 0x33, 0xdd, 0xef, 0x71, 0xcf, 0x3d, 0x0d, 0x19, 0x98, 0xb8, 0xa3, 0x82, 0x21, - 0x65, 0x57, 0x8d, 0xc0, 0xa5, 0x2a, 0x54, 0x6a, 0x66, 0xb0, 0x28, 0xc1, 0xd8, 0xe0, 0x9a, 0xee, - 0xfd, 0x98, 0x9a, 0x1c, 0x33, 0x03, 0xec, 0x82, 0x0e, 0xf2, 0x76, 0x72, 0x40, 0x46, 0x64, 0xbc, - 0x3b, 0xe5, 0xe2, 0x6f, 0x5f, 0xe1, 0xf6, 0xc2, 0xed, 0xf5, 0xdb, 0x91, 0x37, 0xeb, 0x76, 0xa6, - 0x2b, 0x42, 0x77, 0xda, 0x54, 0xf6, 0x44, 0xe8, 0xc0, 0x21, 0xec, 0xb4, 0x2f, 0xe2, 0xb7, 0x95, - 0x7f, 0xf6, 0x2f, 0xd6, 0xb9, 0x06, 0x27, 0x8f, 0x2f, 0x1f, 0xab, 0xad, 0x11, 0xe3, 0xb2, 0xa7, - 0x07, 0x67, 0x15, 0x86, 0xeb, 0x8a, 0x93, 0x4d, 0xc5, 0xc9, 0x7b, 0xc5, 0xc9, 0x73, 0xcd, 0xbd, - 0x4d, 0xcd, 0xbd, 0xd7, 0x9a, 0x7b, 0x37, 0x63, 0x1d, 0xdb, 0xbb, 0x32, 0x12, 0x73, 0x4c, 0xe5, - 0x1c, 0x4d, 0x8a, 0xc6, 0x45, 0x3d, 0x7c, 0x0b, 0xb3, 0xcb, 0x1c, 0x4c, 0x34, 0x68, 0xbb, 0x3c, - 0xff, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x01, 0xc5, 0x11, 0x71, 0xe3, 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(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, "/gaia.globalfee.v1beta1.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(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: "/gaia.globalfee.v1beta1.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: "gaia.globalfee.v1beta1.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Params", - Handler: _Query_Params_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "gaia/globalfee/v1beta1/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/globalfee/types/query.pb.gw.go b/x/globalfee/types/query.pb.gw.go deleted file mode 100644 index 71ec5cba..00000000 --- a/x/globalfee/types/query.pb.gw.go +++ /dev/null @@ -1,153 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: gaia/globalfee/v1beta1/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{"gaia", "globalfee", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(false))) -) - -var ( - forward_Query_Params_0 = runtime.ForwardResponseMessage -)