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
19 changes: 19 additions & 0 deletions crates/core/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ pub struct NetworkConfig {
pub network_passphrase: String,
/// History archive URL(s).
pub archive_urls: Vec<String>,
/// Per-request timeout in seconds for all RPC calls.
///
/// Any request that does not receive a complete response within this
/// window is cancelled and returns [`crate::types::error::PrismError::NetworkTimeout`].
/// Defaults to [`DEFAULT_REQUEST_TIMEOUT_SECS`] (30 s) when deserializing
/// configs that do not specify this field.
#[serde(default = "default_request_timeout_secs")]
pub request_timeout_secs: u64,
}

/// Default per-request timeout: 30 seconds.
pub const DEFAULT_REQUEST_TIMEOUT_SECS: u64 = 30;

fn default_request_timeout_secs() -> u64 {
DEFAULT_REQUEST_TIMEOUT_SECS
}

impl NetworkConfig {
Expand All @@ -50,6 +65,7 @@ impl NetworkConfig {
archive_urls: vec![
"https://history.stellar.org/prd/core-testnet/core_testnet_001".to_string(),
],
request_timeout_secs: DEFAULT_REQUEST_TIMEOUT_SECS,
}
}

Expand All @@ -62,6 +78,7 @@ impl NetworkConfig {
archive_urls: vec![
"https://history.stellar.org/prd/core-live/core_live_001".to_string()
],
request_timeout_secs: DEFAULT_REQUEST_TIMEOUT_SECS,
}
}

Expand All @@ -72,6 +89,7 @@ impl NetworkConfig {
rpc_url: "https://rpc-futurenet.stellar.org".to_string(),
network_passphrase: "Test SDF Future Network ; October 2022".to_string(),
archive_urls: vec!["https://history-futurenet.stellar.org".to_string()],
request_timeout_secs: DEFAULT_REQUEST_TIMEOUT_SECS,
}
}

Expand All @@ -82,6 +100,7 @@ impl NetworkConfig {
rpc_url: rpc_url.to_string(),
network_passphrase: passphrase.to_string(),
archive_urls: Vec::new(),
request_timeout_secs: DEFAULT_REQUEST_TIMEOUT_SECS,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::fmt;
/// Top-level error type for all Prism operations.
#[derive(Debug)]
pub enum PrismError {
/// A network request exceeded the configured timeout duration.
NetworkTimeout { method: String, timeout_secs: u64 },
/// Error communicating with the Soroban RPC endpoint.
RpcError(String),
/// Error fetching or parsing history archive data.
Expand Down Expand Up @@ -34,6 +36,9 @@ pub enum PrismError {
impl fmt::Display for PrismError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NetworkTimeout { method, timeout_secs } => {
write!(f, "RPC request timed out after {timeout_secs}s (method: {method})")
}
Self::RpcError(msg) => write!(f, "RPC error: {msg}"),
Self::ArchiveError(msg) => write!(f, "Archive error: {msg}"),
Self::XdrError(msg) => write!(f, "XDR error: {msg}"),
Expand Down