Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
619 changes: 442 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ version = "0.1.0"
edition = "2021"

[dependencies]
axum = "0.8.6"
tokio = { version = "1.48.0", features = ["full"] }
axum = "0.8.9"
reqwest = { version = "0.13.3", features = ["json"] }
tokio = { version = "1.52.1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
futures = "0.3"
tokio-stream = "0.1"
clap = { version = "4.5.51", features = ["env", "derive"] }
alloy = { version = "1.7.3", features = ["provider-ws"] }
thiserror = "2.0.17"
clap = { version = "4.6.1", features = ["env", "derive"] }
alloy = { version = "2.0.4", features = ["provider-ws", "getrandom"] }
thiserror = "2.0.18"
tracing = "0.1.43"
tracing-subscriber = { version = "0.3.22", features = ["json", "env-filter"] }
tokio-util = { version = "0.7.17" }
tower-http = { version = "0.6", features = ["cors"] }

metrics = "0.24"
metrics-exporter-prometheus = "0.16"
rustls = { version = "0.23", features = ["ring"], default-features = false }
metrics = "0.24.5"
metrics-exporter-prometheus = "0.18.3"
rustls = { version = "0.23.40", features = ["ring"], default-features = false }
backon = "1"
uuid = { version = "1.22.0", features = ["v4"] }
uuid = { version = "1.23.1", features = ["v4"] }

[dev-dependencies]
wiremock = "0.6.5"
serde_json="1.0.149"
14 changes: 14 additions & 0 deletions src/config/back_off_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use backon::ExponentialBuilder;
use std::time::Duration;

const TOKEN_LIST_FETCHER_BACKOFFS: usize = 3;

// token list fetcher backoff configuration
// needed to handle errors when load token list
pub fn get_token_list_fetcher_backoff() -> ExponentialBuilder {
ExponentialBuilder::default()
.with_min_delay(Duration::from_secs(1))
.with_max_delay(Duration::from_secs(3))
.with_max_times(TOKEN_LIST_FETCHER_BACKOFFS)
.with_jitter()
}
3 changes: 0 additions & 3 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use std::time::Duration;

/// Maximum number of concurrent HTTP requests when fetching token lists
pub const TOKEN_FETCH_CONCURRENCY: usize = 5;

/// Capacity of the broadcast channel for balance events per subscription
pub const BROADCAST_CHANNEL_CAPACITY: usize = 256;

Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod back_off_config;
pub mod constants;
pub mod network_config;
2 changes: 0 additions & 2 deletions src/domain/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ use serde::{Deserialize, Serialize};
#[serde(rename_all = "camelCase")]
pub struct Token {
pub address: Address,
pub name: String,
pub decimals: u8,
pub chain_id: u64,
}
8 changes: 6 additions & 2 deletions src/services/session_manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::back_off_config::get_token_list_fetcher_backoff;
use crate::domain::{BalanceEvent, EvmNetwork, Session};
use crate::services::balance_fetcher::BalanceFetcher;
use crate::services::cleanup_stream;
Expand All @@ -19,9 +20,11 @@ use serde::Serialize;
use std::collections::{HashMap, HashSet};
use std::convert::Infallible;
use std::sync::Arc;
use std::time::Instant;
use std::time::{Duration, Instant};
use tokio_stream::wrappers::BroadcastStream;

const TOKEN_LIST_CACHE_TTL: Duration = Duration::from_hours(5);

// handle subscriptions: fetch token lists, spawn watchers, update watched tokens
pub struct SessionManager {
sub_manager: Arc<SubscriptionManager>,
Expand Down Expand Up @@ -95,7 +98,8 @@ impl SessionManager {
snapshot_interval: usize,
token_limit: usize,
) -> Self {
let token_list_fetcher = TokenListFetcher::new();
let token_list_fetcher =
TokenListFetcher::new(TOKEN_LIST_CACHE_TTL, get_token_list_fetcher_backoff());

let sub_manager = Arc::new(SubscriptionManager::new());
Arc::clone(&sub_manager).spawn_cleanup();
Expand Down
Loading
Loading