Skip to content

Commit

Permalink
fix: handling of HTTP 403 thrown by proxyd (#2835)
Browse files Browse the repository at this point in the history
When a method is missing:
proxyd returns HTTP 403:  methodnotfound
while api server returns HTTP 200: methodnotfound

we need to handle both.
  • Loading branch information
pompon0 authored Sep 10, 2024
1 parent 52f4f76 commit 2d71c74
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions core/node/consensus/src/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl EN {
let global_config = self
.fetch_global_config(ctx)
.await
.wrap("fetch_genesis()")?;
.wrap("fetch_global_config()")?;
let mut conn = self.pool.connection(ctx).await.wrap("connection()")?;

conn.try_update_global_config(ctx, &global_config)
Expand Down Expand Up @@ -90,7 +90,7 @@ impl EN {
if let Ok(new) = self.fetch_global_config(ctx).await {
if new != old {
return Err(anyhow::format_err!(
"genesis changed: old {old:?}, new {new:?}"
"global config changed: old {old:?}, new {new:?}"
)
.into());
}
Expand Down Expand Up @@ -282,29 +282,29 @@ impl EN {
match ctx.wait(self.client.consensus_global_config()).await? {
Ok(cfg) => {
let cfg = cfg.context("main node is not running consensus component")?;
Ok(zksync_protobuf::serde::deserialize(&cfg.0).context("deserialize()")?)
}
Err(ClientError::Call(err)) if err.code() == ErrorCode::MethodNotFound.code() => {
tracing::info!(
"consensus_global_config() not found, calling consensus_genesis() instead"
);
let genesis = ctx
.wait(self.client.consensus_genesis())
.await?
.context("consensus_genesis()")?
.context("main node is not running consensus component")?;
Ok(consensus_dal::GlobalConfig {
genesis: zksync_protobuf::serde::deserialize(&genesis.0)
.context("deserialize()")?,
registry_address: None,
})
return Ok(zksync_protobuf::serde::deserialize(&cfg.0).context("deserialize()")?);
}
// For non-whitelisted methods, proxyd returns HTTP 403 with MethodNotFound in the body.
// For some stupid reason ClientError doesn't expose HTTP error codes.
Err(ClientError::Transport(_)) => {}
// For missing methods api server, returns HTTP 200 with MethodNotFound in the body.
Err(ClientError::Call(err)) if err.code() == ErrorCode::MethodNotFound.code() => {}
Err(err) => {
return Err(err)
.context("consensus_global_config()")
.map_err(|err| err.into())
.map_err(|err| err.into());
}
}
tracing::info!("consensus_global_config() not found, calling consensus_genesis() instead");
let genesis = ctx
.wait(self.client.consensus_genesis())
.await?
.context("consensus_genesis()")?
.context("main node is not running consensus component")?;
Ok(consensus_dal::GlobalConfig {
genesis: zksync_protobuf::serde::deserialize(&genesis.0).context("deserialize()")?,
registry_address: None,
})
}

#[tracing::instrument(skip_all)]
Expand Down

0 comments on commit 2d71c74

Please sign in to comment.