Why Energey cost is different when transfer USDT in TRON network.steemCreated with Sketch.

in CryptoDog4 years ago

I believe this issue has confused many developers. I sufferred this for a long time when i first start working on TRON network. even after my development work is done, i still do not understand why is that. i have asked help from my other experienced engineers, seems they also dont fully understand this issue. since it will not block any development work, so they would not spend too much time on that.

group-111-500x109.png
Today we will take a look at what caused these differences.

Phenomenon and Issue

First, let's take a look at several common energy consumptions in USDT transfers. After browsing the recent transactions of the USDT contract, I found that the energy consumption is mainly in the following two situations. The first case is the most common case, which is 14,631. The second case is not as probable as the first case, but it is also a frequently seen consumption, 29631.

  1. 14631
    Example TX:
    image-20210112171335170.png

  2. 29631
    Example TX:
    image-20210112171411708.png

To know why there is such a difference, we first need to understand the calculation principle of energy.

Energy calculation principle

  • How much energy does the entire network have
    From the official TRON document, the total energy of TRON's entire network is 50_000_000_000, and this energy will be divided proportionally according to the number of users frozen TRX and the total number of frozen TRX in the entire network. That is:

Account energy limit = frozen TRX for energy/total amount of frozen TRX for energy acquisition in the entire network * 50_000_000_000.

  • Energy recovery principle:
    The energy consumed will be smoothly reduced to 0 within 24 hours. How to understand it, for example as follows.

    • The user has a total energy of 10,000.

    • The user consumed 5000 energy at 03:00. At this time, the remaining energy of the user is 5000

    • Assuming that the account does not have any other energy consumption operations for the next 12 hours, the energy available to the user at 15:00 is

      (1-(15-3)/24)*5000+5000=7500

    • Similarly, after 24 hours, the user's available energy will become 10,000.

  • Energy cost calculation method
    After the contract is compiled, it will be converted into OpCode, and the calling cost of different OpCode is different. Specific cost consumption can refer to the code: https://github.com/tronprotocol/java-tron/blob/develop/actuator/src/main/java/org/tron/core/vm/OpCode.java
    Energy is calculated and deducted according to the instructions executed by the contract. Since different instructions are deducted differently, the more complex the contract, the more energy will be consumed. Refined to the functions in the contract, in most cases, the energy consumed by executing the same function of the same contract is the same. So in most cases, you can easily know how much energy each function consumes by referring to the transaction records of the contract.

Current problem analysis

Now we are back to the topic. As mentioned earlier, since in most cases, the energy consumed by the same function is the same, why are there the problems mentioned above?

Let's first look at an introduction from the official document:
image-20210115144131781.png

Let's take a look at the difference between the energy consumed in the above 2 transactions, 29631-14631 = 15000. Comparing the table above, it can be seen that the difference is exactly 15,000. Seeing this, I believe everyone already understands the reason. The SSTORE operation is required in the final transfer process. The energy consumption of this operation is not fixed but depends on the state of the operation object. If the operated object is not zero, only 5000 energy will be consumed. If the operating object is 0, then 20000 energy will be consumed.

Then we are here to summarize:

  1. For the function TRANSFER, val represents the TOKEN balance corresponding to the address.
  2. If the balance of the address is 0, 20000 energy is consumed.
  3. If the balance of the address is not 0, only 5000 energy is consumed.

This is the fundamental reason why energy consumption is different for the same transfer function of USDT.

other issues

Finally, let's take a look at why the amount of TRX burned by paying the same energy is different. Take a look at this transaction. It is also 14631 energy. This transaction only burned 0.014631 TRX, while the previous transaction burned 0.58524 TRX.

image-20210112171818344.png

In fact, this problem is very simple. Since the energy consumption is the same, we only need to see if the unit price of energy has changed.

On TRON, the unit price of energy and bandwidth can be modified through the proposal. After checking the proposal history, it is not difficult to find that the following two voting requests are about energy and bandwidth costs, and they have all taken effect. Since the effective date of the proposal, the energy cost has changed from 0.00001 to 0.00004. Comparing the above data, it is not difficult to understand why burning TRX has become 4 times than the old one. Details of the proposal are as follows:

https://tronscan.org/#/proposal/47

https://tronscan.org/#/proposal/48

to sum up

The above is the main content of this article, I hope to help you understand this problem.

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 62934.10
ETH 2452.99
USDT 1.00
SBD 2.66