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: logging with multiple(external) logs #751

Merged
merged 9 commits into from
Dec 22, 2022
Merged

Conversation

hal3e
Copy link
Contributor

@hal3e hal3e commented Dec 19, 2022

Fixes two bugs we had with decoding logs from RevertTransactionError:

  1. Take the last log instead of the first log.
    If we had several log statements before the require we would take the first one and that would be wrong. The last log should be the log from the require statement.

  2. If we had a script calling a contract which was logging some variables our decode would fail. This was because we could not find the logId in our LogDecoder. Now we just do a filter_map and take only the logs we have in our LogDecoder.

Added test:

  • logs before require
  • e2e test where script is calling a contract that makes some logs

@hal3e hal3e added the bug Something isn't working label Dec 19, 2022
@hal3e hal3e requested a review from a team December 19, 2022 18:31
@hal3e hal3e self-assigned this Dec 19, 2022
Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm whether I understood this correctly:

If we had a script calling a contract which was logging some variables our decode would fail. This was because we could not find the logId in our LogDecoder.

Is this the case where we load a (foreign-non-SDK-generated) script binary and execute it but it turns out the script bytecode had called a contract that logged something but we can't decode it since we don't have the contract's abi-json?

If so, do we have a test covering this scenario?

packages/fuels-contract/src/logs.rs Outdated Show resolved Hide resolved
@hal3e
Copy link
Contributor Author

hal3e commented Dec 20, 2022

Can you confirm whether I understood this correctly:

If we had a script calling a contract which was logging some variables our decode would fail. This was because we could not find the logId in our LogDecoder.

Is this the case where we load a (foreign-non-SDK-generated) script binary and execute it but it turns out the script bytecode had called a contract that logged something but we can't decode it since we don't have the contract's abi-json?

If so, do we have a test covering this scenario?

Yes that was the case. We would have a (contract_id, log_id) entry that was not in our LogDecoder. For more clarity the problem was not that it was not there but how we handled that case. Previously, we would return an error and that would mean that we can not decode a log and that we return the initial revert error message. Now, we just filter them out. We can do this because the require will generate a log and there will be a valid log_id in the receipts. IMO we do not need a test that shows that it filters out non existing entries.. It is obvious from the code.

That said, it would be cool if we could use your shared types PR, where we can simultaneously load several contracts and scripts, to combine all LogDecoders into one and pass it down. This would mean that we can do complex logging.

@segfault-magnet
Copy link
Contributor

segfault-magnet commented Dec 20, 2022

Can you confirm whether I understood this correctly:

If we had a script calling a contract which was logging some variables our decode would fail. This was because we could not find the logId in our LogDecoder.

Is this the case where we load a (foreign-non-SDK-generated) script binary and execute it but it turns out the script bytecode had called a contract that logged something but we can't decode it since we don't have the contract's abi-json?
If so, do we have a test covering this scenario?

Yes that was the case. We would have a (contract_id, log_id) entry that was not in our LogDecoder. For more clarity the problem was not that it was not there but how we handled that case. Previously, we would return an error and that would mean that we can not decode a log and that we return the initial revert error message. Now, we just filter them out. We can do this because the require will generate a log and there will be a valid log_id in the receipts.

IMO we do not need a test that shows that it filters out non existing entries.. It is obvious from the code.

That said, it would be cool if we could use your shared types PR, where we can simultaneously load several contracts and scripts, to combine all LogDecoders into one and pass it down. This would mean that we can do complex logging.

Tnx for the clarification.

We filter out/ignore log receipts for which we do not know the type. And the only way that could happen is by running foreign contract calling scripts.

We can do this because the require will generate a log and there will be a valid log_id in the receipts

I'm not sure what you wanted to say. We must filter out precisely because we don't have the mapping for those log_ids. Presumably, you're saying that the way log decoding works is by having the log_id->type mapping provided in the json-abi. I'm ok with that, it's just that the filtering is introduced for those cases where we don't have the json-abi for the contract that logged the log.

IMO we do not need a test that shows that it filters out non-existing entries. It is obvious from the code.

It has naught to do with clarity. We have behavior where we're willing to ignore invalid/stray log receipts but we're (possibly) not testing it. So this fix will not have any protection against regression.

@hal3e
Copy link
Contributor Author

hal3e commented Dec 20, 2022

Makes sense. I will add a unit test for this.

@hal3e
Copy link
Contributor Author

hal3e commented Dec 21, 2022

At the end I decided to add a e2e test as we do not have any test where a script is calling a contract.

@hal3e hal3e requested review from segfault-magnet and a team December 21, 2022 10:17
@hal3e hal3e changed the title fix: decode revert log with multiple logs fix: log with multiple(external) logs Dec 21, 2022
@hal3e hal3e changed the title fix: log with multiple(external) logs fix: logging with multiple(external) logs Dec 21, 2022
Co-authored-by: Ahmed Sagdati <37515857+segfault-magnet@users.noreply.github.com>
Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@hal3e hal3e merged commit b08c8a8 into master Dec 22, 2022
@hal3e hal3e deleted the hal3e/revert-log-log branch December 22, 2022 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants