Skip to content

Commit 9932680

Browse files
authored
chore(anvil): spawn estimate on blocking task (#10307)
1 parent b75625a commit 9932680

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,17 +2659,22 @@ impl EthApi {
26592659
}
26602660
}
26612661

2662-
self.backend
2663-
.with_database_at(Some(block_request), |mut state, block| {
2664-
if let Some(overrides) = overrides {
2665-
state = Box::new(state::apply_state_override(
2666-
overrides.into_iter().collect(),
2667-
state,
2668-
)?);
2669-
}
2670-
self.do_estimate_gas_with_state(request, &state, block)
2671-
})
2672-
.await?
2662+
// this can be blocking for a bit, especially in forking mode
2663+
// <https://github.com/foundry-rs/foundry/issues/6036>
2664+
self.on_blocking_task(|this| async move {
2665+
this.backend
2666+
.with_database_at(Some(block_request), |mut state, block| {
2667+
if let Some(overrides) = overrides {
2668+
state = Box::new(state::apply_state_override(
2669+
overrides.into_iter().collect(),
2670+
state,
2671+
)?);
2672+
}
2673+
this.do_estimate_gas_with_state(request, &state, block)
2674+
})
2675+
.await?
2676+
})
2677+
.await
26732678
}
26742679

26752680
/// Estimates the gas usage of the `request` with the state.

0 commit comments

Comments
 (0)