Skip to content

Instantly share code, notes, and snippets.

@faddat
Last active December 7, 2022 09:48
Show Gist options
  • Save faddat/2e56952ee1564a2e899abedd73a87400 to your computer and use it in GitHub Desktop.
Save faddat/2e56952ee1564a2e899abedd73a87400 to your computer and use it in GitHub Desktop.
juno global fees

Juno Fees and Fees Check

Juno Fees

The Juno has two types of fees, both of which, are the sdk.DecCoins type:

  • global fees (are defined at the network level, via Gov Proposals)
  • min_gas_prices (are specified validator node, in the config/app.toml configuration file)

Global Fees

Global Fees Concept

Global fees are the fees that each transaction incurs—except bypass fee message types. Global fees are set up through a governance proposal which must be voted on by validators.

For global fees to be valid:

  • fees have to be alphabetically sorted by denomination (denom)
  • fees must have non-negative amount, with a valid and unique denom (i.e. no duplicate denoms are allowed).

Global fees allow denoms with zero coins or value.

Zero value coins are used to define fee denoms, when the chain does not charge fees. Each transaction (except bypass transactions) have to meet the following global fee requirements:

  • All denoms of the paid fees (except zero coins) have to be a subset of the global fee's denom set.
  • All paidfees' contain at least one denom that is present and greater than/or equal to the amount of the same denom in globalfee.

Query Global Fees

CLI queries to retrieve the global fee value:

gaiad q globalfee minimum-gas-prices
# or
gaiad q params subspace globalfee MinimumGasPricesParam

Empty Global Fees and Default Global Fees

When the global fee is not setup, the query will return an empty globalfee list: minimum_gas_prices: []. Junod will use 0ujuno as global fee in this case. This is due to the Juno accepting ujuno as fee denom by default.

Setting Up Global Fees via Gov Proposals

An example of setting up a global fee by a gov proposals is shown below.

gov submit-proposal param-change proposal.json

A proposal.json example:

{
  "title": "Global fees Param Change",
  "description": "Update global fees",
  "changes": [
    {
      "subspace": "globalfee",
      "key": "MinimumGasPricesParam",
      "value": [{"denom":"stake", "amount":"0.002"}, {"denom":"ujuno", "amount": "0.001"}]
    }
  ],
  "deposit": "1000stake"
}

Please note: in the above "value" field, coins must sorted alphabetically by denom.

Min_gas_prices

min_gas_prices are a node's further requirement of fees. Zero coins are removed from min_gas_prices when parsing min_gas_prices, this is different from global fees.

  • If the min_gas_prices set a denom that is not global fees's denom set. This min_gas_prices denom will not be considered when paying fees.
  • If the min_gas_prices have a denom in global fees's denom set, and the min_gas_prices are lower than global fees, the fee still need to meet the global fees.
  • If the min_gas_prices have a denom in global fees's denom set, and the min_gas_prices are higher than global fees, the fee need to meet the min_gas_prices.

Fee Checks

Global fees, min_gas_prices and the paid fees all allow zero coins setup. After parsing the fee coins, zero coins and paid fees will be removed from the min_gas_prices and paid fees.

Only global fees might contain zero coins, which is used to define the allowed denoms of paid fees.

The Fee AnteHandle will take global fees and min_gas_prices and merge them into one combined sdk.Deccoins according to the denoms and amounts of global fees and min_gas_prices.

If the paid fee is a subset of the combined fees set and the paid fee amount is greater than or equal to the required fees amount, the transaction can pass the fee check, otherwise an error will occur.

Bypass Fees Message Types

The above global fee and min_as_prices fee checks do not apply to bypass message types. Transactions of bypass message types are free of fee charge. However, if the bypass type transactions still carry nonzero fees, the denom has to be a subset of denoms that global fees defined.

A node can set up its own bypass message types by modify the configuration parameter bypass-min-fee-msg-types in config/app.toml file. Nodes using app.toml files initialized by gaiad version of v7.0.1 or earlier might not have bypass-min-fee-msg-types, users can insert it before the field [telemetry] in app.toml.

An example:

