-
Notifications
You must be signed in to change notification settings - Fork 545
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
Cannot use database by reference when registering handlers #1144
Comments
Every reference to db would make this unusable as the handler register could potentially make additional references. This is not the case if we use generic over Made PR here: Wodann#4 |
btw would definitely want to include this example inside repo. |
Thanks for the fix. I've created a PR with the cleaned up example: #1150 |
@rakita At first your proposed solution of using trait generics to avoid the lifetime constrained seemed to work. Every time I applied this solution, the errors bubbled up one layer. Each time I was able to design a workaround (albeit not very elegant), until I ran into this issue: NomicFoundation/hardhat@ef9240a#r139362460 This shows that in most cases, the compiler is able to generate some form of code that adheres to lifetime constraints, but the I tried creating another minimal example for you to look at but given that we're many layers into the EDR code, it's not a trivial effort. I'm happy to try and explain the use case to you in more detail, but at a high level it looks like this:
I might be doing something wrong, but it feels like the inclusion of the
|
I was able to work around the lifetime issue by moving the data into the The downside of this is that it pollutes a lot of APIs, which is why I wanted to pass in the state as a reference. |
Yeah if you have any reference it will get "potentially" tied to the handler. as ref signature allows that. This could work to send it back and forth. I wonder if doing something like |
Do you mean instead of storing the |
API is restrictive but allows reusage of handlers boxes. For a solution, I would recommend the same thing that you did, return the database or Context back from Evm and create Evm only when you need it. Or introduce Database that has inner mutability.
Will close this issue for now, as there is nothing to be done. |
Similar to previous versions of the
revm
that usedInspectors
, the new implementation that uses handlers couples the lifetime of the database with theHandleRegister
functions.I proposed a fix for previous versions of
revm
in this PR.This commit shows how to produce irresolvable compile errors with
revm
v6.1.0.The only way I can think of to resolve this issue is by removing the
DB
generic from theHandleRegister
andEvmContext
by providing access to the database using a&mut dyn Database<Error = DBErrorT>
, asDBErrorT
should minimise the chances of lifetime conflicts. This would decouple the user's type from theEvm
and avoid lifetime issues.The text was updated successfully, but these errors were encountered: