@@ -41,6 +41,9 @@ use std::{
4141 time:: Instant ,
4242} ;
4343
44+ /// min number of txs to parallel execute.
45+ const MIN_PARALLEL_TXS : usize = 64 ;
46+
4447pub ( crate ) type MVMemory = DashMap < LocationAndType , BTreeMap < TxId , MemoryEntry > > ;
4548
4649#[ derive( Metrics ) ]
@@ -266,9 +269,6 @@ where
266269 env : BlockEnv ,
267270 block_size : usize ,
268271 txs : Arc < Vec < TxEnv > > ,
269- /// SAFETY: `UnsafeCell` allows the commit thread to mutate state while worker threads read.
270- /// The commit thread has exclusive write access (serialized by finality ordering).
271- /// Worker threads only read via `DatabaseRef` (DashMap-based, thread-safe).
272272 state : UnsafeCell < ParallelState < DB > > ,
273273 results : Mutex < Vec < ExecutionResult > > ,
274274 tx_states : Vec < Mutex < TxState > > ,
@@ -445,16 +445,15 @@ where
445445 std:: env:: var ( "GREVM_CONCURRENT_LEVEL" )
446446 . map_or ( * CONCURRENT_LEVEL , |s| s. parse ( ) . unwrap_or ( * CONCURRENT_LEVEL ) ) ,
447447 ) ;
448- if * FALLBACK_SEQUENTIAL {
448+ if * FALLBACK_SEQUENTIAL || self . block_size < MIN_PARALLEL_TXS {
449449 return self . fallback_sequential ( ) ;
450450 }
451451 let commiter = Mutex :: new ( StateAsyncCommit :: new (
452452 self . env . beneficiary ,
453453 CommitGuard :: new ( & self . state ) ,
454454 self . cfg . disable_nonce_check ,
455455 ) ) ;
456- // SAFETY: Worker threads access `ParallelState` only through `DatabaseRef` (read-only,
457- // DashMap-based, inherently thread-safe). The commit thread is the sole writer.
456+
458457 let state_ref = unsafe { & * self . state . get ( ) } ;
459458 commiter. lock ( ) . init ( ) . map_err ( |e| GrevmError { txid : 0 , error : EVMError :: Database ( e) } ) ?;
460459 thread:: scope ( |scope| {
@@ -571,9 +570,6 @@ where
571570 }
572571
573572 let mut sequential_results = Vec :: with_capacity ( self . block_size - num_commit) ;
574- // SAFETY: fallback_sequential is called either before parallel execution starts
575- // (when FALLBACK_SEQUENTIAL is true) or after post_execute (after thread::scope
576- // has joined all threads), so no concurrent access exists.
577573 let mut commit_guard = CommitGuard :: new ( & self . state ) ;
578574 let state_mut = commit_guard. state_mut ( ) ;
579575 {
0 commit comments