###############################################################################
###                        Custom Juno Configuration                        ###
###############################################################################
# bypass-min-fee-msg-types defines custom message types the operator may set that
# will bypass minimum fee checks during CheckTx.
#
# Example:
# ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", ...]
bypass-min-fee-msg-types = ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement","/ibc.applications.transfer.v1.MsgTransfer"]

Even though each node can set its own min_gas_prices and bypass-min-fee-msg-types, when the transactions enters a validator's mempool, the transactions carried fees have to satisfy the validator's min_gas_prices and bypass-min-fee-msg-types's requirement in order for the validators to process the transactions.

Examples

Here are a few examples to clarify the relationship between global fees, min_gas_prices and paid fees.

  • Case 1: globalfee=[], min_gas_prices=0.0001ujuno, gas=2000000

    This is the same case as globalfee=0ujuno, min_gas_prices=0.0001ujuno, gas=2000000.

    • paidfee = "2000000 * 0.0001ujuno", pass
    • paidfee = "2000000 * 0.0001ujuno, 0stake", pass
    • paidfee = "2000000 * 0.0001ujuno, 1stake", fail
    • paidfee = "2000000 * 0.0001/2ujuno", fail
    • paidfee = "", pass
  • Case 2: globalfee=[], min_gas_prices="", gas=2000000

    • paidfee = "", pass
    • paidfee = "0ujuno", pass
    • paidfee = "1ujuno", pass
    • paidfee = "0ujuno, 0stake", pass
    • paidfee = "0ujuno, 1stake", fail
  • Case 3: globalfee=0.0002ujuno, min_gas_prices=0.0001ujuno, gas=2000000 (global fee is lower than min_as_price)

    • paidfee = "2000000 * 0.0002ujuno", pass
    • paidfee = "2000000 * 0.0001ujuno", fail
    • paidfee = "2000000 * 0.0002ujuno, 1stake", fail
    • paidfee = "2000000 * 0.0002ujuno, 0stake", pass
    • paidfee = "2000000 * 0.0002stake", fail
    • paidfee = "", fail
    • paidfee = 0ujuno, fail
  • Case 4: globalfee=0.0001ujuno, min_gas_prices=0.0002ujuno, gas=2000000 (global fee is higher than min_as_price)

    • paidfee = "2000000 * 0.0002ujuno", pass
    • paidfee = "2000000 * 0.0001ujuno", fail
    • paidfee = "2000000 * 0.0002ujuno, 1stake", fail
    • paidfee = "2000000 * 0.0002ujuno, 0stake", pass
    • paidfee = "2000000 * 0.0002stake", fail
    • paidfee = "", fail
    • paidfee = 0ujuno, fail
  • Case 5: globalfee=[0ujuno, 1stake], min_gas_prices="", gas=200000.

  • fees="2000000 0ujuno, 2000000 0.5stake", fail, (this is due to fee parsing, zero coins are removed, it equals to paidfees = 0.5stake in this case)

  • paidfees="", pass

  • paidfees="2000000 * 1ujuno, 0.5stake", pass

  • paidfees="0ujuno, 0stake" pass, (due to the parsing of paidfees, it makes paidfees="")

  • paidfees="2000000 * 1stake", pass

  • Case 6: globalfee=[0.001ujuno, 1stake], min_gas_prices=0.002ujuno, gas=200000.

    • paidfee = "2000000 * 0.0002ujuno", pass
    • paidfee = "2000000 * 0.0001ujuno", fail
    • paidfee = "2000000 * 1stake", pass
    • paidfee = "2000000 * 1/2stake", fail
    • paidfee = "2000000 0.0001ujuno, 20000001stake", pass
    • paidfee = "2000000 0.0002atom, 20000001/2stake", pass
    • paidfee = "2000000 0.0001ujuno, 20000001/2stake", fail
  • Case 7:globalfee=[0.0001ujuno], min_gas_prices=0.0002ujuno,1stake, gas=200000.

    bypass-min-fee-msg-types = ["/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"]

    • msg withdraw-all-rewards with paidfee=0ujuno, pass
    • msg withdraw-all-rewards with paidfee=200000 * 0.0001/2ujuno, pass
    • msg withdraw-all-rewards with paidfee=0stake,0photon, pass
    • msg withdraw-all-rewards with paidfee=200000 * 1stake, 0photon, fail

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment