Skip to content

Commit

Permalink
refactor(bridge): print EL provider response on error (#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML authored Feb 9, 2024
1 parent 717f56f commit 234b089
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion portal-bridge/src/api/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl ConsensusApi {
"Starting ConsensusApi with provider at url: {:?}",
client.config().base_url
);
check_provider(&client).await?;
check_provider(&client)
.await
.map_err(|err| anyhow!("Check CL provider failed. Provider may be offline: {err:?}"))?;
Ok(Self { client })
}

Expand Down
28 changes: 18 additions & 10 deletions portal-bridge/src/api/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl ExecutionApi {
client.config().base_url
);
if provider != Provider::Test {
check_provider(&client).await?;
check_provider(&client).await.map_err(|err| {
anyhow!("Check EL provider failed. Provider may be offline: {err:?}")
})?;
}
let master_acc = MasterAccumulator::default();
Ok(Self { client, master_acc })
Expand Down Expand Up @@ -298,25 +300,31 @@ impl ExecutionApi {
.client
.post("")
.body_json(&json!(requests))
.map_err(|e| anyhow!("Unable to construct json post request: {e:?}"))?
.map_err(|e| anyhow!("Unable to construct json post for batched requests: {e:?}"))?;
let response = result
.recv_string()
.await
.map_err(|err| anyhow!("Unable to request execution batch from provider: {err:?}"));
serde_json::from_str::<Vec<Value>>(&result?)
.map_err(|err| anyhow!("Unable to parse execution batch from provider: {err:?}"))
.map_err(|err| anyhow!("Unable to request execution batch from provider: {err:?}"))?;
serde_json::from_str::<Vec<Value>>(&response).map_err(|err| {
anyhow!("Unable to parse execution batch from provider: {err:?} response: {response:?}")
})
}

async fn send_request(&self, request: JsonRequest) -> anyhow::Result<Value> {
let result = self
.client
.post("")
.body_json(&request)
.map_err(|e| anyhow!("Unable to construct json post request: {e:?}"))?
.map_err(|e| anyhow!("Unable to construct json post for single request: {e:?}"))?;
let response = result
.recv_string()
.await
.map_err(|err| anyhow!("Unable to request execution payload from provider: {err:?}"));
serde_json::from_str::<Value>(&result?)
.map_err(|err| anyhow!("Unable to parse execution response from provider: {err:?}"))
.map_err(|err| anyhow!("Unable to request execution payload from provider: {err:?}"))?;
serde_json::from_str::<Value>(&response).map_err(|err| {
anyhow!(
"Unable to parse execution response from provider: {err:?} response: {response:?}"
)
})
}
}

Expand Down Expand Up @@ -390,7 +398,7 @@ async fn check_provider(client: &Client) -> anyhow::Result<()> {
.recv_string()
.await
.map_err(|err| anyhow!("Unable to request execution batch from provider: {err:?}"))?;
let response: Value = serde_json::from_str(&response).map_err(|err| anyhow!("Unable to parse json response from execution provider, it's likely unavailable/configured incorrectly: {err:?}"))?;
let response: Value = serde_json::from_str(&response).map_err(|err| anyhow!("Unable to parse json response from execution provider, it's likely unavailable/configured incorrectly: {err:?} response: {response:?}"))?;
if response["result"].as_str().is_none() {
bail!("Invalid response from execution provider check, it's likely unavailable/configured incorrectly");
}
Expand Down

0 comments on commit 234b089

Please sign in to comment.