I know there is an upcoming change to solidity which will allow the returning of require() calls with a string error message. But I'm wondering if it's possible to do something like this now. Since each node has to run the code up to the revert
point to know that the code reverts, doesn't this mean that the event will get stored in the history still? And if we're operating a node couldn't we see that the event was fired off even inside of a reverted transaction? I'm not an expert on the EVM so maybe I'm missing something crucial but it seems like something like this should be possible.
2 Answers
No, when a revert
occurs, the transaction state changes are thrown away, including any event logs.
This behaviour is defined in the Yellow Paper here:
The A0 bit when w = REVERT is the formal version of what I said above: no logs are recorded in the case of a revert.
If you are running your own node, of course you can do whatever you like. Geth, for example can provide very detailed transaction traces that you can look at and see what happened even for aborted transactions. But none of that will get stored on the main blockchain.
-
Thanks I think this answers my question. The logs are thrown away, but I could trace the transaction locally and recreate the computation and do some analysis and see if an event was fired. Sounds a bit above my head, but thanks!– LsaetherCommented Jan 30, 2018 at 22:39
-
As mentioned in the accepted answer, when you are running your own node you can access traces on reverted transactions via the debug_traceTransaction
RPC endpoint. With this trace you can extract the event logs.
The python eth-event package provides a decode_trace
method to simplify this process:
>>> trace = web3.provider.make_request(
"debug_traceTransaction",
('0x71a7146996957b8a465a4e5dd41951d614254f8271fc9140b875c4fc55dde578', {})
)
>>> eth_event.decode_trace(trace, abi)
[{'name': 'Transfer', 'data': [{'name': 'from', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a'}, {'name': 'to', 'type': 'address', 'value': '0xbd4940951bfa463f8fb6db762e55686f6cfdb73a', 'decoded': True}, {'name': 'tokens', 'type': 'uint256', 'value': 100, 'decoded': True}]}]
Disclosure: I am the creator of eth-event
.