From b041cd8bb0e3a095bb12587f06d5cb4b927f417a Mon Sep 17 00:00:00 2001 From: Rim Rakhimov Date: Mon, 14 Aug 2023 13:31:48 +0300 Subject: [PATCH] Update 'search_sourcify_sources' handler to support newest sourcify lib (#576) --- eth-bytecode-db/Cargo.lock | 2 +- .../eth-bytecode-db-server/Cargo.toml | 2 +- .../eth-bytecode-db-server/src/server.rs | 11 +++++++---- .../src/services/database.rs | 16 ++++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/eth-bytecode-db/Cargo.lock b/eth-bytecode-db/Cargo.lock index 991914274..3f9b58209 100644 --- a/eth-bytecode-db/Cargo.lock +++ b/eth-bytecode-db/Cargo.lock @@ -5109,7 +5109,7 @@ dependencies = [ [[package]] name = "sourcify" version = "0.1.0" -source = "git+https://github.com/blockscout/blockscout-rs?branch=rimrakhimov/libs/sourcify#9abb78b6b373bd08f2a5f4dac1a4d069e60c7dd6" +source = "git+https://github.com/blockscout/blockscout-rs?rev=e61bd59#e61bd59f41694bb51665f578a5f75f00f48572be" dependencies = [ "anyhow", "blockscout-display-bytes", diff --git a/eth-bytecode-db/eth-bytecode-db-server/Cargo.toml b/eth-bytecode-db/eth-bytecode-db-server/Cargo.toml index 9062e3101..12a3c9024 100644 --- a/eth-bytecode-db/eth-bytecode-db-server/Cargo.toml +++ b/eth-bytecode-db/eth-bytecode-db-server/Cargo.toml @@ -22,7 +22,7 @@ sea-orm = "0.11" serde = "1.0" serde_json = "1.0.96" serde_with = "2.1" -sourcify = { git = "https://github.com/blockscout/blockscout-rs", branch = "rimrakhimov/libs/sourcify" } +sourcify = { git = "https://github.com/blockscout/blockscout-rs", rev = "e61bd59" } tokio = { version = "1.23", features = [ "rt-multi-thread", "macros" ] } tonic = "0.8" tracing = "0.1" diff --git a/eth-bytecode-db/eth-bytecode-db-server/src/server.rs b/eth-bytecode-db/eth-bytecode-db-server/src/server.rs index a3475b25a..c7d75017e 100644 --- a/eth-bytecode-db/eth-bytecode-db-server/src/server.rs +++ b/eth-bytecode-db/eth-bytecode-db-server/src/server.rs @@ -91,10 +91,13 @@ pub async fn run(settings: Settings) -> Result<(), anyhow::Error> { .sourcify .enabled .then(|| { - sourcify::ClientBuilder::default() - .base_url(&settings.database.sourcify.base_url) - .total_duration(settings.database.sourcify.total_request_duration) - .build() + Ok::<_, anyhow::Error>( + sourcify::ClientBuilder::default() + .try_base_url(&settings.database.sourcify.base_url) + .map_err(|err| anyhow::anyhow!(err))? + .total_duration(settings.database.sourcify.total_request_duration) + .build(), + ) }) .transpose()?; let database = Arc::new(DatabaseService::new_arc(db_connection, sourcify_client)); diff --git a/eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs b/eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs index 9fa096bec..b995e4970 100644 --- a/eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs +++ b/eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs @@ -98,20 +98,16 @@ impl Database for DatabaseService { } } -fn process_sourcify_error(error: sourcify::Error) -> Option { +fn process_sourcify_error( + error: sourcify::Error, +) -> Option { match error { - sourcify::Error::InvalidArgument { .. } - | sourcify::Error::Reqwest(_) - | sourcify::Error::ReqwestMiddleware(_) => { + sourcify::Error::Reqwest(_) | sourcify::Error::ReqwestMiddleware(_) => { tracing::error!(target: "sourcify", "{error}"); Some(tonic::Status::internal( "sending request to sourcify failed", )) } - sourcify::Error::Sourcify(sourcify::SourcifyError::TooManyRequests(_)) => { - tracing::error!(target: "sourcify", "{error}"); - Some(tonic::Status::resource_exhausted(error.to_string())) - } sourcify::Error::Sourcify(sourcify::SourcifyError::InternalServerError(_)) => { tracing::error!(target: "sourcify", "{error}"); Some(tonic::Status::internal("sourcify responded with error")) @@ -132,5 +128,9 @@ fn process_sourcify_error(error: sourcify::Error) -> Option { tracing::error!(target: "sourcify", "{error}"); Some(tonic::Status::internal("sourcify responded with error")) } + sourcify::Error::Sourcify(sourcify::SourcifyError::Custom(_)) => { + // `EmptyCustomError` enum has no variants and cannot be initialized + unreachable!() + } } }