Update engine state in broadcast
## Issue Addressed
N/A
## Proposed Changes
Set the engine state to `EngineState::Offline` if the engine api call fails during broadcast. This caused issues while pausing sync when the execution engine is offline because `EngineState` always returned `Synced`.
@@ -399,18 +399,22 @@ impl<T: EngineApi> Engines<T> {
let futures = self.engines.iter().map(|engine| async move {
let is_offline = *engine.state.read().await == EngineState::Offline;
if !is_offline {
- func(engine).await.map_err(|error| {
+ match func(engine).await {
+ Ok(res) => Ok(res),
+ Err(error) => {
debug!(
self.log,
"Execution engine call failed";
"error" => ?error,
"id" => &engine.id
);
- EngineError::Api {
+ *engine.state.write().await = EngineState::Offline;
+ Err(EngineError::Api {
id: engine.id.clone(),
error,
- }
})
+ }
+ }
} else {
Err(EngineError::Offline {
id: engine.id.clone(),
