1.Why send the fee_limit field when sending a transaction to call a smart contract?

Answer
Prevent the contract call transaction from consuming too much energy

Explanation
The fee_limit indicates the value of the total energy that the contract caller can tolerate at most for this transaction. The unit is sun, and the maximum value can be set to 1e9,If the user does not set fee_limit, the default value is 0. For example, if the fee_limit is set to 1000sun in the transaction, it means that the contract caller will endure the transaction and consume up to 100 energy (the current unit price of energy is 10sun).

If the amount of energy consumed by the transaction execution exceeds the fee_limit*energy unit price, contract execution will be stopped and an OUT_OF_ENERGY error will be triggered.

In some contract functions, there will be complex loops. If the user calls it by mistake without knowing it, it may cause the user to consume too much energy, so the user can set this fee_limit field to set an upper limit.

There are some situations that cause all fee_limit to be deducted:

  • Illegal instruction encountered during contract execution
  • Contract call timeout, trigger OUT_OF_TIME error
  • if the array index you are accessing is too large or negative (for example x[i] where i >= x.length or i < 0).
  • If you access a fixed length of bytesN the index is too large or negative.
  • If you use zero as a divisor for division or modulo operations (for example 5 / 0 or 23 % 0 ).
  • If you shift the negative digit.
  • If you convert a too large or negative value to an enumerated type.
  • If you call an uninitialized internal function type variable.
  • If you call the argument of the assert (expression), and the final result is false.
  • If a JVMStackOverFlowException occurs.
  • If an OutofMem exception occurs, that is, memory exceeded 3M.
  • During contract operation, an overflow occurs, such as addition.

At present, TRON has a global setting. The execution time of calling smart contract transactions cannot exceed 50ms. This 50ms parameter can be modified by SR voting. If the contract code is very complex and the execution time exceeds 50ms, it will trigger an OUT_OF_TIME error and deduct all fee_limit fees.

2.Why trigger OUT_OF_TIME error when calling contract function?

Answer
The contract function is too complex or the performance of the SR node fluctuates.

Explanation
At present, TRON has a global setting. The execution time of calling smart contract transactions cannot exceed 50ms. This 50ms parameter can be modified by SR voting. If the contract code is very complex and the execution time exceeds 50ms, it will trigger an OUT_OF_TIME error and deduct all fee_limit fees.

If the same contract function sometimes triggers the OUT_OF_TIME error, sometimes it does not trigger the OUT_OF_TIME error, indicating that the complexity of the contract code is at a critical value. Because the machine performance of different SRs is different, it will cause intermittent triggering.

In addition, it should be noted that due to the fluctuation of SR machine performance, there will be a small probability that the contract function call with very low complexity will also trigger the OUT_OF_TIME error. It is recommended that users set the appropriate fee_limit according to the contract complexity to prevent excessive losses caused by excessive setting of fee_limit.