Transaction: Prepare txRefundGas to support txCallEvm

There's only one call left to `refundGas(Transaction, ...)`, and the
similarity to the tail of `rpcEstimateGas` is obvious.

Gather this into `call_evm`: `refundGas` -> `txRefundGas`.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-03 19:19:34 +01:00
parent 52fd8b8129
commit 4187eb1959
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
4 changed files with 11 additions and 10 deletions

View File

@ -72,7 +72,7 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
result = tx.gasLimit
if not c.shouldBurnGas:
c.refundGas(tx, sender)
txRefundGas(tx, sender, c)
result -= c.gasMeter.gasRemaining
vmState.cumulativeGasUsed += result

View File

@ -10,7 +10,8 @@ import
eth/common/eth_types, stint, options, stew/byteutils,
".."/[vm_types, vm_types2, vm_state, vm_computation, utils],
".."/[db/db_chain, config, vm_state_transactions, rpc/hexstrings],
".."/[db/accounts_cache, transaction, vm_precompiles, vm_gas_costs], eth/trie/db
".."/[db/accounts_cache, transaction, vm_precompiles, vm_gas_costs], eth/trie/db,
".."/vm_internals
type
RpcCallData* = object
@ -172,3 +173,10 @@ proc txSetupComputation*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
result = newComputation(vmState, msg)
doAssert result.isOriginComputation
proc txRefundGas*(tx: Transaction, sender: EthAddress, c: Computation) =
let maxRefund = (tx.gasLimit - c.gasMeter.gasRemaining) div 2
let refund = min(c.getGasRefund(), maxRefund)
c.gasMeter.returnGas(refund)
c.vmState.mutateStateDB:
db.addBalance(sender, c.gasMeter.gasRemaining.u256 * tx.gasPrice.u256)

View File

@ -25,9 +25,3 @@ proc execComputation*(c: Computation) =
c.vmState.touchedAccounts.incl c.touchedAccounts
c.vmstate.status = c.isSuccess
proc refundGas*(c: Computation, tx: Transaction, sender: EthAddress) =
let maxRefund = (tx.gasLimit - c.gasMeter.gasRemaining) div 2
c.gasMeter.returnGas min(c.getGasRefund(), maxRefund)
c.vmState.mutateStateDB:
db.addBalance(sender, c.gasMeter.gasRemaining.u256 * tx.gasPrice.u256)

View File

@ -16,7 +16,6 @@ else:
vm2/state_transactions as vmx
export
vmx.execComputation,
vmx.refundGas
vmx.execComputation
# End