simplify computation

This commit is contained in:
andri lim 2020-01-30 17:26:08 +07:00 committed by zah
parent 8564e9532b
commit 1cd9353faa
3 changed files with 2 additions and 21 deletions

View File

@ -337,26 +337,10 @@ proc execSelfDestruct*(c: Computation, beneficiary: EthAddress) =
proc addLogEntry*(c: Computation, log: Log) {.inline.} = proc addLogEntry*(c: Computation, log: Log) {.inline.} =
c.logEntries.add(log) c.logEntries.add(log)
proc getSuicides*(c: Computation): HashSet[EthAddress] =
if c.isSuccess:
result = c.suicides
proc getGasRefund*(c: Computation): GasInt = proc getGasRefund*(c: Computation): GasInt =
if c.isSuccess: if c.isSuccess:
result = c.gasMeter.gasRefunded result = c.gasMeter.gasRefunded
proc getGasUsed*(c: Computation): GasInt =
if c.shouldBurnGas:
result = c.msg.gas
else:
result = max(0, c.msg.gas - c.gasMeter.gasRemaining)
proc getGasRemaining*(c: Computation): GasInt =
if c.shouldBurnGas:
result = 0
else:
result = c.gasMeter.gasRemaining
proc refundSelfDestruct*(c: Computation) = proc refundSelfDestruct*(c: Computation) =
let cost = gasFees[c.fork][RefundSelfDestruct] let cost = gasFees[c.fork][RefundSelfDestruct]
c.gasMeter.refundGas(cost * c.suicides.len) c.gasMeter.refundGas(cost * c.suicides.len)

View File

@ -106,9 +106,6 @@ proc getTracingResult*(vmState: BaseVMState): JsonNode =
doAssert(vmState.tracingEnabled) doAssert(vmState.tracingEnabled)
vmState.tracer.trace vmState.tracer.trace
proc addLogs*(vmState: BaseVMState, logs: seq[Log]) =
shallowCopy(vmState.logEntries, logs)
proc getAndClearLogEntries*(vmState: BaseVMState): seq[Log] = proc getAndClearLogEntries*(vmState: BaseVMState): seq[Log] =
shallowCopy(result, vmState.logEntries) shallowCopy(result, vmState.logEntries)
vmState.logEntries = @[] vmState.logEntries = @[]

View File

@ -82,8 +82,8 @@ proc execComputation*(c: Computation) =
if c.isSuccess: if c.isSuccess:
c.refundSelfDestruct() c.refundSelfDestruct()
c.vmState.suicides = c.getSuicides() shallowCopy(c.vmState.suicides, c.suicides)
c.vmState.addLogs(c.logEntries) shallowCopy(c.vmState.logEntries, c.logEntries)
c.vmstate.status = c.isSuccess c.vmstate.status = c.isSuccess