hypersync_client_solana/config.rs
1use std::time::Duration;
2
3/// Configuration for the Solana HyperSync client.
4#[derive(Debug, Clone)]
5pub struct ClientConfig {
6 /// Base URL of the HyperSync server (e.g. "https://solana.hypersync.xyz").
7 pub url: String,
8 /// Bearer token for authenticated requests.
9 pub bearer_token: Option<String>,
10 /// Timeout for individual HTTP requests.
11 pub http_req_timeout: Duration,
12 /// Maximum number of retries per request.
13 pub max_num_retries: u32,
14 /// Base delay for exponential backoff retries.
15 pub retry_base_ms: u64,
16 /// Maximum delay for exponential backoff retries.
17 pub retry_ceiling_ms: u64,
18 /// Whether to proactively sleep when the rate limit is exhausted instead of
19 /// sending requests that will be rejected with 429.
20 ///
21 /// Enabled by default. Set to `false` to opt out and handle rate limits yourself.
22 pub proactive_rate_limit_sleep: bool,
23}
24
25impl Default for ClientConfig {
26 fn default() -> Self {
27 Self {
28 url: String::new(),
29 bearer_token: None,
30 http_req_timeout: Duration::from_secs(30),
31 max_num_retries: 12,
32 retry_base_ms: 500,
33 retry_ceiling_ms: 5_000,
34 proactive_rate_limit_sleep: true,
35 }
36 }
37}
38
39/// Configuration for concurrent streaming.
40#[derive(Debug, Clone)]
41pub struct StreamConfig {
42 /// Number of slots to request per chunk.
43 pub batch_size: u64,
44 /// Maximum batch size (for adaptive sizing).
45 pub max_batch_size: u64,
46 /// Minimum batch size (for adaptive sizing).
47 pub min_batch_size: u64,
48 /// Number of concurrent in-flight requests.
49 pub concurrency: usize,
50 /// Response byte threshold above which batch size shrinks.
51 pub response_bytes_ceiling: u64,
52 /// Response byte threshold below which batch size grows.
53 pub response_bytes_floor: u64,
54}
55
56impl Default for StreamConfig {
57 fn default() -> Self {
58 Self {
59 batch_size: 1_000,
60 max_batch_size: 200_000,
61 min_batch_size: 100,
62 concurrency: 10,
63 response_bytes_ceiling: 500_000,
64 response_bytes_floor: 250_000,
65 }
66 }
67}