Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix not append logs when tx was reverted #1747

Closed
wants to merge 3 commits into from
Closed

fix: fix not append logs when tx was reverted #1747

wants to merge 3 commits into from

Conversation

graykode
Copy link

@graykode graykode commented Mar 5, 2023

#1746.

What does this PR do?

Skip event logs on failed tx.

Reviewers

Main reviewers:

Codeowner reviewers:

@graykode graykode requested a review from tclemos as a code owner March 5, 2023 11:44
@cla-bot
Copy link

cla-bot bot commented Mar 5, 2023

We require contributors @graykode to read our Contributor License Agreement, please check the CLA document

@tclemos tclemos self-assigned this Mar 6, 2023
@tclemos
Copy link
Contributor

tclemos commented Mar 6, 2023

Hey @graykode thanks for your feedback on this.

I'll take a look into that to make sure we don't return the logs from reverted transactions when calling eth_getLogs.

The solution you propose fixes the problem, but solving it in the RPC layer will add unnecessary overhead to the State layer.

I'll be performing an investigation around this topic to make sure the behavior works as is in Ethereum and also want to try a different solution to reduce the overhead in the State layer.

@graykode
Copy link
Author

graykode commented Mar 6, 2023

@tclemos Cool I'll check it out too in Ethereum

@graykode
Copy link
Author

graykode commented Mar 6, 2023

@tclemos I have a question, https://github.com/0xPolygonHermez/zkevm-node/blob/develop/jsonrpc/endpoints_eth.go#L343 already uses context related to State. is this okay?

@tclemos
Copy link
Contributor

tclemos commented Mar 6, 2023

@tclemos I have a question, https://github.com/0xPolygonHermez/zkevm-node/blob/develop/jsonrpc/endpoints_eth.go#L343 already uses context related to State. is this okay?

yep, the State is where everything is stored and the context is shared from the top layer until the bottom, so we can control the whole request.

@graykode
Copy link
Author

graykode commented Mar 6, 2023

@tclemos Then, isn't this also the overhead caused by using State?

@graykode
Copy link
Author

graykode commented Mar 7, 2023

Also I find bug that failed txs(reverted) are not mined. It was denied by rpc node.

@tclemos
Copy link
Contributor

tclemos commented Mar 7, 2023

Also I find bug that failed txs(reverted) are not mined. It was denied by rpc node.

it was fixed here: #1744

@tclemos
Copy link
Contributor

tclemos commented Mar 7, 2023

@tclemos Then, isn't this also the overhead caused by using State?

No, the overhead is calling the state for every log, we can filter it directly when reading the logs from the db for example, but we could also avoid storing these logs if they are not needed, I still need to investigate if they should affect the state somehow.

@arnaubennassar
Copy link
Member

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Mar 7, 2023
@cla-bot
Copy link

cla-bot bot commented Mar 7, 2023

The cla-bot has been summoned, and re-checked this pull request!

@graykode
Copy link
Author

graykode commented Mar 8, 2023

@tclemos

I checked the code in go-ethereum and found that event logs are not recorded in a block when transactions fail. This causes issues when trying to debug failed transactions using tools like etherscan, which execute traceTransaction when displaying event logs.

Here are the reasons I found:

  1. The makeLog function (in instructions.go) creates a log for each event. It records the log using Addlog (in instructions.go) if the transaction was not failed.
  2. An opcode is run by the evm.interpreter.Run function (in evm.go).
  3. However, the stateDB is rolled back to the snapshot before execution (in evm.go). This means that the logs created by makeLog are not recorded in the block if the transaction fails.

Therefore, I reverted before commit and added a filter where reciept.Status = 1 (txSucceeded) in pgstatestorage: c060e9b

@tclemos
Copy link
Contributor

tclemos commented Mar 8, 2023

Yes, nice investigation.

The approach to filter logs in the query DB is correct when trying to avoid the overhead by calling the DB multiple times, but the change to the DB query is wrong.

Inner join is meant to join tables, so when adding the receipt table to the query, we should be able to join it by matching the tx hash, as we do when we join the table state.transaction to the state.log table, and then, we must add the receipt status condition to the where clause.

So, instead of having this:

INNER JOIN state.receipt r ON r.status = 1

we should have something like this:

INNER JOIN state.receipt r ON r.tx_hash = t.hash
...
WHERE ...
AND r.status = 1

@arnaubennassar
Copy link
Member

@graykode This will be fixed in the executor (the actual EVM implementation), so this logs are not created in the first place.

We expect this changes to reach testnet in ~24 hours. Thanks for the feedback and the effort 💜

@graykode
Copy link
Author

graykode commented Mar 8, 2023

@tclemos Then, can I open new pr about fixing postgresql query. @arnaubennassar

@tclemos
Copy link
Contributor

tclemos commented Mar 12, 2023

@graykode It's not needed, the problem is going to be solved in a step before, the current query will work and the data will be filtered when the tx is executed, not generating logs for reverted TXs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants