From 95416ae09cb85bc99f144b3f096c5ad700891ff7 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 5 Apr 2024 13:49:34 -0400 Subject: [PATCH] chore: fix formatting --- justfile | 43 ++++---- rustfmt.toml | 28 ++--- src/analytics/mod.rs | 46 ++++---- src/env/mod.rs | 152 +++++++++++++-------------- src/error.rs | 4 +- src/handlers/balance.rs | 26 +++-- src/handlers/metrics.rs | 5 +- src/handlers/profile/address.rs | 8 +- src/handlers/profile/attributes.rs | 4 +- src/handlers/profile/register.rs | 23 ++-- src/lib.rs | 32 +----- src/metrics.rs | 139 +++++++++++++----------- src/project/config.rs | 4 +- src/project/metrics/mod.rs | 9 +- src/project/storage/config.rs | 3 +- src/providers/coinbase.rs | 10 +- src/providers/infura.rs | 10 +- src/providers/mod.rs | 36 ++++--- src/providers/one_inch.rs | 8 +- src/providers/zerion.rs | 19 ++-- src/providers/zora.rs | 10 +- src/storage/redis/mod.rs | 3 +- tests/functional/database.rs | 78 ++++++++------ tests/functional/http/aurora.rs | 6 +- tests/functional/http/base.rs | 6 +- tests/functional/http/binance.rs | 6 +- tests/functional/http/infura.rs | 6 +- tests/functional/http/mantle.rs | 6 +- tests/functional/http/near.rs | 6 +- tests/functional/http/publicnode.rs | 6 +- tests/functional/http/quicknode.rs | 6 +- tests/functional/http/zksync.rs | 6 +- tests/functional/http/zora.rs | 6 +- tests/functional/websocket/infura.rs | 3 +- tests/functional/websocket/zora.rs | 3 +- 35 files changed, 356 insertions(+), 410 deletions(-) diff --git a/justfile b/justfile index e038402ec..efac9004d 100644 --- a/justfile +++ b/justfile @@ -39,7 +39,6 @@ alias clean := cargo-clean alias check := cargo-check alias clippy := cargo-clippy alias udeps := cargo-udeps -alias checkfmt := cargo-checkfmt alias tfsec := tf-tfsec alias tflint := tf-tflint @@ -47,13 +46,6 @@ alias tflint := tf-tflint ################################################################################ # Meta recipes -# Format the project code -fmt target='all': (_check-string-in-set target "all,rust,tf") - #!/bin/bash - set -euo pipefail - [[ '{{ target }}' == 'all' || '{{ target }}' == 'rust' ]] && { just cargo-fmt; } - [[ '{{ target }}' == 'all' || '{{ target }}' == 'tf' ]] && { just tf-fmt; } - # Update project documentation docs target='all': (_check-string-in-set target "all,rust,tf") #!/bin/bash @@ -62,7 +54,7 @@ docs target='all': (_check-string-in-set target "all,rust,tf") [[ '{{ target }}' == 'all' || '{{ target }}' == 'tf' ]] && { just tf-docs; } # Run linting and tests -devloop: lint cargo-test-all +devloop: lint cargo-test-all fmt-imports ################################################################################ # Linting recipes @@ -76,7 +68,7 @@ lint target='all': (_check-string-in-set target "all,rust,tf") # Lint the rust project for any quality issues -lint-rust: cargo-check cargo-clippy cargo-udeps cargo-checkfmt +lint-rust: cargo-clippy fmt cargo-udeps # Lint the terrafrom project for any quality issues lint-tf: tf-checkfmt tf-validate tf-tfsec tf-tflint @@ -116,7 +108,6 @@ cargo target='' sub-target='': (_check-string-in-set target "open-docs,build-doc [[ '{{ target }}' == 'check' ]] && { just cargo-check; } [[ '{{ target }}' == 'clippy' ]] && { just cargo-clippy; } [[ '{{ target }}' == 'udeps' ]] && { just cargo-udeps; } - [[ '{{ target }}' == 'checkfmt' ]] && { just cargo-checkfmt; } # Open rust project documentation in your local browser cargo-open-docs: (_cargo-build-docs "open" "nodeps") @@ -129,10 +120,27 @@ cargo-build-docs: (_cargo-build-docs "" "nodeps") echo "==> Building project documentation @$JUST_ROOT/target/doc" cargo doc --all-features --document-private-items ${nodeps:+--no-deps} ${open:+--open} -# Format the application code -@cargo-fmt: _check-cmd-cargo-fmt - printf '==> Running {{ color-cmd }}rustfmt{{ nocolor }}\n' - cargo +nightly fmt +fmt: + #!/bin/bash + set -euo pipefail + + if command -v cargo-fmt >/dev/null; then + echo '==> Running rustfmt' + cargo fmt + else + echo '==> rustfmt not found in PATH, skipping' + fi + +fmt-imports: + #!/bin/bash + set -euo pipefail + + if command -v cargo-fmt >/dev/null; then + echo '==> Running rustfmt' + cargo +nightly fmt -- --config group_imports=StdExternalCrate,imports_granularity=One + else + echo '==> rustfmt not found in PATH, skipping' + fi # Build service for development cargo-build: _check-cmd-cargo @@ -191,11 +199,6 @@ cargo-udeps: _check-cmd-cargo-udeps @printf '==> Running {{ color-cmd }}udeps{{ nocolor }}\n' cargo +nightly udeps -# Check the rust code formatting -cargo-checkfmt: _check-cmd-cargo-fmt - @printf '==> Running {{ color-cmd }}rustfmt{{ nocolor }} --check\n' - cargo +nightly fmt --check - ################################################################################ # Terraform recipes diff --git a/rustfmt.toml b/rustfmt.toml index c39c39ab4..e58473296 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,18 +1,22 @@ edition = "2021" -fn_single_line = false -format_code_in_doc_comments = true -format_strings = true -imports_layout = "HorizontalVertical" -imports_granularity = "One" -normalize_comments = true -normalize_doc_attributes = true + reorder_imports = true -reorder_impl_items = true -group_imports = "StdExternalCrate" use_try_shorthand = true -wrap_comments = true -overflow_delimited_expr = true remove_nested_parens = true reorder_modules = true -unstable_features = true use_field_init_shorthand = true + +## We only use settings available in the stable channel + +#fn_single_line = false +#format_code_in_doc_comments = true +#format_strings = true +#imports_layout = "HorizontalVertical" +#imports_granularity = "One" +#normalize_comments = true +#normalize_doc_attributes = true +#reorder_impl_items = true +#group_imports = "StdExternalCrate" +#wrap_comments = true +#overflow_delimited_expr = true +#unstable_features = true diff --git a/src/analytics/mod.rs b/src/analytics/mod.rs index e48139260..9d392a848 100644 --- a/src/analytics/mod.rs +++ b/src/analytics/mod.rs @@ -5,17 +5,8 @@ use { tracing::info, wc::{ analytics::{ - self, - AnalyticsExt, - ArcCollector, - AwsConfig, - AwsExporter, - BatchCollector, - BatchObserver, - CollectionObserver, - Collector, - CollectorConfig, - ExportObserver, + self, AnalyticsExt, ArcCollector, AwsConfig, AwsExporter, BatchCollector, + BatchObserver, CollectionObserver, Collector, CollectorConfig, ExportObserver, ParquetBatchFactory, }, geoip::{self, MaxMindResolver, Resolver}, @@ -23,10 +14,8 @@ use { }, }; pub use { - config::Config, - history_lookup_info::HistoryLookupInfo, - identity_lookup_info::IdentityLookupInfo, - message_info::MessageInfo, + config::Config, history_lookup_info::HistoryLookupInfo, + identity_lookup_info::IdentityLookupInfo, message_info::MessageInfo, onramp_history_lookup_info::OnrampHistoryLookupInfo, }; @@ -79,10 +68,11 @@ where let size = res.as_deref().map(|data| data.len()).unwrap_or(0); let elapsed = elapsed.as_millis() as u64; - wc::metrics::counter!("analytics_batches_finished", 1, &[ - self.0.as_kv(), - success_kv(res.is_ok()) - ]); + wc::metrics::counter!( + "analytics_batches_finished", + 1, + &[self.0.as_kv(), success_kv(res.is_ok())] + ); if let Err(err) = res { tracing::warn!( @@ -106,10 +96,11 @@ where E: std::error::Error, { fn observe_collection(&self, res: &Result<(), E>) { - wc::metrics::counter!("analytics_records_collected", 1, &[ - self.0.as_kv(), - success_kv(res.is_ok()) - ]); + wc::metrics::counter!( + "analytics_records_collected", + 1, + &[self.0.as_kv(), success_kv(res.is_ok())] + ); if let Err(err) = res { tracing::warn!( @@ -126,10 +117,11 @@ where E: std::error::Error, { fn observe_export(&self, elapsed: Duration, res: &Result<(), E>) { - wc::metrics::counter!("analytics_batches_exported", 1, &[ - self.0.as_kv(), - success_kv(res.is_ok()) - ]); + wc::metrics::counter!( + "analytics_batches_exported", + 1, + &[self.0.as_kv(), success_kv(res.is_ok())] + ); let elapsed = elapsed.as_millis() as u64; diff --git a/src/env/mod.rs b/src/env/mod.rs index a8843a848..33941f5db 100644 --- a/src/env/mod.rs +++ b/src/env/mod.rs @@ -12,19 +12,8 @@ use { std::{collections::HashMap, fmt::Display}, }; pub use { - aurora::*, - base::*, - binance::*, - getblock::*, - infura::*, - mantle::*, - near::*, - pokt::*, - publicnode::*, - quicknode::*, - server::*, - zksync::*, - zora::*, + aurora::*, base::*, binance::*, getblock::*, infura::*, mantle::*, near::*, pokt::*, + publicnode::*, quicknode::*, server::*, zksync::*, zora::*, }; mod aurora; mod base; @@ -182,72 +171,77 @@ mod test { values.iter().for_each(set_env_var); - assert_eq!(Config::from_env().unwrap(), Config { - server: ServerConfig { - host: "1.2.3.4".to_owned(), - port: 123, - prometheus_port: 234, - log_level: "TRACE".to_owned(), - external_ip: Some(Ipv4Addr::new(2, 3, 4, 5).into()), - blocked_countries: vec![ - "KP".to_owned(), - "IR".to_owned(), - "CU".to_owned(), - "SY".to_owned(), - ], - s3_endpoint: None, - geoip_db_bucket: Some("GEOIP_DB_BUCKET".to_owned()), - geoip_db_key: Some("GEOIP_DB_KEY".to_owned()), - testing_project_id: Some("TESTING_PROJECT_ID".to_owned()), - validate_project_id: true, - }, - registry: project::Config { - api_url: Some("API_URL".to_owned()), - api_auth_token: Some("API_AUTH_TOKEN".to_owned()), - project_data_cache_ttl: 345, - }, - storage: project::storage::Config { - redis_max_connections: 456, - project_data_redis_addr_read: Some("redis://127.0.0.1/data/read".to_owned()), - project_data_redis_addr_write: Some("redis://127.0.0.1/data/write".to_owned()), - identity_cache_redis_addr_read: Some("redis://127.0.0.1/identity/read".to_owned()), - identity_cache_redis_addr_write: Some( - "redis://127.0.0.1/identity/write".to_owned() - ), - rate_limiting_cache_redis_addr_read: Some( - "redis://127.0.0.1/rate_limit/read".to_owned() - ), - rate_limiting_cache_redis_addr_write: Some( - "redis://127.0.0.1/rate_limit/write".to_owned() - ), - }, - postgres: PostgresConfig { - uri: "postgres://postgres@localhost:5432/postgres".to_owned(), - max_connections: 32, - }, - analytics: analytics::Config { - s3_endpoint: Some("s3://127.0.0.1".to_owned()), - export_bucket: Some("EXPORT_BUCKET".to_owned()), - }, - profiler: ProfilerConfig {}, - providers: ProvidersConfig { - prometheus_query_url: Some("PROMETHEUS_QUERY_URL".to_owned()), - prometheus_workspace_header: Some("PROMETHEUS_WORKSPACE_HEADER".to_owned()), - infura_project_id: "INFURA_PROJECT_ID".to_string(), - pokt_project_id: "POKT_PROJECT_ID".to_string(), - quicknode_api_token: "QUICKNODE_API_TOKEN".to_string(), - zerion_api_key: Some("ZERION_API_KEY".to_owned()), - coinbase_api_key: Some("COINBASE_API_KEY".to_owned()), - coinbase_app_id: Some("COINBASE_APP_ID".to_owned()), - one_inch_api_key: Some("ONE_INCH_API_KEY".to_owned()), - getblock_access_tokens: Some("{}".to_owned()), - }, - rate_limiting: RateLimitingConfig { - max_tokens: Some(100), - refill_interval_sec: Some(1), - refill_rate: Some(10), - }, - }); + assert_eq!( + Config::from_env().unwrap(), + Config { + server: ServerConfig { + host: "1.2.3.4".to_owned(), + port: 123, + prometheus_port: 234, + log_level: "TRACE".to_owned(), + external_ip: Some(Ipv4Addr::new(2, 3, 4, 5).into()), + blocked_countries: vec![ + "KP".to_owned(), + "IR".to_owned(), + "CU".to_owned(), + "SY".to_owned(), + ], + s3_endpoint: None, + geoip_db_bucket: Some("GEOIP_DB_BUCKET".to_owned()), + geoip_db_key: Some("GEOIP_DB_KEY".to_owned()), + testing_project_id: Some("TESTING_PROJECT_ID".to_owned()), + validate_project_id: true, + }, + registry: project::Config { + api_url: Some("API_URL".to_owned()), + api_auth_token: Some("API_AUTH_TOKEN".to_owned()), + project_data_cache_ttl: 345, + }, + storage: project::storage::Config { + redis_max_connections: 456, + project_data_redis_addr_read: Some("redis://127.0.0.1/data/read".to_owned()), + project_data_redis_addr_write: Some("redis://127.0.0.1/data/write".to_owned()), + identity_cache_redis_addr_read: Some( + "redis://127.0.0.1/identity/read".to_owned() + ), + identity_cache_redis_addr_write: Some( + "redis://127.0.0.1/identity/write".to_owned() + ), + rate_limiting_cache_redis_addr_read: Some( + "redis://127.0.0.1/rate_limit/read".to_owned() + ), + rate_limiting_cache_redis_addr_write: Some( + "redis://127.0.0.1/rate_limit/write".to_owned() + ), + }, + postgres: PostgresConfig { + uri: "postgres://postgres@localhost:5432/postgres".to_owned(), + max_connections: 32, + }, + analytics: analytics::Config { + s3_endpoint: Some("s3://127.0.0.1".to_owned()), + export_bucket: Some("EXPORT_BUCKET".to_owned()), + }, + profiler: ProfilerConfig {}, + providers: ProvidersConfig { + prometheus_query_url: Some("PROMETHEUS_QUERY_URL".to_owned()), + prometheus_workspace_header: Some("PROMETHEUS_WORKSPACE_HEADER".to_owned()), + infura_project_id: "INFURA_PROJECT_ID".to_string(), + pokt_project_id: "POKT_PROJECT_ID".to_string(), + quicknode_api_token: "QUICKNODE_API_TOKEN".to_string(), + zerion_api_key: Some("ZERION_API_KEY".to_owned()), + coinbase_api_key: Some("COINBASE_API_KEY".to_owned()), + coinbase_app_id: Some("COINBASE_APP_ID".to_owned()), + one_inch_api_key: Some("ONE_INCH_API_KEY".to_owned()), + getblock_access_tokens: Some("{}".to_owned()), + }, + rate_limiting: RateLimitingConfig { + max_tokens: Some(100), + refill_interval_sec: Some(1), + refill_rate: Some(10), + }, + } + ); values.iter().for_each(reset_env_var); } diff --git a/src/error.rs b/src/error.rs index 632a0421c..4b051f7c6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,6 @@ use { crate::{ - project::ProjectDataError, - storage::error::StorageError, - utils::crypto::CryptoUitlsError, + project::ProjectDataError, storage::error::StorageError, utils::crypto::CryptoUitlsError, }, axum::{response::IntoResponse, Json}, cerberus::registry::RegistryError, diff --git a/src/handlers/balance.rs b/src/handlers/balance.rs index 9adaa6120..550bedb6f 100644 --- a/src/handlers/balance.rs +++ b/src/handlers/balance.rs @@ -30,17 +30,21 @@ pub enum BalanceCurrencies { impl Display for BalanceCurrencies { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - BalanceCurrencies::BTC => "btc", - BalanceCurrencies::ETH => "eth", - BalanceCurrencies::USD => "usd", - BalanceCurrencies::EUR => "eur", - BalanceCurrencies::GBP => "gbp", - BalanceCurrencies::AUD => "aud", - BalanceCurrencies::CAD => "cad", - BalanceCurrencies::INR => "inr", - BalanceCurrencies::JPY => "jpy", - }) + write!( + f, + "{}", + match self { + BalanceCurrencies::BTC => "btc", + BalanceCurrencies::ETH => "eth", + BalanceCurrencies::USD => "usd", + BalanceCurrencies::EUR => "eur", + BalanceCurrencies::GBP => "gbp", + BalanceCurrencies::AUD => "aud", + BalanceCurrencies::CAD => "cad", + BalanceCurrencies::INR => "inr", + BalanceCurrencies::JPY => "jpy", + } + ) } } diff --git a/src/handlers/metrics.rs b/src/handlers/metrics.rs index b59468567..60d92880e 100644 --- a/src/handlers/metrics.rs +++ b/src/handlers/metrics.rs @@ -1,8 +1,5 @@ use { - axum::response::IntoResponse, - hyper::StatusCode, - tracing::error, - wc::metrics::ServiceMetrics, + axum::response::IntoResponse, hyper::StatusCode, tracing::error, wc::metrics::ServiceMetrics, }; pub async fn handler() -> impl IntoResponse { diff --git a/src/handlers/profile/address.rs b/src/handlers/profile/address.rs index 328232c7b..438094486 100644 --- a/src/handlers/profile/address.rs +++ b/src/handlers/profile/address.rs @@ -1,11 +1,7 @@ use { super::{ - super::HANDLER_TASK_METRICS, - utils::is_timestamp_within_interval, - Eip155SupportedChains, - RegisterRequest, - UpdateAddressPayload, - UNIXTIMESTAMP_SYNC_THRESHOLD, + super::HANDLER_TASK_METRICS, utils::is_timestamp_within_interval, Eip155SupportedChains, + RegisterRequest, UpdateAddressPayload, UNIXTIMESTAMP_SYNC_THRESHOLD, }, crate::{ database::{ diff --git a/src/handlers/profile/attributes.rs b/src/handlers/profile/attributes.rs index 241c1ab2a..f42995f8b 100644 --- a/src/handlers/profile/attributes.rs +++ b/src/handlers/profile/attributes.rs @@ -2,9 +2,7 @@ use { super::{ super::HANDLER_TASK_METRICS, utils::{check_attributes, is_timestamp_within_interval}, - Eip155SupportedChains, - RegisterRequest, - UpdateAttributesPayload, + Eip155SupportedChains, RegisterRequest, UpdateAttributesPayload, UNIXTIMESTAMP_SYNC_THRESHOLD, }, crate::{ diff --git a/src/handlers/profile/register.rs b/src/handlers/profile/register.rs index 0f3d13ed2..a2460371d 100644 --- a/src/handlers/profile/register.rs +++ b/src/handlers/profile/register.rs @@ -2,16 +2,10 @@ use { super::{ super::HANDLER_TASK_METRICS, utils::{ - check_attributes, - is_name_format_correct, - is_name_in_allowed_zones, - is_name_length_correct, - is_timestamp_within_interval, + check_attributes, is_name_format_correct, is_name_in_allowed_zones, + is_name_length_correct, is_timestamp_within_interval, }, - Eip155SupportedChains, - RegisterPayload, - RegisterRequest, - ALLOWED_ZONES, + Eip155SupportedChains, RegisterPayload, RegisterRequest, ALLOWED_ZONES, UNIXTIMESTAMP_SYNC_THRESHOLD, }, crate::{ @@ -122,10 +116,13 @@ pub async fn handler_internal( } // Register (insert) a new domain with address - let addresses: ENSIP11AddressesMap = HashMap::from([(register_request.coin_type, Address { - address: register_request.address, - created_at: None, - })]); + let addresses: ENSIP11AddressesMap = HashMap::from([( + register_request.coin_type, + Address { + address: register_request.address, + created_at: None, + }, + )]); let insert_result = insert_name( payload.name.clone(), diff --git a/src/lib.rs b/src/lib.rs index 95a1b7f2c..df9beddb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,39 +18,17 @@ use { Router, }, env::{ - AuroraConfig, - BaseConfig, - BinanceConfig, - GetBlockConfig, - InfuraConfig, - MantleConfig, - NearConfig, - PoktConfig, - PublicnodeConfig, - QuicknodeConfig, - ZKSyncConfig, - ZoraConfig, + AuroraConfig, BaseConfig, BinanceConfig, GetBlockConfig, InfuraConfig, MantleConfig, + NearConfig, PoktConfig, PublicnodeConfig, QuicknodeConfig, ZKSyncConfig, ZoraConfig, }, error::RpcResult, http::Request, hyper::{body::Incoming, header::HeaderName, http}, hyper_util::{rt::TokioIo, server}, providers::{ - AuroraProvider, - BaseProvider, - BinanceProvider, - GetBlockProvider, - InfuraProvider, - InfuraWsProvider, - MantleProvider, - NearProvider, - PoktProvider, - ProviderRepository, - PublicnodeProvider, - QuicknodeProvider, - ZKSyncProvider, - ZoraProvider, - ZoraWsProvider, + AuroraProvider, BaseProvider, BinanceProvider, GetBlockProvider, InfuraProvider, + InfuraWsProvider, MantleProvider, NearProvider, PoktProvider, ProviderRepository, + PublicnodeProvider, QuicknodeProvider, ZKSyncProvider, ZoraProvider, ZoraWsProvider, }, sqlx::postgres::PgPoolOptions, std::{ diff --git a/src/metrics.rs b/src/metrics.rs index a4aed5202..004c011b2 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -6,11 +6,7 @@ use { hyper::http, std::time::{Duration, SystemTime}, sysinfo::{ - CpuRefreshKind, - MemoryRefreshKind, - RefreshKind, - System, - MINIMUM_CPU_UPDATE_INTERVAL, + CpuRefreshKind, MemoryRefreshKind, RefreshKind, System, MINIMUM_CPU_UPDATE_INTERVAL, }, wc::metrics::{ otel::{ @@ -258,33 +254,41 @@ impl Metrics { impl Metrics { pub fn add_rpc_call(&self, chain_id: String) { - self.rpc_call_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( - "chain.id", chain_id, - )]); + self.rpc_call_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new("chain.id", chain_id)], + ); } pub fn add_http_call(&self, code: u16, route: String) { - self.http_call_counter.add(&otel::Context::new(), 1, &[ - otel::KeyValue::new("code", i64::from(code)), - otel::KeyValue::new("route", route), - ]); + self.http_call_counter.add( + &otel::Context::new(), + 1, + &[ + otel::KeyValue::new("code", i64::from(code)), + otel::KeyValue::new("route", route), + ], + ); } pub fn add_http_latency(&self, code: u16, route: String, latency: f64) { - self.http_latency_tracker - .record(&otel::Context::new(), latency, &[ + self.http_latency_tracker.record( + &otel::Context::new(), + latency, + &[ otel::KeyValue::new("code", i64::from(code)), otel::KeyValue::new("route", route), - ]) + ], + ) } pub fn add_external_http_latency(&self, provider_kind: ProviderKind, latency: f64) { - self.http_external_latency_tracker - .record(&otel::Context::new(), latency, &[otel::KeyValue::new( - "provider", - provider_kind.to_string(), - )]) + self.http_external_latency_tracker.record( + &otel::Context::new(), + latency, + &[otel::KeyValue::new("provider", provider_kind.to_string())], + ) } pub fn add_rejected_project(&self) { @@ -298,27 +302,36 @@ impl Metrics { } pub fn add_rate_limited_call(&self, provider: &dyn RpcProvider, project_id: String) { - self.rate_limited_call_counter - .add(&otel::Context::new(), 1, &[ + self.rate_limited_call_counter.add( + &otel::Context::new(), + 1, + &[ otel::KeyValue::new("provider_kind", provider.provider_kind().to_string()), otel::KeyValue::new("project_id", project_id), - ]) + ], + ) } pub fn add_failed_provider_call(&self, provider: &dyn RpcProvider) { - self.provider_failed_call_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( + self.provider_failed_call_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new( "provider", provider.provider_kind().to_string(), - )]) + )], + ) } pub fn add_finished_provider_call(&self, provider: &dyn RpcProvider) { - self.provider_finished_call_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( + self.provider_finished_call_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new( "provider", provider.provider_kind().to_string(), - )]) + )], + ) } pub fn add_status_code_for_provider( @@ -327,20 +340,26 @@ impl Metrics { status: http::StatusCode, chain_id: String, ) { - self.provider_status_code_counter - .add(&otel::Context::new(), 1, &[ + self.provider_status_code_counter.add( + &otel::Context::new(), + 1, + &[ otel::KeyValue::new("provider", provider.provider_kind().to_string()), otel::KeyValue::new("status_code", format!("{}", status.as_u16())), otel::KeyValue::new("chain_id", chain_id), - ]) + ], + ) } pub fn record_provider_weight(&self, provider: &ProviderKind, chain_id: String, weight: u64) { - self.weights_value_recorder - .record(&otel::Context::new(), weight, &[ + self.weights_value_recorder.record( + &otel::Context::new(), + weight, + &[ otel::KeyValue::new("provider", provider.to_string()), otel::KeyValue::new("chain_id", chain_id), - ]) + ], + ) } pub fn add_identity_lookup(&self) { @@ -349,11 +368,11 @@ impl Metrics { } pub fn add_identity_lookup_success(&self, source: &IdentityLookupSource) { - self.identity_lookup_success_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( - "source", - source.as_str(), - )]); + self.identity_lookup_success_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new("source", source.as_str())], + ); } pub fn add_identity_lookup_latency(&self, latency: Duration, source: &IdentityLookupSource) { @@ -428,26 +447,27 @@ impl Metrics { } pub fn add_websocket_connection(&self, chain_id: String) { - self.websocket_connection_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( - "chain_id", chain_id, - )]); + self.websocket_connection_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new("chain_id", chain_id)], + ); } pub fn add_history_lookup(&self, provider: &ProviderKind) { - self.history_lookup_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( - "provider", - provider.to_string(), - )]); + self.history_lookup_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new("provider", provider.to_string())], + ); } pub fn add_history_lookup_success(&self, provider: &ProviderKind) { - self.history_lookup_success_counter - .add(&otel::Context::new(), 1, &[otel::KeyValue::new( - "provider", - provider.to_string(), - )]); + self.history_lookup_success_counter.add( + &otel::Context::new(), + 1, + &[otel::KeyValue::new("provider", provider.to_string())], + ); } pub fn add_history_lookup_latency(&self, provider: &ProviderKind, latency: Duration) { @@ -459,10 +479,11 @@ impl Metrics { } fn add_cpu_usage(&self, usage: f64, cpu_id: f64) { - self.cpu_usage - .record(&otel::Context::new(), usage, &[otel::KeyValue::new( - "cpu", cpu_id, - )]); + self.cpu_usage.record( + &otel::Context::new(), + usage, + &[otel::KeyValue::new("cpu", cpu_id)], + ); } fn add_memory_total(&self, memory: f64) { diff --git a/src/project/config.rs b/src/project/config.rs index 85339342e..fd08a2852 100644 --- a/src/project/config.rs +++ b/src/project/config.rs @@ -1,7 +1,5 @@ use { - serde::Deserialize, - serde_piecewise_default::DeserializePiecewiseDefault, - std::time::Duration, + serde::Deserialize, serde_piecewise_default::DeserializePiecewiseDefault, std::time::Duration, }; #[derive(DeserializePiecewiseDefault, Debug, Clone, PartialEq, Eq)] diff --git a/src/project/metrics/mod.rs b/src/project/metrics/mod.rs index 0b46dbd52..efb8784ee 100644 --- a/src/project/metrics/mod.rs +++ b/src/project/metrics/mod.rs @@ -59,10 +59,11 @@ impl ProjectDataMetrics { } pub fn request(&self, time: Duration, source: ResponseSource, resp: &ProjectDataResult) { - self.requests_total.add(&otel::Context::new(), 1, &[ - source_tag(source), - response_tag(resp), - ]); + self.requests_total.add( + &otel::Context::new(), + 1, + &[source_tag(source), response_tag(resp)], + ); self.total_time .record(&otel::Context::new(), duration_ms(time), &[]); } diff --git a/src/project/storage/config.rs b/src/project/storage/config.rs index 8f1debd72..0e9717f0b 100644 --- a/src/project/storage/config.rs +++ b/src/project/storage/config.rs @@ -1,6 +1,5 @@ use { - crate::storage::redis::Addr as RedisAddr, - serde::Deserialize, + crate::storage::redis::Addr as RedisAddr, serde::Deserialize, serde_piecewise_default::DeserializePiecewiseDefault, }; diff --git a/src/providers/coinbase.rs b/src/providers/coinbase.rs index 4df092444..880d8680a 100644 --- a/src/providers/coinbase.rs +++ b/src/providers/coinbase.rs @@ -4,13 +4,9 @@ use { error::{RpcError, RpcResult}, handlers::{ history::{ - HistoryQueryParams, - HistoryResponseBody, - HistoryTransaction, - HistoryTransactionFungibleInfo, - HistoryTransactionMetadata, - HistoryTransactionTransfer, - HistoryTransactionTransferQuantity, + HistoryQueryParams, HistoryResponseBody, HistoryTransaction, + HistoryTransactionFungibleInfo, HistoryTransactionMetadata, + HistoryTransactionTransfer, HistoryTransactionTransferQuantity, }, onramp::{ options::{OnRampBuyOptionsParams, OnRampBuyOptionsResponse}, diff --git a/src/providers/infura.rs b/src/providers/infura.rs index 5e084acac..79a9bacf2 100644 --- a/src/providers/infura.rs +++ b/src/providers/infura.rs @@ -1,13 +1,7 @@ use { super::{ - Provider, - ProviderKind, - RateLimited, - RpcProvider, - RpcProviderFactory, - RpcQueryParams, - RpcWsProvider, - WS_PROXY_TASK_METRICS, + Provider, ProviderKind, RateLimited, RpcProvider, RpcProviderFactory, RpcQueryParams, + RpcWsProvider, WS_PROXY_TASK_METRICS, }, crate::{ env::InfuraConfig, diff --git a/src/providers/mod.rs b/src/providers/mod.rs index a1ac18932..1b4b79cb9 100644 --- a/src/providers/mod.rs +++ b/src/providers/mod.rs @@ -369,22 +369,26 @@ pub enum ProviderKind { impl Display for ProviderKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - ProviderKind::Aurora => "Aurora", - ProviderKind::Infura => "Infura", - ProviderKind::Pokt => "Pokt", - ProviderKind::Binance => "Binance", - ProviderKind::ZKSync => "zkSync", - ProviderKind::Publicnode => "Publicnode", - ProviderKind::Base => "Base", - ProviderKind::Zora => "Zora", - ProviderKind::Zerion => "Zerion", - ProviderKind::Coinbase => "Coinbase", - ProviderKind::Quicknode => "Quicknode", - ProviderKind::Near => "Near", - ProviderKind::Mantle => "Mantle", - ProviderKind::GetBlock => "GetBlock", - }) + write!( + f, + "{}", + match self { + ProviderKind::Aurora => "Aurora", + ProviderKind::Infura => "Infura", + ProviderKind::Pokt => "Pokt", + ProviderKind::Binance => "Binance", + ProviderKind::ZKSync => "zkSync", + ProviderKind::Publicnode => "Publicnode", + ProviderKind::Base => "Base", + ProviderKind::Zora => "Zora", + ProviderKind::Zerion => "Zerion", + ProviderKind::Coinbase => "Coinbase", + ProviderKind::Quicknode => "Quicknode", + ProviderKind::Near => "Near", + ProviderKind::Mantle => "Mantle", + ProviderKind::GetBlock => "GetBlock", + } + ) } } diff --git a/src/providers/one_inch.rs b/src/providers/one_inch.rs index 1a3e0530b..88ebe562c 100644 --- a/src/providers/one_inch.rs +++ b/src/providers/one_inch.rs @@ -3,17 +3,13 @@ use { error::{RpcError, RpcResult}, handlers::convert::{ approve::{ - ConvertApproveQueryParams, - ConvertApproveResponseBody, - ConvertApproveTx, + ConvertApproveQueryParams, ConvertApproveResponseBody, ConvertApproveTx, ConvertApproveTxEip155, }, quotes::{ConvertQuoteQueryParams, ConvertQuoteResponseBody, QuoteItem}, tokens::{TokenItem, TokensListQueryParams, TokensListResponseBody}, transaction::{ - ConvertTransactionQueryParams, - ConvertTransactionResponseBody, - ConvertTx, + ConvertTransactionQueryParams, ConvertTransactionResponseBody, ConvertTx, ConvertTxEip155, }, }, diff --git a/src/providers/zerion.rs b/src/providers/zerion.rs index 607b2e827..bbfb62e0d 100644 --- a/src/providers/zerion.rs +++ b/src/providers/zerion.rs @@ -5,19 +5,12 @@ use { handlers::{ balance::{BalanceQueryParams, BalanceResponseBody}, history::{ - HistoryQueryParams, - HistoryResponseBody, - HistoryTransaction, - HistoryTransactionFungibleInfo, - HistoryTransactionMetadata, - HistoryTransactionMetadataApplication, - HistoryTransactionNFTContent, - HistoryTransactionNFTInfo, - HistoryTransactionNFTInfoFlags, - HistoryTransactionTransfer, - HistoryTransactionTransferQuantity, - HistoryTransactionURLItem, - HistoryTransactionURLandContentTypeItem, + HistoryQueryParams, HistoryResponseBody, HistoryTransaction, + HistoryTransactionFungibleInfo, HistoryTransactionMetadata, + HistoryTransactionMetadataApplication, HistoryTransactionNFTContent, + HistoryTransactionNFTInfo, HistoryTransactionNFTInfoFlags, + HistoryTransactionTransfer, HistoryTransactionTransferQuantity, + HistoryTransactionURLItem, HistoryTransactionURLandContentTypeItem, }, portfolio::{PortfolioPosition, PortfolioQueryParams, PortfolioResponseBody}, }, diff --git a/src/providers/zora.rs b/src/providers/zora.rs index ea1648c27..bd668b06b 100644 --- a/src/providers/zora.rs +++ b/src/providers/zora.rs @@ -1,13 +1,7 @@ use { super::{ - Provider, - ProviderKind, - RateLimited, - RpcProvider, - RpcProviderFactory, - RpcQueryParams, - RpcWsProvider, - WS_PROXY_TASK_METRICS, + Provider, ProviderKind, RateLimited, RpcProvider, RpcProviderFactory, RpcQueryParams, + RpcWsProvider, WS_PROXY_TASK_METRICS, }, crate::{ env::ZoraConfig, diff --git a/src/storage/redis/mod.rs b/src/storage/redis/mod.rs index 6da787c17..21370fa7b 100644 --- a/src/storage/redis/mod.rs +++ b/src/storage/redis/mod.rs @@ -3,8 +3,7 @@ use { async_trait::async_trait, deadpool_redis::{ redis::{AsyncCommands, Value}, - Config, - Pool, + Config, Pool, }, serde::{de::DeserializeOwned, Serialize}, std::{fmt::Debug, time::Duration}, diff --git a/tests/functional/database.rs b/tests/functional/database.rs index c0b976df9..5eb8fa3b2 100644 --- a/tests/functional/database.rs +++ b/tests/functional/database.rs @@ -2,15 +2,9 @@ use { crate::utils::{generate_random_string, get_postgres_pool}, rpc_proxy::database::{ helpers::{ - delete_address, - delete_name, - get_addresses_by_name, - get_name, - get_name_and_addresses_by_name, - get_names_by_address, - get_names_by_address_and_namespace, - insert_name, - insert_or_update_address, + delete_address, delete_name, get_addresses_by_name, get_name, + get_name_and_addresses_by_name, get_names_by_address, + get_names_by_address_and_namespace, insert_name, insert_or_update_address, update_name_attributes, }, types, @@ -25,10 +19,13 @@ async fn insert_and_get_name_by_name() { let name = format!("{}.connect.id", generate_random_string(10)); let address = format!("0x{}", generate_random_string(16)); let chain_id = 1; - let addresses = HashMap::from([(chain_id, types::Address { - address, - created_at: None, - })]); + let addresses = HashMap::from([( + chain_id, + types::Address { + address, + created_at: None, + }, + )]); // create a new hashmap with attributes let attributes: HashMap = HashMap::from_iter([ @@ -77,10 +74,13 @@ async fn insert_and_get_names_by_address() { let name = format!("{}.connect.id", generate_random_string(10)); let address = format!("0x{}", generate_random_string(16)); let chain_id = 1; - let addresses = HashMap::from([(chain_id, types::Address { - address: address.clone(), - created_at: None, - })]); + let addresses = HashMap::from([( + chain_id, + types::Address { + address: address.clone(), + created_at: None, + }, + )]); let insert_result = insert_name( name.clone(), @@ -114,10 +114,13 @@ async fn insert_and_get_names_by_address_and_namespace() { let address = format!("0x{}", generate_random_string(16)); let namespace = types::SupportedNamespaces::Eip155; let chain_id = 1; - let addresses = HashMap::from([(chain_id, types::Address { - address: address.clone(), - created_at: None, - })]); + let addresses = HashMap::from([( + chain_id, + types::Address { + address: address.clone(), + created_at: None, + }, + )]); let insert_result = insert_name( name.clone(), @@ -151,10 +154,13 @@ async fn insert_and_get_name_and_addresses() { let address = format!("0x{}", generate_random_string(16)); let namespace = types::SupportedNamespaces::Eip155; let expected_ensip11_coin_type = 60; - let addresses = HashMap::from([(expected_ensip11_coin_type, types::Address { - address: address.clone(), - created_at: None, - })]); + let addresses = HashMap::from([( + expected_ensip11_coin_type, + types::Address { + address: address.clone(), + created_at: None, + }, + )]); let attributes: HashMap = HashMap::from_iter([( "avatar".to_string(), @@ -201,10 +207,13 @@ async fn insert_and_update_name_attributes() { let name = format!("{}.connect.id", generate_random_string(10)); let address = format!("0x{}", generate_random_string(16)); let chain_id = 1; - let addresses = HashMap::from([(chain_id, types::Address { - address, - created_at: None, - })]); + let addresses = HashMap::from([( + chain_id, + types::Address { + address, + created_at: None, + }, + )]); // create a new hashmap with attributes let attributes: HashMap = HashMap::from_iter([ @@ -264,10 +273,13 @@ async fn insert_delete_two_addresses() { let name = format!("{}.connect.id", generate_random_string(10)); let address = format!("0x{}", generate_random_string(16)); let mut chain_id = 1; - let addresses = HashMap::from([(chain_id, types::Address { - address: address.clone(), - created_at: None, - })]); + let addresses = HashMap::from([( + chain_id, + types::Address { + address: address.clone(), + created_at: None, + }, + )]); let insert_result = insert_name( name.clone(), diff --git a/tests/functional/http/aurora.rs b/tests/functional/http/aurora.rs index 9b813c71d..087ed3a76 100644 --- a/tests/functional/http/aurora.rs +++ b/tests/functional/http/aurora.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/base.rs b/tests/functional/http/base.rs index 3293109e7..1e4c5ead5 100644 --- a/tests/functional/http/base.rs +++ b/tests/functional/http/base.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/binance.rs b/tests/functional/http/binance.rs index 84387cc02..d517d7bf3 100644 --- a/tests/functional/http/binance.rs +++ b/tests/functional/http/binance.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/infura.rs b/tests/functional/http/infura.rs index 118522391..283d5a1ad 100644 --- a/tests/functional/http/infura.rs +++ b/tests/functional/http/infura.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/mantle.rs b/tests/functional/http/mantle.rs index 68aa250e3..df464b1f8 100644 --- a/tests/functional/http/mantle.rs +++ b/tests/functional/http/mantle.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/near.rs b/tests/functional/http/near.rs index 2cef51e90..76cdc0625 100644 --- a/tests/functional/http/near.rs +++ b/tests/functional/http/near.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_near_protocol, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_near_protocol, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/publicnode.rs b/tests/functional/http/publicnode.rs index 5173e6fc6..8e79990d0 100644 --- a/tests/functional/http/publicnode.rs +++ b/tests/functional/http/publicnode.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/quicknode.rs b/tests/functional/http/quicknode.rs index e83e90c28..f33833988 100644 --- a/tests/functional/http/quicknode.rs +++ b/tests/functional/http/quicknode.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/zksync.rs b/tests/functional/http/zksync.rs index 8d41a203e..8657c1515 100644 --- a/tests/functional/http/zksync.rs +++ b/tests/functional/http/zksync.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/http/zora.rs b/tests/functional/http/zora.rs index 9c5f7efdd..a980c1de2 100644 --- a/tests/functional/http/zora.rs +++ b/tests/functional/http/zora.rs @@ -1,8 +1,6 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, - rpc_proxy::providers::ProviderKind, - test_context::test_context, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, + rpc_proxy::providers::ProviderKind, test_context::test_context, }; #[test_context(ServerContext)] diff --git a/tests/functional/websocket/infura.rs b/tests/functional/websocket/infura.rs index 92e80e664..379881fef 100644 --- a/tests/functional/websocket/infura.rs +++ b/tests/functional/websocket/infura.rs @@ -1,6 +1,5 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, test_context::test_context, }; diff --git a/tests/functional/websocket/zora.rs b/tests/functional/websocket/zora.rs index 6c5127f9f..cc0d1eb36 100644 --- a/tests/functional/websocket/zora.rs +++ b/tests/functional/websocket/zora.rs @@ -1,6 +1,5 @@ use { - super::check_if_rpc_is_responding_correctly_for_supported_chain, - crate::context::ServerContext, + super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext, test_context::test_context, };