diff --git a/nimbus/vm/interpreter_dispatch.nim b/nimbus/vm/interpreter_dispatch.nim index 22b87faee..008be60b2 100644 --- a/nimbus/vm/interpreter_dispatch.nim +++ b/nimbus/vm/interpreter_dispatch.nim @@ -300,3 +300,7 @@ proc executeOpcodes(computation: BaseComputation) = let msg = getCurrentExceptionMsg() computation.setError(&"Opcode Dispatch Error msg={msg}, depth={computation.msg.depth}", true) computation.nextProc() + + if computation.isError(): + if computation.tracingEnabled: computation.traceError() + debug "executeOpcodes error", msg=computation.error.info diff --git a/nimbus/vm/transaction_tracer.nim b/nimbus/vm/transaction_tracer.nim index bdc49638e..311f642cd 100644 --- a/nimbus/vm/transaction_tracer.nim +++ b/nimbus/vm/transaction_tracer.nim @@ -120,9 +120,10 @@ proc traceError*(tracer: var TransactionTracer, c: BaseComputation) = j["error"] = %(c.error.info) trace "Error", json = j.pretty() - # TODO: figure out how to get gasCost - # when contract execution failed before traceOpCodeEnded called - # because exception raised - #j["gasCost"] = % + # even though the gasCost is incorrect, + # we have something to display, + # it is an error anyway + let gasRemaining = j["gas"].getInt() + j["gasCost"] = %(gasRemaining - c.gasMeter.gasRemaining) tracer.trace["failed"] = %true diff --git a/nimbus/vm_state_transactions.nim b/nimbus/vm_state_transactions.nim index 790449a29..9ba36d379 100644 --- a/nimbus/vm_state_transactions.nim +++ b/nimbus/vm_state_transactions.nim @@ -74,7 +74,7 @@ proc execComputation*(computation: var BaseComputation): bool = for deletedAccount in computation.accountsForDeletion: db.deleteAccount deletedAccount inc suicidedCount - + # FIXME: hook this into actual RefundSelfDestruct const RefundSelfDestruct = 24_000 computation.gasMeter.refundGas(RefundSelfDestruct * suicidedCount) @@ -82,8 +82,6 @@ proc execComputation*(computation: var BaseComputation): bool = result = computation.isSuccess if result: computation.vmState.addLogs(computation.logEntries) - else: - if computation.tracingEnabled: computation.traceError() proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt = let diff --git a/tests/fixtures/TracerTests/block46402.json b/tests/fixtures/TracerTests/block46402.json index 46b0d28d6..90514db11 100644 --- a/tests/fixtures/TracerTests/block46402.json +++ b/tests/fixtures/TracerTests/block46402.json @@ -283,7 +283,8 @@ "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000060" ], - "error": "Opcode Dispatch Error msg=Out of gas: Needed 20000 - Remaining 412 - Reason: SSTORE: 9a049f5d18c239efaa258af9f3e7002949a977a0[0] -> 924236965777326770894530693462975209021625492404 (0), depth=0" + "error": "Opcode Dispatch Error msg=Out of gas: Needed 20000 - Remaining 412 - Reason: SSTORE: 9a049f5d18c239efaa258af9f3e7002949a977a0[0] -> 924236965777326770894530693462975209021625492404 (0), depth=0", + "gasCost": 0 } ], "stateDiff": { @@ -704,7 +705,8 @@ "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000060" ], - "error": "Opcode Dispatch Error msg=Out of gas: Needed 20000 - Remaining 412 - Reason: SSTORE: 9a049f5d18c239efaa258af9f3e7002949a977a0[0] -> 924236965777326770894530693462975209021625492404 (0), depth=0" + "error": "Opcode Dispatch Error msg=Out of gas: Needed 20000 - Remaining 412 - Reason: SSTORE: 9a049f5d18c239efaa258af9f3e7002949a977a0[0] -> 924236965777326770894530693462975209021625492404 (0), depth=0", + "gasCost": 0 } ] },