ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
889 stars 131 forks source link

RecursionError: nonreentrant ContractCache.get:<address> [APE-1361] #1647

Closed nazariyv closed 1 year ago

nazariyv commented 1 year ago

Environment information

What went wrong?

We started experiencing CI issues yesterday. No code changed on our side, so we suspected it must be the plugins that ape is pulling in (since we didn't fix foundry version in ape-config.yaml). That was correct.

Here is the repo I prepped that reproduces the bug: https://github.com/nazariyv/ape-recursion-error

Tests run fine locally, see the Readme in the above repo.

However, running them in CI fails (see last github action: https://github.com/nazariyv/ape-recursion-error/actions/runs/6051011716/job/16421551565)

How can it be fixed?

I fixed it by fixing the ape-foundry plugin version to "0.6.14".

antazoey commented 1 year ago

It looks like you hit Etherscan rate limiting when fetching a contract type.

antazoey commented 1 year ago

It also smells like a proxy (safe?) related issue and the reason you may not be hitting it locally is that you already successfully have the contracts cached.

I fixed it by fixing the ape-foundry plugin version to "0.6.14".

Can you try 0.6.15 and see if the problem still happens? I am having a hard time knowing how 0.6.15 of ape-foundry could contain the bug if it does, that is a small amount of diff to analyze. I have a hunch the bug was maybe in evm-trace a23 (we released a24 a little bit ago). Also, I had a similar issue with Anvil and Solidity today ...

And one last thing, do you have your Etherscan API key set? If that 429 caused this, then that would explain why eventually it stopped happening (contracts eventually cached). But if you set the API key that may help, or include the contracts in your projects.

nazariyv commented 1 year ago

so the ci job that is failing: https://github.com/nazariyv/ape-recursion-error/actions/runs/6051011716/job/16421551565, is running "0.6.15": https://github.com/nazariyv/ape-recursion-error/blob/main/ape-config.yaml#L5

I have actually never set an etherscan api key. Neither locally, nor in github secrets (for it to pick up in the ci job)

nazariyv commented 1 year ago

if I downgrade ape-foundry to "0.6.14" you can see that this very same test now passes in the ci with no issue: https://github.com/nazariyv/ape-recursion-error/actions/runs/6054804220/job/16432787905

(no changes to setting etherscan api key anywhere)

antazoey commented 1 year ago

The issue must be in that it is failing for some reason to calculate a sourc traceback, likely due to needing contract types and only having etherscan to fetch them from (even though it wasn't given an API key).

So i made foundry handle these errors and work the same as before if stuff like that happens. Let me know (if you can) if that fixes it for you

https://github.com/ApeWorX/ape-foundry/pull/72

nazariyv commented 1 year ago

Not sure how to incorporate the above. Can I specify the version for ape-foundry via commit hash in ape-config.yaml?

fubuloubu commented 1 year ago

Not sure how to incorporate the above. Can I specify the version for ape-foundry via commit hash in ape-config.yaml?

No, not today. But also our plugins system is just a wrapper around pip and you can install via commit hashes w/ pip install git+...

nazariyv commented 1 year ago

Brilliant, this fixes the issue, you can confirm with this job: https://github.com/nazariyv/ape-recursion-error/actions/runs/6066810063/job/16457801974

Using the fixed commit hash for ape-foundry as suggested: https://github.com/nazariyv/ape-recursion-error/commit/4a520bdbf0380a6474c0faf13668bb9351fde3ec

Thank you!

fubuloubu commented 1 year ago

Perfect! We will try and trace down/resolve this issue, but at least you have a workaround for now

nazariyv commented 1 year ago

I have actually downgraded to ape-foundry 0.6.14, and that works too :) Thanks for figuring this out so quickly!