TRON Adaptive Energy Model Analysis

TRON Core Devs
TRON
Published in
5 min readNov 14, 2019

Introduction

TRON Odyssey v3.5 covers 6 major upgrades that will significantly improve the performance of the TRON network and remove the access barriers for third-party developers. The adaptive adjustment of the Total Energy Limit (Energy limit) of TRON network is one of them. By allowing the Energy limit to fluctuate based on the current Internet status, this upgrade has made the Energy consumption in the TRON network more efficient. Now we will walk you through the details of implementing this proposal.

Background

Before the proposal that allows adaptive adjustment of Energy limit took effect, TRON held a fixed amount of Energy supply. This will cause waste and curb diversity on the entire TRON network in cases when Energy is hoarded and left unused by some developers while badly needed by others.

As a solution, TRON proposed Adaptive Adjustment of Energy Limit in version 3.5. The proposal is planned to be approved by the end of November.

What is Adaptive Adjustment of Energy Limit

About Energy

First, let’s talk about Energy.

Creating and running smart contracts consume Energy. Like running a program, smart contracts have to operate in the virtual machine, which takes up memory and CPU resources that expand with higher contract complexity. Consumption of such resources in the TRON network is measured by Energy.

Obtain Energy

In addition to the free Energy, users can also obtain Energy by freezing TRX:

Energy obtained by the user = TRX frozen by the user for Energy * Total Energy Limit of TRON network / total TRX frozen in the network for Energy

Users acquire Energy in proportion to the amount of TRX they freeze. The more they freeze, the more Energy they receive. In other words, users exchange TRX for Energy at a price equal to the reciprocal of the latter part of the formula above: Total Energy Limit of TRON network / Total amount of TRX frozen in the network for Energy. In this sense, changing Energy limit is essentially an adjustment of Energy price.

Note that there are no Exchange or Price in real cases. In the TRON network, users freeze TRX first (at which point the value in the above formula has been determined if we take away the TRX frozen by later users), and have the amount of Energy they can consume calculated when using it. The calculation is always done at the moment of consumption.

Users can get their frozen TRX back by unfreezing them (at least 3 frozen days). In other words, obtaining Energy won’t cost users any TRX.

Energy Limit Adjustment

The Energy limit is the max supply of Energy on the TRON network. Given the fixed overall Energy supply, developers who receive Energy but choose not to use it will limit the Energy available to other developers. With the feature of adaptive adjustment in place, developers could obtain more Energy at lower costs when there is less demand for Energy on the network. Therefore, to some extent, this mechanism could drive the costs of Energy down.

In addition, the introduction of adaptive adjustment of Energy limit helps build a sound underlying infrastructure for DApp operation and development, as DApp operate with the support of smart contracts.

Underlying technology

Obtain Energy (new version)

The amount of Energy obtained by a user can be calculated with the following formula:

USER_ENERGY_LIMIT = USER_ENERGY_WEIGHT * TOTAL_ENERGY_LIMIT / TOTAL_ENERGY_WEIGHT

USER_ENERGY_LIMIT : Energy obtained by the user

USER_ENERGY_WEIGHT : TRX frozen by the user

TOTAL_ENERGY_LIMIT : The max supply of Energy on the TRON network within 24hs. It is a fixed value determined and modified by Proposal №19.

TOTAL_ENERGY_WEIGHT : The total amount of TRX
frozen on TRON network for Energy

It is evident that we only have to change one variant, TOTAL_ENERGY_LIMIT, in the formula so as to adjust the Energy available to users.

Reasoning

To avoid confusion with the previous approach, a new expression is used ( TOTAL_ENERGY_LIMIT is replaced by TOTAL_ENERGY_CURRENT_LIMIT )

USER_ENERGY_LIMIT = USER_ENERGY_WEIGHT * TOTAL_ENERGY_CURRENT_LIMIT / TOTAL_ENERGY _WEIGHT

The adjustment of Energy limit, in essence, is a process that changes the value of TOTAL_ENERGY_CURRENT_LIMIT by certain rules. We compare the Energy (TOTAL_ENERGY_AVERAGE_USAGE) consumed within a certain period of time (say 1 min) with the value of a TARGET (TOTAL_ENERGY_TARGET_LIMIT) to adjust TOTAL_ENERGY_CURRENT_LIMIT.

Implementation Logic

Total Energy consumed in the network for producing the last 20 blocks (in one minute) is marked as TOTAL_ENERGY_AVERAGE_USAGE. After a block is produced, a new TOTAL_ENERGY_AVERAGE_USAGE is calculated based on the previous TOTAL_ENERGY_AVERAGE_USAGE and Energy used for producing the current block(blockEnergyUsage). This number is then compared with TOTAL_ENERGY_TARGET_LIMIT so as to adjust TOTAL_ENERGY_CURRENT_LIMIT.

When TOTAL_ENERGY_AVERAGE_USAGE is greater than TOTAL_ENERGY_TARGET_LIMIT, demand for Energy is larger, thus the unit price needs to be higher by lowering TOTAL_ENERGY_CURRENT_LIMIT. Instead, if TOTAL_ENERGY_TARGET_LIMIT is larger, Energy is consumed less for the moment, and price should be set lower by raising TOTAL_ENERGY_CURRENT_LIMIT.

It’s worth noting that in order to protect developers’ interests, TOTAL_ENERGY_CURRENT_LIMIT only ranges between TOTAL_ENERGY_LIMIT and 50 * TOTAL_ENERGY_LIMIT. This means that users will receive Energy no less than their previous level, with a max 50 times increase.

Code interpreting

We will illustrate the whole process with pseudo code.

● Energy available to users.

def get_user_energy(account):# TRX frozen by usersenergy_weight = get_weight_by_balance(account.froze_balance)# Energy users receive by freezingTRX 
user_total_energy = energy_weight * TOTAL_ENERGY_CURRENT_LIMIT / TOTAL_ENERGY_ WEIGHT
# Energy already consumed by users
user_used_energy = account.get_energy_usage()
# Energy available for use
return (user_total_energy — user_used_energy)

● Adaptive adjustment of Energy limit

def process_block(block):# processing blocks

# adjusting Energy upper limit
if allow_adaptive_energy:
# Energy usage of the current block
block_energy_usage = block.get_block_energy_usage()
# Total Energy usage for the last 20 blocks (in one minute) TOTAL_ENERGY_AVERAGE_USAGE = TOTAL_ENERGY_AVERAGE_USAGE * 19/20 + block_en ergy_usage# Lower upper limit to 99/100 of the original one
if TOTAL_ENERGY_AVERAGE_USAGE > TOTAL_ENERGY_TARGET_LIMIT:
TOTAL_ENERGY_CURRENT_LIMIT = TOTAL_ENERGY_CURRENT_LIMIT * 99/100# raise upper limit to 1000/999 of the original one
else:
TOTAL_ENERGY_CURRENT_LIMIT = TOTAL_ENERGY_CURRENT_LIMIT * 1000/999

Regarding the above process, TOTAL_ENERGY_CURRENT_LIMIT must be set between TOTAL_ENERGY_LIMIT and 50*TOTAL_ENERGY_LIMIT. And the current maximum multiplier (ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER), 50, could be modified through proposals.

Initiate the adaptive adjustment of Energy limit

According to the content above, it takes both the value of TOTAL_ENERGY_TARGET_LIMIT and the ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER to initiate this proposal.

def do_allow_apative_energy:# Half of the Energy upper limit available in the TRON network in one minute is decided by the TOTAL_ENERGY_LIMIT# There are 1440 minutes in 24 hours(60*24); further split a minute in half and you get 2880 (1440*2)ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO = 2880TOTAL_ENERGY_TARGET_LIMIT = TOTAL_ENERGY_LIMIT / ADAPTIVE_RESOURCE_LIMIT_TARGE T_RATIOADAPTIVE_RESOURCE_LIMIT_MULTIPLIER = 50

While ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER is modified by other proposals, TOTAL_ENERGY_TARGET_LIMIT changes along with it, TOTAL_ENERGY_TARGET_LIMIT =

TOTAL_ENERGY_LIMIT / ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO

Conclusion

To conclude, the adaptive adjustment of Energy limit essentially adopts a mathematical approach — change the variant (CURRENT) in the formula to adjust the value indicating Energy obtained by the user and compare the value of AVERAGE with that of TARGET within a certain period of time so as to adjust the limit dynamically.

References

https://github.com/tronprotocol/tips/blob/master/tip-17.md

For more information:

Github: https://github.com/tronprotocol

Telegram: https://t.me/troncoredevscommunity

--

--