Consider the following situation: my function can be divided into 2 parts
- Always consumes constant gas;
- Always results in a refund of
0 < R < 1500000gas.
After the second part had happened, but before the end of a function call, how do I know the value of
The problem is that the
msg.gas(which is remaining gas) doesn't account for the refund(cause the refund cannot be used inside the transaction itself). Due to this the following approach will fail:
uint startGas = msg.gas; // e.g. 100000 gas delete myArray; // consumes 40000 gas, but will refund 20000 in the end uint gasUsed = startGas - msg.gas + 21500; // gasUsed = 100000 - 60000 + 21500 == 61500 gas (21500 is for initial tx and function call)
We estimated that the gas spent for execution will be
61500, but in fact, after the refund, transaction receipt gasUsed value will be
I wonder if there is something like
msg.refundGas is planned, or should I create a feature request?