mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-04 00:05:22 +00:00
simplify 'gasUsed' and 'refundGas'
This commit is contained in:
parent
d9991b1e8b
commit
270854a5aa
@ -13,21 +13,22 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
|
|||||||
trace "Sender", sender
|
trace "Sender", sender
|
||||||
trace "txHash", rlpHash = tx.rlpHash
|
trace "txHash", rlpHash = tx.rlpHash
|
||||||
|
|
||||||
var gasUsed = 0.GasInt
|
|
||||||
if validateTransaction(vmState, tx, sender, fork):
|
if validateTransaction(vmState, tx, sender, fork):
|
||||||
gasUsed = tx.gasLimit
|
|
||||||
var c = setupComputation(vmState, tx, sender, fork)
|
var c = setupComputation(vmState, tx, sender, fork)
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
db.subBalance(sender, tx.gasLimit.u256 * tx.gasPrice.u256)
|
db.subBalance(sender, tx.gasLimit.u256 * tx.gasPrice.u256)
|
||||||
execComputation(c)
|
execComputation(c)
|
||||||
if not c.shouldBurnGas:
|
|
||||||
gasUsed = c.refundGas(tx, sender)
|
|
||||||
|
|
||||||
vmState.cumulativeGasUsed += gasUsed
|
result = tx.gasLimit
|
||||||
|
if not c.shouldBurnGas:
|
||||||
|
c.refundGas(tx, sender)
|
||||||
|
result -= c.gasMeter.gasRemaining
|
||||||
|
|
||||||
|
vmState.cumulativeGasUsed += result
|
||||||
|
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
# miner fee
|
# miner fee
|
||||||
let txFee = gasUsed.u256 * tx.gasPrice.u256
|
let txFee = result.u256 * tx.gasPrice.u256
|
||||||
db.addBalance(vmState.blockHeader.coinbase, txFee)
|
db.addBalance(vmState.blockHeader.coinbase, txFee)
|
||||||
|
|
||||||
for deletedAccount in vmState.suicides:
|
for deletedAccount in vmState.suicides:
|
||||||
@ -42,7 +43,6 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
|
|||||||
db.deleteAccount(account)
|
db.deleteAccount(account)
|
||||||
|
|
||||||
vmState.accountDb.updateOriginalRoot()
|
vmState.accountDb.updateOriginalRoot()
|
||||||
result = gasUsed
|
|
||||||
|
|
||||||
type
|
type
|
||||||
# TODO: these types need to be removed
|
# TODO: these types need to be removed
|
||||||
|
@ -84,17 +84,11 @@ proc execComputation*(c: Computation) =
|
|||||||
|
|
||||||
c.vmstate.status = c.isSuccess
|
c.vmstate.status = c.isSuccess
|
||||||
|
|
||||||
proc refundGas*(c: Computation, tx: Transaction, sender: EthAddress): GasInt =
|
proc refundGas*(c: Computation, tx: Transaction, sender: EthAddress) =
|
||||||
let
|
let maxRefund = (tx.gasLimit - c.gasMeter.gasRemaining) div 2
|
||||||
gasRemaining = c.gasMeter.gasRemaining
|
c.gasMeter.returnGas min(c.getGasRefund(), maxRefund)
|
||||||
gasRefunded = c.getGasRefund()
|
|
||||||
gasUsed = tx.gasLimit - gasRemaining
|
|
||||||
gasRefund = min(gasRefunded, gasUsed div 2)
|
|
||||||
|
|
||||||
c.vmState.mutateStateDB:
|
c.vmState.mutateStateDB:
|
||||||
db.addBalance(sender, (gasRemaining + gasRefund).u256 * tx.gasPrice.u256)
|
db.addBalance(sender, c.gasMeter.gasRemaining.u256 * tx.gasPrice.u256)
|
||||||
|
|
||||||
result = gasUsed - gasRefund
|
|
||||||
|
|
||||||
#[
|
#[
|
||||||
method executeTransaction(vmState: BaseVMState, transaction: Transaction): (Computation, BlockHeader) {.base.}=
|
method executeTransaction(vmState: BaseVMState, transaction: Transaction): (Computation, BlockHeader) {.base.}=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user