revm icon indicating copy to clipboard operation
revm copied to clipboard

able to define shared cache db across multiple threads

Open jafar75 opened this issue 8 months ago • 0 comments

Hi, I plan to use revm in a multi-threaded environment and want to share a cache database across multiple threads.

I have an implementation like this

image

and I define the db as : let mut ethers_db = EthersDB::new(Arc::clone(&client), Some(block_id)).expect("error in create ether db"); let mut cache_db = CacheDB::new(ethers_db.clone());

If I clone the cache_db in each thread, I think caching mechanism will not work efficiently. also, using Arc and Mutex for whole evm.transact().unwrap(); will not work for me, because it will block all other threads and nearly all of my processing is about transacting.

Is there any clever way to handle this? I'm aware that internal hashMap of the cache db (hashBrown) is not designed for parallel lock-free access and I think changing it to something else would have a lot of work.

thanks

jafar75 avatar Jun 19 '24 14:06 jafar75