From f5ab01f7e9cf8b16a0878d52b28e8264e2eae5e8 Mon Sep 17 00:00:00 2001 From: scx1332 Date: Mon, 11 Mar 2024 17:52:49 +0100 Subject: [PATCH] updating libraries --- Cargo.lock | 157 +++++++++++++++--- Cargo.toml | 4 +- .../erc20_payment_lib/src/sender/service.rs | 14 +- crates/erc20_payment_lib_common/src/utils.rs | 5 +- crates/erc20_rpc_pool/src/rpc_pool/pool.rs | 2 +- crates/erc20_rpc_pool/src/rpc_pool/utils.rs | 5 +- .../src/rpc_pool/verify/verify_impl.rs | 8 +- src/actions/create_deposit.rs | 3 +- 8 files changed, 157 insertions(+), 41 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27eaecce..9e6942ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -522,15 +522,15 @@ dependencies = [ [[package]] name = "base64" -version = "0.13.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" [[package]] name = "base64ct" @@ -585,9 +585,9 @@ dependencies = [ [[package]] name = "bollard" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af254ed2da4936ef73309e9597180558821cb16ae9bba4cb24ce6b612d8d80ed" +checksum = "83545367eb6428eb35c29cdec3a1f350fa8d6d9085d59a7d7bcb637f2e38db5a" dependencies = [ "base64 0.21.7", "bollard-stubs", @@ -595,9 +595,12 @@ dependencies = [ "futures-core", "futures-util", "hex", - "http 0.2.12", - "hyper", - "hyperlocal", + "http 1.1.0", + "http-body-util", + "hyper 1.2.0", + "hyper-named-pipe", + "hyper-util", + "hyperlocal-next", "log", "pin-project-lite", "serde", @@ -608,17 +611,19 @@ dependencies = [ "thiserror", "tokio", "tokio-util", + "tower-service", "url", "winapi", ] [[package]] name = "bollard-stubs" -version = "1.42.0-rc.7" +version = "1.44.0-rc.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602bda35f33aeb571cef387dcd4042c643a8bf689d8aaac2cc47ea24cb7bc7e0" +checksum = "709d9aa1c37abb89d40f19f5d0ad6f0d88cb1581264e571c9350fc5bb89cf1c5" dependencies = [ "serde", + "serde_repr", "serde_with", ] @@ -1863,6 +1868,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "pin-project-lite", +] + [[package]] name = "http-range" version = "0.1.5" @@ -1899,7 +1927,7 @@ dependencies = [ "futures-util", "h2", "http 0.2.12", - "http-body", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -1911,6 +1939,40 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-named-pipe" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b7d8abf35697b81a825e386fc151e0d503e8cb5fcb93cc8669c376dfd6f278" +dependencies = [ + "hex", + "hyper 1.2.0", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", + "winapi", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -1919,23 +1981,45 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.12", - "hyper", + "hyper 0.14.28", "rustls 0.21.10", "tokio", "tokio-rustls 0.24.1", ] [[package]] -name = "hyperlocal" -version = "0.8.0" +name = "hyper-util" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fafdf7b2b2de7c9784f76e02c0935e65a8117ec3b768644379983ab333ac98c" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" dependencies = [ + "bytes", + "futures-channel", "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "hyperlocal-next" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf569d43fa9848e510358c07b80f4adf34084ddc28c6a4a651ee8474c070dcc" +dependencies = [ "hex", - "hyper", - "pin-project", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "pin-project-lite", "tokio", + "tower-service", ] [[package]] @@ -2058,6 +2142,7 @@ checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" dependencies = [ "equivalent", "hashbrown 0.14.3", + "serde", ] [[package]] @@ -2921,8 +3006,8 @@ dependencies = [ "futures-util", "h2", "http 0.2.12", - "http-body", - "hyper", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", @@ -3322,15 +3407,17 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.3.3" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +checksum = "15d167997bd841ec232f5b2b8e0e26606df2e7caa4c31b95ea9ca52b200bd270" dependencies = [ - "base64 0.13.1", + "base64 0.21.7", "chrono", "hex", "indexmap 1.9.3", + "indexmap 2.2.5", "serde", + "serde_derive", "serde_json", "time", ] @@ -4051,6 +4138,28 @@ dependencies = [ "winnow 0.6.5", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + [[package]] name = "tower-service" version = "0.3.2" @@ -4426,7 +4535,7 @@ dependencies = [ "actix-files", "actix-web", "awc", - "base64 0.21.7", + "base64 0.22.0", "chrono", "dotenv", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 80270c48..4ad09195 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,8 @@ actix-web = { version = "4", default-features = false, features = [ actix-web-actors = { version = "4", default-features = false } anyhow = "1" awc = { version = "3.1", features = ["rustls"] } -base64 = "0.21" -bollard = "0.14" +base64 = "0.22" +bollard = "0.16" chrono = { version = "0.4", features = ["serde"] } csv = "1.2" dotenv = "0.15" diff --git a/crates/erc20_payment_lib/src/sender/service.rs b/crates/erc20_payment_lib/src/sender/service.rs index 3e99e2a5..180b8a44 100644 --- a/crates/erc20_payment_lib/src/sender/service.rs +++ b/crates/erc20_payment_lib/src/sender/service.rs @@ -395,8 +395,9 @@ fn get_next_gather_time( last_gather_time: chrono::DateTime, gather_transactions_interval: i64, ) -> chrono::DateTime { - let next_gather_time = - last_gather_time + chrono::Duration::seconds(gather_transactions_interval); + let next_gather_time = last_gather_time + + chrono::Duration::try_seconds(gather_transactions_interval) + .expect("Invalid gather interval"); if let Some(external_gather_time) = *account.external_gather_time.lock().unwrap() { std::cmp::min(external_gather_time, next_gather_time) @@ -412,8 +413,9 @@ fn get_next_gather_time_and_clear_if_success( ) -> Option> { let mut external_gather_time_guard = account.external_gather_time.lock().unwrap(); - let next_gather_time = - last_gather_time + chrono::Duration::seconds(gather_transactions_interval); + let next_gather_time = last_gather_time + + chrono::Duration::try_seconds(gather_transactions_interval) + .expect("Invalid gather transactions interval"); let next_gather_time = if let Some(external_gather_time) = *external_gather_time_guard { std::cmp::min(external_gather_time, next_gather_time) @@ -475,7 +477,9 @@ pub async fn service_loop( ) { let gather_transactions_interval = payment_setup.gather_interval as i64; let mut last_gather_time = if payment_setup.gather_at_start { - chrono::Utc::now() - chrono::Duration::seconds(gather_transactions_interval) + chrono::Utc::now() + - chrono::Duration::try_seconds(gather_transactions_interval) + .expect("Invalid gather interval") } else { chrono::Utc::now() }; diff --git a/crates/erc20_payment_lib_common/src/utils.rs b/crates/erc20_payment_lib_common/src/utils.rs index 231eee6d..2bc983bc 100644 --- a/crates/erc20_payment_lib_common/src/utils.rs +++ b/crates/erc20_payment_lib_common/src/utils.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use rust_decimal::prelude::ToPrimitive; use rust_decimal::Decimal; use std::env; @@ -7,8 +7,7 @@ use std::fmt::{Display, Formatter}; use web3::types::U256; pub fn datetime_from_u256_timestamp(timestamp: U256) -> Option> { - NaiveDateTime::from_timestamp_opt(timestamp.as_u64() as i64, 0) - .map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc)) + DateTime::from_timestamp(timestamp.as_u64() as i64, 0) } pub fn get_env_bool_value(env_name: &str) -> bool { env::var(env_name) diff --git a/crates/erc20_rpc_pool/src/rpc_pool/pool.rs b/crates/erc20_rpc_pool/src/rpc_pool/pool.rs index 15c7b901..97fe690e 100644 --- a/crates/erc20_rpc_pool/src/rpc_pool/pool.rs +++ b/crates/erc20_rpc_pool/src/rpc_pool/pool.rs @@ -311,7 +311,7 @@ impl Web3RpcPool { } fn cleanup_sources_after_grace_period(&self) { - let grace_period = chrono::Duration::seconds(300); + let grace_period = chrono::Duration::try_seconds(300).unwrap(); self.endpoints .try_lock_for(Duration::from_secs(5)) .unwrap() diff --git a/crates/erc20_rpc_pool/src/rpc_pool/utils.rs b/crates/erc20_rpc_pool/src/rpc_pool/utils.rs index 9833df24..bd2278b4 100644 --- a/crates/erc20_rpc_pool/src/rpc_pool/utils.rs +++ b/crates/erc20_rpc_pool/src/rpc_pool/utils.rs @@ -1,7 +1,6 @@ -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use web3::types::U256; pub fn datetime_from_u256_timestamp(timestamp: U256) -> Option> { - NaiveDateTime::from_timestamp_opt(timestamp.as_u64() as i64, 0) - .map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc)) + DateTime::from_timestamp(timestamp.as_u64() as i64, 0) } diff --git a/crates/erc20_rpc_pool/src/rpc_pool/verify/verify_impl.rs b/crates/erc20_rpc_pool/src/rpc_pool/verify/verify_impl.rs index a097bf56..97f3e4dc 100644 --- a/crates/erc20_rpc_pool/src/rpc_pool/verify/verify_impl.rs +++ b/crates/erc20_rpc_pool/src/rpc_pool/verify/verify_impl.rs @@ -50,7 +50,10 @@ async fn verify_endpoint_int( return VerifyEndpointResult::NoBlockInfo; }; if let Some(max_head_behind_secs) = vep.allow_max_head_behind_secs { - if Utc::now() - date > Duration::seconds(max_head_behind_secs as i64) { + if Utc::now() - date + > Duration::try_seconds(max_head_behind_secs as i64) + .expect("max_head_behind_secs invalid value") + { log::warn!("Verify endpoint error - {name} error: Head behind"); return VerifyEndpointResult::HeadBehind(date); } @@ -88,9 +91,10 @@ pub async fn verify_endpoint(chain_id: u64, m: Arc>, for if let Some(last_verified) = web3_rpc_info.last_verified { if !force && Utc::now() - last_verified - < Duration::seconds( + < Duration::try_seconds( web3_rpc_params.web3_endpoint_params.verify_interval_secs as i64, ) + .expect("verify_interval_secs invalid value") { log::debug!("Verification skipped {}", last_verified); return; diff --git a/src/actions/create_deposit.rs b/src/actions/create_deposit.rs index d42faedd..7bac0694 100644 --- a/src/actions/create_deposit.rs +++ b/src/actions/create_deposit.rs @@ -103,7 +103,8 @@ pub async fn make_deposit_local( let timestamp = if let Some(block_for) = make_deposit_options.block_for { let now = Utc::now(); - let date_fut = now + chrono::Duration::seconds(block_for as i64); + let date_fut = + now + chrono::Duration::try_seconds(block_for as i64).expect("Invalid value block_for"); date_fut.timestamp() as u64 } else if let Some(block_until) = make_deposit_options.block_until { block_until.timestamp() as u64