diff --git a/app/upgrades/v8_1/constants.go b/app/upgrades/v8_1/constants.go index f970040c8..b664957c9 100644 --- a/app/upgrades/v8_1/constants.go +++ b/app/upgrades/v8_1/constants.go @@ -1,4 +1,4 @@ -package v8_1 +package v81 import ( "github.com/classic-terra/core/v3/app/upgrades" diff --git a/app/upgrades/v8_1/upgrades.go b/app/upgrades/v8_1/upgrades.go index 3ca0dee33..12c59f5e9 100644 --- a/app/upgrades/v8_1/upgrades.go +++ b/app/upgrades/v8_1/upgrades.go @@ -1,4 +1,4 @@ -package v8_1 +package v81 import ( "github.com/classic-terra/core/v3/app/keepers" diff --git a/custom/auth/post/post.go b/custom/auth/post/post.go index 19c4eda9a..bb737fc07 100644 --- a/custom/auth/post/post.go +++ b/custom/auth/post/post.go @@ -3,10 +3,9 @@ package post import ( dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper" dyncommpost "github.com/classic-terra/core/v3/x/dyncomm/post" - tax2gasKeeper "github.com/classic-terra/core/v3/x/tax2gas/keeper" - tax2gasPost "github.com/classic-terra/core/v3/x/tax2gas/post" - "github.com/classic-terra/core/v3/x/tax2gas/types" - tax2gasTypes "github.com/classic-terra/core/v3/x/tax2gas/types" + tax2gaskeeper "github.com/classic-terra/core/v3/x/tax2gas/keeper" + tax2gaspost "github.com/classic-terra/core/v3/x/tax2gas/post" + tax2gastypes "github.com/classic-terra/core/v3/x/tax2gas/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/ante" ) @@ -14,11 +13,11 @@ import ( // HandlerOptions are the options required for constructing a default SDK AnteHandler. type HandlerOptions struct { AccountKeeper ante.AccountKeeper - BankKeeper types.BankKeeper - FeegrantKeeper types.FeegrantKeeper + BankKeeper tax2gastypes.BankKeeper + FeegrantKeeper tax2gastypes.FeegrantKeeper DyncommKeeper dyncommkeeper.Keeper - TreasuryKeeper tax2gasTypes.TreasuryKeeper - Tax2Gaskeeper tax2gasKeeper.Keeper + TreasuryKeeper tax2gastypes.TreasuryKeeper + Tax2Gaskeeper tax2gaskeeper.Keeper } // NewPostHandler returns an PostHandler that checks and set target @@ -26,6 +25,6 @@ type HandlerOptions struct { func NewPostHandler(options HandlerOptions) (sdk.PostHandler, error) { return sdk.ChainPostDecorators( dyncommpost.NewDyncommPostDecorator(options.DyncommKeeper), - tax2gasPost.NewTax2GasPostDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper, options.Tax2Gaskeeper), + tax2gaspost.NewTax2GasPostDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper, options.Tax2Gaskeeper), ), nil } diff --git a/custom/wasm/keeper/handler_plugin.go b/custom/wasm/keeper/handler_plugin.go index 49cea8f54..2f8fe2c6b 100644 --- a/custom/wasm/keeper/handler_plugin.go +++ b/custom/wasm/keeper/handler_plugin.go @@ -88,17 +88,19 @@ func (h SDKMessageHandler) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddr } for _, sdkMsg := range sdkMsgs { - taxes := FilterMsgAndComputeTax(ctx, h.treasuryKeeper, sdkMsg) - if !taxes.IsZero() { - eventManager := sdk.NewEventManager() + if h.tax2gaskeeper.IsEnabled(ctx) { + taxes := FilterMsgAndComputeTax(ctx, h.treasuryKeeper, sdkMsg) + if !taxes.IsZero() { + eventManager := sdk.NewEventManager() + + gas, err := tax2gasutils.ComputeGas(h.tax2gaskeeper.GetGasPrices(ctx), taxes) + if err != nil { + return nil, nil, err + } + ctx.GasMeter().ConsumeGas(gas, "tax gas") - gas, err := tax2gasutils.ComputeGas(ctx, h.tax2gaskeeper.GetGasPrices(ctx), taxes) - if err != nil { - return nil, nil, err + events = eventManager.Events() } - ctx.GasMeter().ConsumeGas(gas, "tax gas") - - events = eventManager.Events() } res, err := h.handleSdkMessage(ctx, contractAddr, sdkMsg) diff --git a/forwarder.wasm b/forwarder.wasm deleted file mode 100644 index 53b24d72c..000000000 Binary files a/forwarder.wasm and /dev/null differ diff --git a/proto/terra/tax2gas/v1beta1/genesis.proto b/proto/terra/tax2gas/v1beta1/genesis.proto index 7299cad79..7c63e7be2 100644 --- a/proto/terra/tax2gas/v1beta1/genesis.proto +++ b/proto/terra/tax2gas/v1beta1/genesis.proto @@ -17,6 +17,8 @@ message Params { (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + + bool enabled = 2; } // GenesisState defines the tax2gas module's genesis state. diff --git a/scripts/run-node.sh b/scripts/run-node.sh index 93d1a9cb6..30243cac4 100755 --- a/scripts/run-node.sh +++ b/scripts/run-node.sh @@ -57,9 +57,9 @@ $BINARY keys add $KEY1 --keyring-backend $KEYRING --home $HOME_DIR $BINARY keys add $KEY2 --keyring-backend $KEYRING --home $HOME_DIR # Allocate genesis accounts (cosmos formatted addresses) -$BINARY add-genesis-account $KEY "1000000000000${DENOM},1000000000000uusd" --keyring-backend $KEYRING --home $HOME_DIR -$BINARY add-genesis-account $KEY1 "1000000000000${DENOM},1000000000000uusd" --keyring-backend $KEYRING --home $HOME_DIR -$BINARY add-genesis-account $KEY2 "1000000000000${DENOM},1000000000000uusd" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY "1000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY1 "1000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR +$BINARY add-genesis-account $KEY2 "1000000000000${DENOM}" --keyring-backend $KEYRING --home $HOME_DIR update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="'$DENOM'"' update_test_genesis '.app_state["gov"]["deposit_params"]["min_deposit"]=[{"denom":"'$DENOM'","amount": "1000000"}]' diff --git a/tests/interchaintest/setup.go b/tests/interchaintest/setup.go index 336c0b389..00b826307 100644 --- a/tests/interchaintest/setup.go +++ b/tests/interchaintest/setup.go @@ -81,6 +81,10 @@ func ModifyGenesis() func(ibc.ChainConfig, []byte) ([]byte, error) { if err := dyno.Set(g, chainConfig.Denom, "app_state", "gov", "params", "min_deposit", 0, "denom"); err != nil { return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err) } + // Disable tax2gas params to disable + if err := dyno.Set(g, false, "app_state", "tax2gas", "params", "enabled"); err != nil { + return nil, fmt.Errorf("failed to set tax2gas params in genesis json: %w", err) + } // Modify signed blocks window if err := dyno.Set(g, signedBlocksWindow, "app_state", "slashing", "params", "signed_blocks_window"); err != nil { return nil, fmt.Errorf("failed to set signed blocks window in genesis json: %w", err) diff --git a/x/tax2gas/ante/ante.go b/x/tax2gas/ante/ante.go index afffdcf9e..ee1f734be 100644 --- a/x/tax2gas/ante/ante.go +++ b/x/tax2gas/ante/ante.go @@ -53,14 +53,14 @@ func (fd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, nex ) msgs := feeTx.GetMsgs() - if tax2gasutils.IsOracleTx(msgs) || simulate { + if tax2gasutils.IsOracleTx(msgs) || simulate || !fd.tax2gasKeeper.IsEnabled(ctx) { return next(ctx, tx, simulate) } // Compute taxes based on consumed gas gasPrices := fd.tax2gasKeeper.GetGasPrices(ctx) gasConsumed := ctx.GasMeter().GasConsumed() - gasConsumedFees, err := tax2gasutils.ComputeFeesOnGasConsumed(ctx, tx, gasPrices, gasConsumed) + gasConsumedFees, err := tax2gasutils.ComputeFeesOnGasConsumed(tx, gasPrices, gasConsumed) if err != nil { return ctx, err } @@ -68,7 +68,7 @@ func (fd FeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, nex // Compute taxes based on sent amount taxes := tax2gasutils.FilterMsgAndComputeTax(ctx, fd.treasuryKeeper, msgs...) // Convert taxes to gas - taxGas, err := tax2gasutils.ComputeGas(ctx, gasPrices, taxes) + taxGas, err := tax2gasutils.ComputeGas(gasPrices, taxes) if err != nil { return ctx, err } @@ -193,9 +193,8 @@ func (fd FeeDecorator) tryDeductFee(ctx sdk.Context, feeTx sdk.FeeTx, taxes sdk. // As there is only 1 element return foundCoins.Denoms()[0], nil - } else { - return "", fmt.Errorf("can't find coin that matches. Expected %s, wanted %s", feeCoins, taxes) } + return "", fmt.Errorf("can't find coin that matches. Expected %s, wanted %s", feeCoins, taxes) } // DeductFees deducts fees from the given account. diff --git a/x/tax2gas/ante/fee_test.go b/x/tax2gas/ante/fee_test.go index 8b1c1bc49..ea89f459f 100644 --- a/x/tax2gas/ante/fee_test.go +++ b/x/tax2gas/ante/fee_test.go @@ -258,5 +258,4 @@ func (s *AnteTestSuite) TestDeductFeeDecorator() { } }) } - } diff --git a/x/tax2gas/keeper/keeper.go b/x/tax2gas/keeper/keeper.go index 799363108..c312b5c84 100644 --- a/x/tax2gas/keeper/keeper.go +++ b/x/tax2gas/keeper/keeper.go @@ -60,6 +60,10 @@ func (k Keeper) GetAuthority() string { return k.authority } +func (k Keeper) IsEnabled(ctx sdk.Context) bool { + return k.GetParams(ctx).Enabled +} + func (k Keeper) GetGasPrices(ctx sdk.Context) sdk.DecCoins { return k.GetParams(ctx).GasPrices.Sort() } diff --git a/x/tax2gas/keeper/msg_server.go b/x/tax2gas/keeper/msg_server.go index dec91e807..2bfff7a50 100644 --- a/x/tax2gas/keeper/msg_server.go +++ b/x/tax2gas/keeper/msg_server.go @@ -3,8 +3,8 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/classic-terra/core/v3/x/tax2gas/types" @@ -24,7 +24,7 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer { func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if k.GetAuthority() != req.Authority { - return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/tax2gas/module.go b/x/tax2gas/module.go index 462996906..e34c9764b 100644 --- a/x/tax2gas/module.go +++ b/x/tax2gas/module.go @@ -39,7 +39,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { } // ValidateGenesis performs genesis state validation for the tax2gas module. -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { var genState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genState); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) @@ -87,7 +87,7 @@ func NewAppModule(cdc codec.Codec, tax2gasKeeper keeper.Keeper) AppModule { } } -func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) { } // QuerierRoute returns the tax2gas module's querier route name. @@ -114,7 +114,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} // EndBlock performs TODO. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } diff --git a/x/tax2gas/post/post.go b/x/tax2gas/post/post.go index acfcc3a04..9682c52c1 100644 --- a/x/tax2gas/post/post.go +++ b/x/tax2gas/post/post.go @@ -31,7 +31,7 @@ func NewTax2GasPostDecorator(accountKeeper ante.AccountKeeper, bankKeeper types. } // TODO: handle fail tx -func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, success bool, next sdk.PostHandler) (sdk.Context, error) { +func (tgd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, success bool, next sdk.PostHandler) (sdk.Context, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") @@ -41,7 +41,7 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") } msgs := feeTx.GetMsgs() - if tax2gasutils.IsOracleTx(msgs) || simulate { + if tax2gasutils.IsOracleTx(msgs) || simulate || !tgd.tax2gasKeeper.IsEnabled(ctx) { return next(ctx, tx, simulate, success) } @@ -59,7 +59,7 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b return next(ctx, tx, simulate, success) } - gasPrices := dd.tax2gasKeeper.GetGasPrices(ctx) + gasPrices := tgd.tax2gasKeeper.GetGasPrices(ctx) found, paidDenomGasPrice := tax2gasutils.GetGasPriceByDenom(gasPrices, paidDenom) if !found { return ctx, types.ErrDenomNotFound @@ -85,15 +85,15 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b // if feegranter set deduct fee from feegranter account. // this works with only when feegrant enabled. if feeGranter != nil { - if dd.feegrantKeeper == nil { + if tgd.feegrantKeeper == nil { return ctx, sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled") } else if !feeGranter.Equals(feePayer) { - allowance, err := dd.feegrantKeeper.GetAllowance(ctx, feeGranter, feePayer) + allowance, err := tgd.feegrantKeeper.GetAllowance(ctx, feeGranter, feePayer) if err != nil { return ctx, errorsmod.Wrapf(err, "fee-grant not found with granter %s and grantee %s", feeGranter, feePayer) } - gasRemainingFees, err := tax2gasutils.ComputeFeesOnGasConsumed(ctx, tx, gasPrices, gasRemaining) + gasRemainingFees, err := tax2gasutils.ComputeFeesOnGasConsumed(tx, gasPrices, gasRemaining) if err != nil { return ctx, err } @@ -102,12 +102,12 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b for _, feeRequired := range gasRemainingFees { _, err := allowance.Accept(ctx, sdk.NewCoins(feeRequired), feeTx.GetMsgs()) if err == nil { - err = dd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, sdk.NewCoins(feeRequired), feeTx.GetMsgs()) + err = tgd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, sdk.NewCoins(feeRequired), feeTx.GetMsgs()) if err != nil { return ctx, errorsmod.Wrapf(err, "%s does not allow to pay fees for %s", feeGranter, feePayer) } - feeGranter := dd.accountKeeper.GetAccount(ctx, feeGranter) - err = dd.bankKeeper.SendCoinsFromAccountToModule(ctx, feeGranter.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeRequired)) + feeGranter := tgd.accountKeeper.GetAccount(ctx, feeGranter) + err = tgd.bankKeeper.SendCoinsFromAccountToModule(ctx, feeGranter.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeRequired)) if err != nil { return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) } @@ -119,7 +119,7 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b } for _, feeCoin := range feeCoins { - feePayer := dd.accountKeeper.GetAccount(ctx, feePayer) + feePayer := tgd.accountKeeper.GetAccount(ctx, feePayer) found, gasPrice := tax2gasutils.GetGasPriceByDenom(gasPrices, feeCoin.Denom) if !found { continue @@ -127,20 +127,20 @@ func (dd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate b feeRequired := sdk.NewCoin(feeCoin.Denom, gasPrice.MulInt64(int64(gasRemaining)).Ceil().RoundInt()) if feeCoin.IsGTE(feeRequired) { - err := dd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeRequired)) + err := tgd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeRequired)) if err != nil { return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) } gasRemaining = 0 break - } else { - err := dd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeCoin)) - if err != nil { - return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) - } - feeRemaining := sdk.NewDecCoinFromCoin(feeRequired.Sub(feeCoin)) - gasRemaining = uint64(feeRemaining.Amount.Quo(gasPrice).Ceil().RoundInt64()) } + + err := tgd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayer.GetAddress(), authtypes.FeeCollectorName, sdk.NewCoins(feeCoin)) + if err != nil { + return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) + } + feeRemaining := sdk.NewDecCoinFromCoin(feeRequired.Sub(feeCoin)) + gasRemaining = uint64(feeRemaining.Amount.Quo(gasPrice).Ceil().RoundInt64()) } if gasRemaining > 0 { return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "fees are not enough to pay for gas") diff --git a/x/tax2gas/types/expected_keeper.go b/x/tax2gas/types/expected_keeper.go index 9281fec9c..b807a722d 100644 --- a/x/tax2gas/types/expected_keeper.go +++ b/x/tax2gas/types/expected_keeper.go @@ -2,8 +2,8 @@ package types import ( "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/x/feegrant" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" ) // TreasuryKeeper for tax charging & recording diff --git a/x/tax2gas/types/genesis.pb.go b/x/tax2gas/types/genesis.pb.go index 7872c590c..33a27210d 100644 --- a/x/tax2gas/types/genesis.pb.go +++ b/x/tax2gas/types/genesis.pb.go @@ -28,6 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Params struct { GasPrices github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,1,rep,name=gas_prices,json=gasPrices,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"gas_prices" yaml:"gas_prices"` + Enabled bool `protobuf:"varint,2,opt,name=enabled,proto3" json:"enabled,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -70,6 +71,13 @@ func (m *Params) GetGasPrices() github_com_cosmos_cosmos_sdk_types.DecCoins { return nil } +func (m *Params) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + // GenesisState defines the tax2gas module's genesis state. type GenesisState struct { // params is the container of tax2gas parameters. @@ -126,29 +134,30 @@ func init() { } var fileDescriptor_589c4ef0e5113034 = []byte{ - // 350 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2e, 0x49, 0x2d, 0x2a, - 0x4a, 0xd4, 0x2f, 0x49, 0xac, 0x30, 0x4a, 0x4f, 0x2c, 0xd6, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, - 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, - 0x12, 0x05, 0x2b, 0xd2, 0x83, 0x2a, 0xd2, 0x83, 0x2a, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, - 0xab, 0xd0, 0x07, 0xb1, 0x20, 0x8a, 0xa5, 0xe4, 0x92, 0xf3, 0x8b, 0x73, 0xf3, 0x8b, 0xf5, 0x93, - 0x12, 0x8b, 0x53, 0xe1, 0xe6, 0x25, 0xe7, 0x67, 0xe6, 0x41, 0xe5, 0x05, 0x13, 0x73, 0x33, 0xf3, - 0xf2, 0xf5, 0xc1, 0x24, 0x44, 0x48, 0x69, 0x1b, 0x23, 0x17, 0x5b, 0x40, 0x62, 0x51, 0x62, 0x6e, - 0xb1, 0x50, 0x17, 0x23, 0x17, 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 0x18, 0x6e, 0x3c, 0x96, - 0x63, 0x88, 0x32, 0x40, 0xf6, 0x44, 0x4e, 0x62, 0x71, 0x71, 0x66, 0xb2, 0x2e, 0xc4, 0x45, 0xc9, - 0xf9, 0x45, 0xa9, 0xfa, 0x65, 0xc6, 0x48, 0x2e, 0x03, 0x7b, 0x29, 0x89, 0x0d, 0x1c, 0xb0, 0xc6, - 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa9, 0x45, 0xad, 0x9c, 0xdf, 0x01, 0x00, 0x00, + // 362 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x50, 0x3f, 0x4f, 0xc2, 0x40, + 0x1c, 0xed, 0xa9, 0x41, 0x2d, 0x2e, 0x34, 0x6a, 0x1a, 0xa2, 0x2d, 0xa9, 0x0b, 0xc1, 0x70, 0x27, + 0xb0, 0xe1, 0x86, 0x26, 0x26, 0x1a, 0x13, 0x82, 0x9b, 0x8b, 0xb9, 0x96, 0x4b, 0x6d, 0xa4, 0xbd, + 0xa6, 0xbf, 0x93, 0xc0, 0x57, 0x60, 0x72, 0x74, 0x74, 0x34, 0x4e, 0x7c, 0x0c, 0x46, 0x46, 0x27, + 0x34, 0x30, 0xb0, 0xfb, 0x09, 0x0c, 0x77, 0x05, 0x19, 0x5c, 0xee, 0xdf, 0xef, 0xbd, 0x77, 0xef, + 0x3d, 0xfd, 0x44, 0xb0, 0x24, 0xa1, 0x44, 0xd0, 0x5e, 0xd5, 0xa7, 0x40, 0xba, 0x15, 0x97, 0x09, + 0x5a, 0x21, 0x3e, 0x8b, 0x18, 0x04, 0x80, 0xe3, 0x84, 0x0b, 0x6e, 0x1c, 0x48, 0x10, 0x4e, 0x41, + 0x38, 0x05, 0xe5, 0xf7, 0x7d, 0xee, 0x73, 0x89, 0x20, 0x8b, 0x93, 0x02, 0xe7, 0x2d, 0x8f, 0x43, + 0xc8, 0x81, 0xb8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df, 0x53, 0x0b, 0xbd, 0xcc, 0x2c, 0x6d, 0x3c, 0xb3, + 0xb4, 0xcf, 0x99, 0xa5, 0xdd, 0x9f, 0xad, 0xc7, 0xeb, 0x50, 0x80, 0xc0, 0x2b, 0x2b, 0x47, 0x1e, + 0x4f, 0x18, 0xe9, 0xd6, 0xd6, 0x9c, 0xc9, 0xb0, 0x6e, 0x46, 0x56, 0x5e, 0xfb, 0x0d, 0x00, 0x00, + 0xff, 0xff, 0x88, 0xc0, 0xca, 0x42, 0xf9, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -171,6 +180,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } if len(m.GasPrices) > 0 { for iNdEx := len(m.GasPrices) - 1; iNdEx >= 0; iNdEx-- { { @@ -244,6 +263,9 @@ func (m *Params) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if m.Enabled { + n += 2 + } return n } @@ -327,6 +349,26 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/tax2gas/types/params.go b/x/tax2gas/types/params.go index 1ced415fd..c1de909bf 100644 --- a/x/tax2gas/types/params.go +++ b/x/tax2gas/types/params.go @@ -38,13 +38,19 @@ func DefaultParams() Params { sdk.NewDecCoinFromDec("umyr", sdk.NewDecWithPrec(3, 0)), sdk.NewDecCoinFromDec("utwd", sdk.NewDecWithPrec(20, 0)), ), + Enabled: true, } } // Validate validates params. func (p Params) Validate() error { - if len(p.GasPrices) == 0 { - return fmt.Errorf("must provide at least 1 gas prices") + if p.Enabled { + if len(p.GasPrices) == 0 { + return fmt.Errorf("must provide at least 1 gas prices") + } + if !p.GasPrices.IsAllPositive() { + return fmt.Errorf("gas prices must be positive") + } } return nil } diff --git a/x/tax2gas/utils/fee_tax.go b/x/tax2gas/utils/fee_tax.go index a8d48b8ff..fd00be723 100644 --- a/x/tax2gas/utils/fee_tax.go +++ b/x/tax2gas/utils/fee_tax.go @@ -115,21 +115,20 @@ func computeTax(ctx sdk.Context, tk types.TreasuryKeeper, principal sdk.Coins) s return taxes } -func ComputeGas(ctx sdk.Context, gasPrices sdk.DecCoins, taxes sdk.Coins) (uint64, error) { +func ComputeGas(gasPrices sdk.DecCoins, taxes sdk.Coins) (uint64, error) { taxes = taxes.Sort() - - var tax2gas sdkmath.Int = sdkmath.ZeroInt() - + tax2gas := sdkmath.ZeroInt() // Convert to gas - var i, j int = 0, 0 + i, j := 0, 0 for i < len(gasPrices) && j < len(taxes) { - if gasPrices[i].Denom == taxes[j].Denom { - tax2gas = tax2gas.Add(sdkmath.Int(sdk.NewDec(taxes[j].Amount.Int64()).Quo((gasPrices[i].Amount)).Ceil().RoundInt())) + switch { + case gasPrices[i].Denom == taxes[j].Denom: + tax2gas = tax2gas.Add(sdk.NewDec(taxes[j].Amount.Int64()).Quo((gasPrices[i].Amount)).Ceil().RoundInt()) i++ j++ - } else if gasPrices[i].Denom < taxes[j].Denom { + case gasPrices[i].Denom < taxes[j].Denom: i++ - } else { + default: j++ } } @@ -137,7 +136,7 @@ func ComputeGas(ctx sdk.Context, gasPrices sdk.DecCoins, taxes sdk.Coins) (uint6 return tax2gas.Uint64(), nil } -func ComputeFeesOnGasConsumed(ctx sdk.Context, tx sdk.Tx, gasPrices sdk.DecCoins, gas uint64) (sdk.Coins, error) { +func ComputeFeesOnGasConsumed(tx sdk.Tx, gasPrices sdk.DecCoins, gas uint64) (sdk.Coins, error) { feeTx, ok := tx.(sdk.FeeTx) if !ok { return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")