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

Cant recreate evm with ContextWithHandlerCfg #1126

Closed
CorrM opened this issue Feb 24, 2024 · 4 comments
Closed

Cant recreate evm with ContextWithHandlerCfg #1126

CorrM opened this issue Feb 24, 2024 · 4 comments

Comments

@CorrM
Copy link
Contributor

CorrM commented Feb 24, 2024

After read this issue: #1062.
I got the concept of recreate evm, but ContextWithHandlerCfg doesnt have clone, so what the proper way to achive multi-threading evm instance.

Also i want db to be shared cross all threads like when i call insert_account_info in thread effect all other threads.

image

@CorrM
Copy link
Contributor Author

CorrM commented Feb 24, 2024

After some digging

let cfg = ContextWithHandlerCfg::new(self.ctx_with_handler.context.clone(), self.ctx_with_handler.cfg.clone());
Evm::builder().with_context_with_handler_cfg(cfg).build();

Why i can ContextWithHandlerCfg::new(self.ctx_with_handler.context.clone(), self.ctx_with_handler.cfg.clone()) but can't self.ctx_with_handler.clone() ?
Is this correct way to do it, its work but correct way ???

But db state not shared.

@rakita
Copy link
Member

rakita commented Feb 24, 2024

You can't as there is no Clone impl on ContextWithHandlerCfg. You are free to make PR that adds it.

Something similar to:

impl<EXT: Clone, DB: Database + Clone> Clone for Context<EXT, DB>
where
DB::Error: Clone,
{
fn clone(&self) -> Self {
Self {
evm: self.evm.clone(),
external: self.external.clone(),
}
}
}

@rakita rakita added good first issue Good for newcomers feature New feature or lib ability labels Feb 24, 2024
@CorrM
Copy link
Contributor Author

CorrM commented Feb 25, 2024

You can't as there is no Clone impl on ContextWithHandlerCfg. You are free to make PR that adds it.

Something similar to:

impl<EXT: Clone, DB: Database + Clone> Clone for Context<EXT, DB>
where
DB::Error: Clone,
{
fn clone(&self) -> Self {
Self {
evm: self.evm.clone(),
external: self.external.clone(),
}
}
}

what about

Also i want db to be shared cross all threads like when i call insert_account_info in thread effect all other threads.

@rakita
Copy link
Member

rakita commented Feb 26, 2024

Also i want db to be shared cross all threads like when i call insert_account_info in thread effect all other threads.

This would mean creating a new struct with RwLock around data. Or what people do is use DatabaseRef to share it across the threads as it does not have mut functions. It is up to your use case

@rakita rakita removed good first issue Good for newcomers feature New feature or lib ability labels Feb 26, 2024
@CorrM CorrM closed this as completed Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants