Skip to main content

RpcPool

Struct RpcPool 

Source
pub struct RpcPool { /* private fields */ }
Expand description

Pool of RPC endpoints with load balancing and health tracking.

§Memory Considerations

The endpoint list is fixed at construction time. Endpoints are never removed, only marked as unhealthy via the HealthTracker. This is intentional:

  • CLI tools are short-lived, so memory growth isn’t a concern
  • Endpoints may recover after temporary issues (circuit breaker resets)
  • The list size is bounded by user configuration

For long-running daemons, consider implementing periodic cleanup of persistently unhealthy endpoints.

§Block Reorganization Handling

This pool does not account for chain reorganizations. Queries for recent blocks may return data that becomes stale if a reorg occurs. This is acceptable for a CLI tool because:

  • Most queries are for historical data (well past finalization)
  • Real-time queries are point-in-time snapshots by nature
  • Reorg detection would add significant complexity

For applications requiring reorg-aware data, consider waiting for finalization (12-15 confirmations on Ethereum mainnet) or using a service that handles reorgs.

Implementations§

Source§

impl RpcPool

Source

pub fn new(chain: Chain, config: &RpcConfig) -> Result<Self>

Create a new RPC pool for a chain

(PERF-008 fix: Uses iterator-based filtering to avoid intermediate Vec clone)

Source

pub fn from_url(url: &str, timeout_secs: u64) -> Result<Self>

Create from a single endpoint URL

Source

pub fn endpoint_count(&self) -> usize

Get number of available endpoints

Source

pub fn concurrency(&self) -> usize

Get concurrency level

Source

pub fn health_tracker(&self) -> Arc<HealthTracker>

Get health tracker

Source

pub async fn get_block_number(&self) -> Result<u64>

Get current block number (tries multiple endpoints)

Source

pub async fn get_transaction(&self, hash: B256) -> Result<Option<Transaction>>

Get a transaction by hash (tries multiple endpoints)

Source

pub async fn get_transaction_receipt( &self, hash: B256, ) -> Result<Option<TransactionReceipt>>

Get a transaction receipt by hash (tries multiple endpoints)

Source

pub async fn get_block_with_txs( &self, block_number: u64, ) -> Result<Option<Block>>

Get a block by number with full transaction objects (tries multiple endpoints)

Source

pub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>>

Fetch logs with automatic retry and load balancing

Source

pub async fn get_logs_parallel( &self, filters: Vec<Filter>, ) -> Vec<Result<Vec<Log>>>

Fetch logs from multiple filters in parallel

Source

pub fn effective_max_block_range(&self, url: &str) -> u64

Get effective max block range for an endpoint

Source

pub fn min_block_range(&self) -> u64

Get the smallest max block range across all endpoints

Source

pub fn max_block_range(&self) -> u64

Get the largest max block range across healthy endpoints Returns the user-specified chunk_size if set, otherwise uses endpoint limits

Source

pub fn get_endpoint_health(&self) -> Vec<(String, u8, Option<EndpointHealth>)>

Get health info for all endpoints

Source

pub fn list_endpoints(&self) -> Vec<&str>

List all endpoint URLs

Source

pub fn archive_endpoint_count(&self) -> usize

Get count of archive endpoints

Source

pub fn debug_endpoint_count(&self) -> usize

Get count of debug-capable endpoints

Source

pub fn select_archive_endpoints(&self, count: usize) -> Vec<Arc<Endpoint>>

Select endpoints that are known archives (for historical data queries) Falls back to all available endpoints if no archives are known

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more