Skip to content

Commit

Permalink
feat: Handle Web3Error::NotImplemented on EN
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrause98 committed Mar 11, 2024
1 parent edc04d3 commit f544652
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@ use zksync_consensus_roles::node;
use zksync_core::{
api_server::{
tx_sender::TxSenderConfig,
web3::{state::InternalApiConfig, Namespace},
web3::{backend_jsonrpsee::into_jsrpc_error, state::InternalApiConfig, Namespace},
},
consensus,
};
use zksync_types::{api::BridgeAddresses, ETHEREUM_ADDRESS};
use zksync_web3_decl::{
error::ClientRpcContext,
error::{ClientRpcContext, Web3Error},
jsonrpsee::{
core::ClientError,
http_client::{HttpClient, HttpClientBuilder},
types::error::ErrorCode,
},
namespaces::{EthNamespaceClient, ZksNamespaceClient},
};

pub(crate) mod observability;
#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -61,7 +60,13 @@ impl RemoteENConfig {
.rpc_context("get_main_contract")
.await?;
let base_token_addr = match client.get_base_token_l1_address().await {
Err(ClientError::Call(err)) if ErrorCode::MethodNotFound.code() == err.code() => {
Err(ClientError::Call(err))
if [
ErrorCode::MethodNotFound.code(),
into_jsrpc_error(Web3Error::NotImplemented).code(),
]
.contains(&(err.code())) =>
{
// This is the fallback case for when the EN tries to interact
// with a node that does not implement the zks_baseTokenL1Address endpoint.
ETHEREUM_ADDRESS
Expand Down Expand Up @@ -612,7 +617,7 @@ impl From<ExternalNodeConfig> for InternalApiConfig {
l2_testnet_paymaster_addr: config.remote.l2_testnet_paymaster_addr,
req_entities_limit: config.optional.req_entities_limit,
fee_history_limit: config.optional.fee_history_limit,
base_token_address: config.remote.base_token_addr,
base_token_address: Some(config.remote.base_token_addr),
filters_disabled: config.optional.filters_disabled,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::api_server::{tx_sender::SubmitTxError, web3::metrics::API_METRICS};
pub mod batch_limiter_middleware;
pub mod namespaces;

pub(crate) fn into_jsrpc_error(err: Web3Error) -> ErrorObjectOwned {
pub fn into_jsrpc_error(err: Web3Error) -> ErrorObjectOwned {
let data = match &err {
Web3Error::SubmitTransactionError(_, data) => Some(format!("0x{}", hex::encode(data))),
_ => None,
Expand Down

0 comments on commit f544652

Please sign in to comment.