Expand description
A Solana RPC client that implements hedged requests across multiple providers.
This library races RPC requests to multiple endpoints and returns the first successful response, significantly reducing tail latency while maintaining reliability.
§Quick Start
use hedged_rpc_client::{HedgedRpcClient, HedgeConfig, ProviderConfig, ProviderId};
use std::time::Duration;
let providers = vec![
ProviderConfig {
id: ProviderId("helius"),
url: "https://mainnet.helius-rpc.com".to_string(),
},
ProviderConfig {
id: ProviderId("triton"),
url: "https://triton.helius.xyz".to_string(),
},
];
let config = HedgeConfig::low_latency(providers.len());
let client = HedgedRpcClient::new(providers, config);
let (provider, blockhash) = client.get_latest_blockhash().await?;
println!("Got blockhash from {}: {}", provider.0, blockhash);§Hedging Strategy
The client uses a configurable hedging strategy:
- Initially queries
initial_providersendpoints - If no response after
hedge_afterduration, fans out to more providers - Returns the first successful response
- Times out after
overall_timeoutif all providers fail
§Preset Configurations
Use HedgeConfig::low_latency(), ::conservative(), or ::aggressive() for
common hedging strategies, or create a custom configuration.
Re-exports§
pub use client::HedgedRpcClient;pub use client::ProviderStatsSnapshot;pub use config::HedgeConfig;pub use config::ProviderConfig;pub use config::ProviderId;pub use errors::HedgedError;
Modules§
Structs§
- Hash
- A hash; the 32-byte output of a hashing algorithm.
- Pubkey
- The address of a Solana account.