pub struct RpcSelector { /* private fields */ }Expand description
Manages selection of RPC endpoints based on configuration.
Implementations§
Source§impl RpcSelector
impl RpcSelector
Sourcepub fn new(
configs: Vec<RpcConfig>,
failure_threshold: u32,
pause_duration_secs: u64,
failure_expiration_secs: u64,
) -> Result<Self, RpcSelectorError>
pub fn new( configs: Vec<RpcConfig>, failure_threshold: u32, pause_duration_secs: u64, failure_expiration_secs: u64, ) -> Result<Self, RpcSelectorError>
Creates a new RpcSelector instance.
§Arguments
configs- RPC configurationsfailure_threshold- Number of consecutive failures before pausing a provider. Defaults to [DEFAULT_PROVIDER_FAILURE_THRESHOLD] if not provided via env varPROVIDER_FAILURE_THRESHOLD.pause_duration_secs- Duration in seconds to pause a provider after reaching failure threshold. Defaults to [DEFAULT_PROVIDER_PAUSE_DURATION_SECS] if not provided via env varPROVIDER_PAUSE_DURATION_SECS.failure_expiration_secs- Duration in seconds after which failures are considered stale and reset. Defaults to [DEFAULT_PROVIDER_FAILURE_EXPIRATION_SECS] (60 seconds).
§Returns
Result<Self>- A new selector instance or an error
§Note
These values are typically loaded from ServerConfig::from_env() which reads from environment variables:
PROVIDER_FAILURE_THRESHOLD(default: 3, legacy:RPC_FAILURE_THRESHOLD)PROVIDER_PAUSE_DURATION_SECS(default: 60, legacy:RPC_PAUSE_DURATION_SECS)
Sourcepub fn new_with_defaults(
configs: Vec<RpcConfig>,
) -> Result<Self, RpcSelectorError>
pub fn new_with_defaults( configs: Vec<RpcConfig>, ) -> Result<Self, RpcSelectorError>
Creates a new RpcSelector instance with default failure threshold and pause duration.
This is a convenience method primarily for testing. In production code, use new() with
values from ServerConfig::from_env().
§Arguments
configs- RPC configurations
§Returns
Result<Self>- A new selector instance or an error
Sourcepub fn provider_count(&self) -> usize
pub fn provider_count(&self) -> usize
Sourcepub fn available_provider_count(&self) -> usize
pub fn available_provider_count(&self) -> usize
Gets the number of available (non-paused) providers
§Returns
usize- The number of non-paused providers
Sourcepub fn get_configs(&self) -> Vec<RpcConfig>
pub fn get_configs(&self) -> Vec<RpcConfig>
Sourcepub fn mark_current_as_failed(&self)
pub fn mark_current_as_failed(&self)
Marks the current endpoint as failed and forces selection of a different endpoint.
This method is used when a provider consistently fails, and we want to try a different one. It adds the current provider to the failed providers set and will avoid selecting it again.
Sourcepub fn get_current_url(&self) -> Result<String, RpcSelectorError>
pub fn get_current_url(&self) -> Result<String, RpcSelectorError>
Gets the URL of the currently selected RPC endpoint.
§Returns
Result<String, RpcSelectorError>- The URL of the current provider, or an error
Sourcepub fn get_next_url(
&self,
excluded_urls: &HashSet<String>,
) -> Result<String, RpcSelectorError>
pub fn get_next_url( &self, excluded_urls: &HashSet<String>, ) -> Result<String, RpcSelectorError>
Sourcepub fn get_client<T>(
&self,
initializer: impl Fn(&str) -> Result<T>,
excluded_urls: &HashSet<String>,
) -> Result<T, RpcSelectorError>
pub fn get_client<T>( &self, initializer: impl Fn(&str) -> Result<T>, excluded_urls: &HashSet<String>, ) -> Result<T, RpcSelectorError>
Trait Implementations§
Source§impl Clone for RpcSelector
impl Clone for RpcSelector
Auto Trait Implementations§
impl Freeze for RpcSelector
impl !RefUnwindSafe for RpcSelector
impl Send for RpcSelector
impl Sync for RpcSelector
impl Unpin for RpcSelector
impl !UnwindSafe for RpcSelector
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more