Skip to content

Commit 79dde48

Browse files
committed
avoid block in tokio async context
1 parent c3ba1aa commit 79dde48

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/scheduler.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,18 @@ where
305305
}
306306

307307
let start = Instant::now();
308-
GREVM_RUNTIME.block_on(async {
309-
let mut tasks = vec![];
310-
for executor in &self.partition_executors {
311-
let executor = executor.clone();
312-
tasks.push(GREVM_RUNTIME.spawn(async move { executor.write().unwrap().execute() }));
313-
}
314-
futures::future::join_all(tasks).await;
308+
// Do not block tokio runtime if we are in async context
309+
tokio::task::block_in_place(|| {
310+
GREVM_RUNTIME.block_on(async {
311+
let mut tasks = vec![];
312+
for executor in &self.partition_executors {
313+
let executor = executor.clone();
314+
tasks.push(
315+
GREVM_RUNTIME.spawn(async move { executor.write().unwrap().execute() }),
316+
);
317+
}
318+
futures::future::join_all(tasks).await;
319+
})
315320
});
316321
self.metrics.parallel_execute_time.increment(start.elapsed().as_nanos() as u64);
317322

src/storage.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl ParallelBundleState for BundleState {
158158
}
159159
}
160160

161-
#[derive(Debug, Default)]
161+
#[derive(Debug)]
162162
pub struct State {
163163
/// Cache the committed data of finality txns and the read-only data during execution after
164164
/// each round of execution. Used as the initial state for the next round of partition
@@ -183,6 +183,17 @@ pub struct State {
183183
pub block_hashes: BTreeMap<u64, B256>,
184184
}
185185

186+
impl Default for State {
187+
fn default() -> Self {
188+
Self {
189+
cache: CacheState::new(false),
190+
transition_state: Some(TransitionState::default()),
191+
bundle_state: BundleState::default(),
192+
block_hashes: BTreeMap::new(),
193+
}
194+
}
195+
}
196+
186197
impl State {
187198
/// Takes the current bundle state.
188199
/// It is typically called after the bundle state has been finalized.

tests/mainnet.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use alloy_rpc_types::{Block, BlockTransactions};
88
use common::{compat, storage::InMemoryDB};
99
use grevm::GrevmScheduler;
1010
use metrics_util::debugging::DebuggingRecorder;
11-
use revm::primitives::{Env, TxEnv};
11+
use revm::{
12+
db::states::bundle_state::BundleRetention,
13+
primitives::{Env, TxEnv},
14+
};
1215

1316
fn test_execute_alloy(block: Block, db: InMemoryDB) {
1417
let spec_id = compat::get_block_spec(&block.header);
@@ -38,7 +41,10 @@ fn test_execute_alloy(block: Block, db: InMemoryDB) {
3841
for (key, _, _, value) in snapshot.into_vec() {
3942
println!("metrics: {} => value: {:?}", key.key().name(), value);
4043
}
41-
(parallel_result, Arc::get_mut(&mut executor.database).unwrap().state.take_bundle())
44+
45+
let database = Arc::get_mut(&mut executor.database).unwrap();
46+
database.state.merge_transitions(BundleRetention::Reverts);
47+
(parallel_result, database.state.take_bundle())
4248
});
4349

4450
common::compare_execution_result(&reth_result.0.results, &parallel_result.0.results);

0 commit comments

Comments
 (0)