tiders_rpc_client/
config.rs

1use crate::query::TraceMethod;
2
3/// All configuration for the RPC client, including both connection settings
4/// and stream behaviour.
5#[derive(Debug, Clone)]
6pub struct ClientConfig {
7    /// JSON-RPC endpoint URL.
8    pub url: String,
9    /// Optional bearer token for authenticated providers.
10    pub bearer_token: Option<String>,
11    /// Maximum number of retries for a single RPC call.
12    pub max_num_retries: u32,
13    /// Fixed per-retry delay in milliseconds used by alloy's `RetryBackoffLayer`.
14    pub retry_backoff_ms: u64,
15    /// Base delay for exponential backoff (used by per-block retry loops, not by alloy).
16    pub retry_base_ms: u64,
17    /// Maximum delay for exponential backoff (used by per-block retry loops, not by alloy).
18    pub retry_ceiling_ms: u64,
19    /// Per-request HTTP timeout in milliseconds.
20    pub req_timeout_millis: u64,
21    /// Compute-unit rate limit for alloy's `RetryBackoffLayer`.
22    pub compute_units_per_second: Option<u64>,
23    /// Initial number of blocks per batch in simple pipeline mode; Response size (in blocks) in multi-pipeline mode (impact memory usage).
24    pub batch_size: Option<usize>,
25    /// Override the trace method for all trace requests.
26    pub trace_method: Option<TraceMethod>,
27    /// When `true`, stop the stream after reaching the chain head instead of
28    /// entering live-polling mode.
29    pub stop_on_head: bool,
30    /// How often to poll for new blocks during live mode, in milliseconds.
31    pub head_poll_interval_millis: u64,
32    /// Bounded channel capacity for the `ArrowResponse` stream.
33    pub buffer_size: usize,
34    /// Number of blocks behind the head to stay, to avoid reorged data.
35    pub reorg_safe_distance: u64,
36}
37
38impl ClientConfig {
39    /// Create a new configuration with sensible defaults for the given RPC URL.
40    pub fn new(url: String) -> Self {
41        Self {
42            url,
43            bearer_token: None,
44            max_num_retries: 5000,
45            retry_backoff_ms: 1000,
46            retry_base_ms: 300,
47            retry_ceiling_ms: 10_000,
48            req_timeout_millis: 30_000,
49            compute_units_per_second: None,
50            batch_size: None,
51            trace_method: None,
52            stop_on_head: false,
53            head_poll_interval_millis: 1000,
54            buffer_size: 10,
55            reorg_safe_distance: 0,
56        }
57    }
58}