diff --git a/Cargo.lock b/Cargo.lock index 942e8737..18041e5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1314,9 +1314,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.10" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bbb8258be8305fb0237d7b295f47bb24ff1b136a535f473baf40e70468515aa" +checksum = "80f656be11ddf91bd709454d15d5bd896fbaf4cc3314e69349e4d1569f5b46cd" dependencies = [ "indenter", "once_cell", @@ -1786,9 +1786,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", @@ -2029,9 +2029,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" @@ -2225,9 +2225,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", @@ -2348,9 +2348,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "open-fastrlp" @@ -2379,9 +2379,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.61" +version = "0.10.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45" +checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -2411,9 +2411,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.97" +version = "0.9.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" +checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" dependencies = [ "cc", "libc", @@ -2657,9 +2657,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "portable-atomic" -version = "1.6.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" +checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" [[package]] name = "powerfmt" @@ -2990,9 +2990,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.7" +version = "0.17.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "684d5e6e18f669ccebf64a92236bb7db9a34f07be010e3627368182027180866" dependencies = [ "cc", "getrandom", @@ -3056,9 +3056,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a" dependencies = [ "bitflags 2.4.1", "errno", @@ -3069,12 +3069,12 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "629648aced5775d558af50b2b4c7b02983a04b312126d45eeead26e7caa498b9" dependencies = [ "log", - "ring 0.17.7", + "ring 0.17.6", "rustls-webpki", "sct", ] @@ -3106,7 +3106,7 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.7", + "ring 0.17.6", "untrusted 0.9.0", ] @@ -3118,9 +3118,9 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "salsa20" @@ -3197,7 +3197,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.7", + "ring 0.17.6", "untrusted 0.9.0", ] @@ -3708,9 +3708,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ "backtrace", "bytes", @@ -3915,9 +3915,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "tui" @@ -3987,9 +3987,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" @@ -4435,9 +4435,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.26" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67b5f0a4e7a27a64c651977932b9dc5667ca7fc31ac44b03ed37a0cf42fdfff" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" dependencies = [ "memchr", ] diff --git a/common/src/resources/transpose.rs b/common/src/resources/transpose.rs index 930d9c77..bcd87606 100644 --- a/common/src/resources/transpose.rs +++ b/common/src/resources/transpose.rs @@ -1,3 +1,4 @@ +use backoff::ExponentialBackoff; use indicatif::ProgressBar; use reqwest::header::HeaderMap; use serde_json::Value; @@ -21,58 +22,67 @@ struct TransposeResponse { } /// executes a transpose SQL query and returns the response -async fn _call_transpose(query: &str, api_key: &str) -> Option { - // get a new logger - let logger = Logger::default(); - - // build the headers - let mut headers = HeaderMap::new(); - headers.insert("Content-Type", "application/json".parse().unwrap()); - headers.insert("X-API-KEY", api_key.parse().unwrap()); - - // clone the query - let query = query.to_owned(); - - // make the request - let client = reqwest::Client::builder() - .redirect(reqwest::redirect::Policy::none()) - .timeout(Duration::from_secs(999999999)) - .build() - .unwrap(); - - let response = match client - .post("https://api.transpose.io/sql") - .body(query.clone()) - .headers(headers) - .send() - .await - { - Ok(res) => res, - Err(e) => { - logger.error("failed to call Transpose ."); - logger.error(&format!("error: {e}")); - std::process::exit(1) - } - }; - - // parse body - match response.text().await { - Ok(body) => Some(match serde_json::from_str(&body) { - Ok(json) => json, - Err(e) => { - logger.error("Transpose request unsucessful."); - logger.debug(&format!("curl: curl -X GET \"https://api.transpose.io/sql\" -H \"accept: application/json\" -H \"Content-Type: application/json\" -H \"X-API-KEY: {api_key}\" -d {query}")); - logger.error(&format!("error: {e}")); - logger.debug(&format!("response body: {body:?}")); - std::process::exit(1) +async fn call_transpose(query: &str, api_key: &str) -> Option { + backoff::future::retry( + ExponentialBackoff { + max_elapsed_time: Some(Duration::from_secs(10)), + ..ExponentialBackoff::default() + }, + || async { + // get a new logger + let logger = Logger::default(); + + // build the headers + let mut headers = HeaderMap::new(); + headers.insert("Content-Type", "application/json".parse().unwrap()); + headers.insert("X-API-KEY", api_key.parse().unwrap()); + + // clone the query + let query = query.to_owned(); + + // make the request + let client = reqwest::Client::builder() + .redirect(reqwest::redirect::Policy::none()) + .timeout(Duration::from_secs(999999999)) + .build() + .unwrap(); + + let response = match client + .post("https://api.transpose.io/sql") + .body(query.clone()) + .headers(headers) + .send() + .await + { + Ok(res) => res, + Err(e) => { + logger.error("failed to call Transpose ."); + logger.error(&format!("error: {e}")); + return Err(backoff::Error::Permanent(())) + } + }; + + // parse body + match response.text().await { + Ok(body) => Ok(match serde_json::from_str(&body) { + Ok(json) => json, + Err(e) => { + logger.error("Transpose request unsucessful."); + logger.debug(&format!("curl: curl -X GET \"https://api.transpose.io/sql\" -H \"accept: application/json\" -H \"Content-Type: application/json\" -H \"X-API-KEY: {api_key}\" -d {query}")); + logger.error(&format!("error: {e}")); + logger.debug(&format!("response body: {body:?}")); + return Err(backoff::Error::Permanent(())) + } + }), + Err(e) => { + logger.error("failed to parse Transpose response body."); + logger.error(&format!("error: {e}")); + Err(backoff::Error::Permanent(())) + } } - }), - Err(e) => { - logger.error("failed to parse Transpose response body."); - logger.error(&format!("error: {e}")); - std::process::exit(1) - } - } + }, + ).await + .ok() } /// Get all interactions with the given address. Includes transactions to, from, as well as internal @@ -115,7 +125,7 @@ pub async fn get_transaction_list( bounds.1 ); - let response = match _call_transpose(&query, api_key).await { + let response = match call_transpose(&query, api_key).await { Some(response) => response, None => { logger.error("failed to get transaction list from Transpose"); @@ -197,7 +207,7 @@ pub async fn get_contract_creation( "{{\"sql\":\"SELECT block_number, transaction_hash FROM {chain}.transactions WHERE TIMESTAMP = ( SELECT created_timestamp FROM {chain}.accounts WHERE address = '{address}' ) AND contract_address = '{address}'\",\"parameters\":{{}},\"options\":{{\"timeout\": 999999999}}}}", ); - let response = match _call_transpose(&query, api_key).await { + let response = match call_transpose(&query, api_key).await { Some(response) => response, None => { logger.error("failed to get creation tx from Transpose");