Change gas logic (Qtum Core / QTUMCORE-72) #146
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We need a minor change into how we handle gasLimit and gasPrice in our current implementation in light of issue #113
The changes must be made on Qtum side, no change to the EVM submodule should be required
The new logic will be as follows:
1- when a Qtum tx is received, we make sure the fee covers gasLimit*gasPrice otherwise reject it
2- we pass the gasLimit to the EVM and pass 1 as gasPrice
3- after we get the execution results, two cases:
if an exception occurs (including out of gas), we consume all the gas (gasLimitgasPrice)
if the transaction is successfully executed, we consume gasUsedgasPrice and send refund (gasLimit-gasUsed)*gasPrice ...
This will allow us to use gasLimit as intended in Qtum, and use gasPrice after the execution to charge the right values to the sender.
Example:
for example, if we call a contract with a gas limit of 50000 and a price of 0.00001, first we check if the tx fee is >= 500000.00001=0.5 then we pass 50000 to the EVM as gasLimit and 1 as gas price, let’s say the gas used was just 20000, then after execution, we should pay the miner 200000.00001=0.2 and refund the sender 30000*0.00001=0.3