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

feat(revm): allow for Evm to be Send + Sync #1152

Open
Autoparallel opened this issue Mar 5, 2024 · 2 comments
Open

feat(revm): allow for Evm to be Send + Sync #1152

Autoparallel opened this issue Mar 5, 2024 · 2 comments
Labels

Comments

@Autoparallel
Copy link
Contributor

Problem

Right now, we cannot share Evm<_> across thread boundaries as there are certain handlers that are not set to be Send + Sync. E.g.:

pub type ValidateEnvHandle<'a, DB> =
Arc<dyn Fn(&Env) -> Result<(), EVMError<<DB as Database>::Error>> + 'a>;
/// Handle that validates transaction environment against the state.
/// Second parametar is initial gas.
pub type ValidateTxEnvAgainstState<'a, EXT, DB> =
Arc<dyn Fn(&mut Context<EXT, DB>) -> Result<(), EVMError<<DB as Database>::Error>> + 'a>;
/// Initial gas calculation handle
pub type ValidateInitialTxGasHandle<'a, DB> =
Arc<dyn Fn(&Env) -> Result<u64, EVMError<<DB as Database>::Error>> + 'a>;

This restricts being able to do Arc<RwLock<Evm<_>>> and having shared access to an Evm<_> instance where one could be able to parallelize over read-only txs.

Solution

  • I have brought this up before, but we could simply tag those dyn Fns with Send + Sync, however I don't think this is what revm wants. Perhaps this could be an option under a feature flag?
  • There could be other ways around this. Do we have any ideas on what would be acceptable?

Related Issues

It was brought up that #916 was related, and I began trying to work on this. I want to open up this issue here to keep it in mind and discuss.

@rakita
Copy link
Member

rakita commented Mar 12, 2024

This is probably not going to happen with whole Evm what i would recommend is to use and send Context while rebuilding Handler when needed.

@rakita rakita added the request label Mar 25, 2024
@CorrM
Copy link
Contributor

CorrM commented Mar 29, 2024

This is probably not going to happen with whole Evm what i would recommend is to use and send Context while rebuilding Handler when needed.

The database will still be a problem to be shared.
Clone the context will make a snapshot of the DB then it's not a true shared state. (correct me if I'm wrong)

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

No branches or pull requests

3 participants