mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 21:04:11 +00:00
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:
parent
52fd8b8129
commit
4187eb1959
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -16,7 +16,6 @@ else:
|
||||
vm2/state_transactions as vmx
|
||||
|
||||
export
|
||||
vmx.execComputation,
|
||||
vmx.refundGas
|
||||
vmx.execComputation
|
||||
|
||||
# End
|
||||
|
Loading…
x
Reference in New Issue
Block a user