Prevent the contract call transaction from consuming too much energy.
The fee_limit indicates the value of the total energy that a contract caller can tolerate at most for this transaction. The base 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 1000 sun 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 10 sun).
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 as an upper limit.
There are some situations which causes 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 enum 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.
The contract function is too complex or the performance of the SR node fluctuates.
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.
Base58 format: T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb
HexString format: 410000000000000000000000000000000000000000
First, according to txid, query the contractResult field in the result returned through the wallet/gettrasactioninfobyid interface. If the field is not empty, you can see the abi code value of the message, convert the code value into a string, and find the reason for the error.
For example, txid:e5e013e81cb50a4c495a11c8130ad165a4e98d89b9e3fb5b79e6111bf23b31ed
Return contractResult data:
Converting 1e536166654d6174683a207375627472616374696f6e206f766572666c6f77 into a string is: SafeMath: subtraction overflow, this transaction is because the transfer address overflowed during the subtraction operation during the transfer. The specific failure may be caused by insufficient balance. You need to check the address balance and transfer amount，Other errors can be checked according to the specific reason of the error.
If the contractResult is empty, it may be caused by the failure of the require assertion without message in the contract. For details, please refer to the document and view the contract source code for analysis.
- The bandwidth is calculated based on the number of bytes encoded by the transaction protobuf.
- Energy is deducted based on the instructions executed by the contract. Different instructions are deducted differently. The more complex the contract, the more energy will be consumed. The energy consumed by the current contract can be estimated by testing on the testnet or viewing the previous historical calls of the contract through tronscan.
Resource model can refer to the document
The transaction broadcast is successful but not on the chain because the transaction is not broadcast to the SR node because of the node's network or other unknown reasons. In this case, because the transaction has a validity period, it is best to add a delay judgment, and add it after the transaction validity period. If a little extra time is not on the chain, it can be judged that the transaction has exceeded the validity period, and the transaction can be initiated again, or the transaction can be rebroadcast within the validity period.
Updated 24 days ago