Skip to content

Commit 9e5f4b9

Browse files
authored
perf: spawn mining on blocking (#10471)
* perf: spawn mining on blocking * fmt
1 parent 15d3970 commit 9e5f4b9

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

crates/anvil/src/eth/api.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -1738,15 +1738,18 @@ impl EthApi {
17381738
return Ok(());
17391739
}
17401740

1741-
// mine all the blocks
1742-
for _ in 0..blocks.to::<u64>() {
1743-
// If we have an interval, jump forwards in time to the "next" timestamp
1744-
if let Some(interval) = interval {
1745-
self.backend.time().increase_time(interval);
1741+
self.on_blocking_task(|this| async move {
1742+
// mine all the blocks
1743+
for _ in 0..blocks.to::<u64>() {
1744+
// If we have an interval, jump forwards in time to the "next" timestamp
1745+
if let Some(interval) = interval {
1746+
this.backend.time().increase_time(interval);
1747+
}
1748+
this.mine_one().await;
17461749
}
1747-
1748-
self.mine_one().await;
1749-
}
1750+
Ok(())
1751+
})
1752+
.await?;
17501753

17511754
Ok(())
17521755
}
@@ -2630,10 +2633,16 @@ impl EthApi {
26302633
}
26312634
}
26322635

2633-
// mine all the blocks
2634-
for _ in 0..blocks_to_mine {
2635-
self.mine_one().await;
2636-
}
2636+
// this can be blocking for a bit, especially in forking mode
2637+
// <https://github.com/foundry-rs/foundry/issues/6036>
2638+
self.on_blocking_task(|this| async move {
2639+
// mine all the blocks
2640+
for _ in 0..blocks_to_mine {
2641+
this.mine_one().await;
2642+
}
2643+
Ok(())
2644+
})
2645+
.await?;
26372646

26382647
Ok(blocks_to_mine)
26392648
}

0 commit comments

Comments
 (0)