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
impl RpcPool
Sourcepub fn new(chain: Chain, config: &RpcConfig) -> Result<Self>
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)
Sourcepub fn from_url(url: &str, timeout_secs: u64) -> Result<Self>
pub fn from_url(url: &str, timeout_secs: u64) -> Result<Self>
Create from a single endpoint URL
Sourcepub fn endpoint_count(&self) -> usize
pub fn endpoint_count(&self) -> usize
Get number of available endpoints
Sourcepub fn concurrency(&self) -> usize
pub fn concurrency(&self) -> usize
Get concurrency level
Sourcepub fn health_tracker(&self) -> Arc<HealthTracker>
pub fn health_tracker(&self) -> Arc<HealthTracker>
Get health tracker
Sourcepub async fn get_block_number(&self) -> Result<u64>
pub async fn get_block_number(&self) -> Result<u64>
Get current block number (tries multiple endpoints)
Sourcepub async fn get_transaction(&self, hash: B256) -> Result<Option<Transaction>>
pub async fn get_transaction(&self, hash: B256) -> Result<Option<Transaction>>
Get a transaction by hash (tries multiple endpoints)
Sourcepub async fn get_transaction_receipt(
&self,
hash: B256,
) -> Result<Option<TransactionReceipt>>
pub async fn get_transaction_receipt( &self, hash: B256, ) -> Result<Option<TransactionReceipt>>
Get a transaction receipt by hash (tries multiple endpoints)
Sourcepub async fn get_block_with_txs(
&self,
block_number: u64,
) -> Result<Option<Block>>
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)
Sourcepub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>>
pub async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>>
Fetch logs with automatic retry and load balancing
Sourcepub async fn get_logs_parallel(
&self,
filters: Vec<Filter>,
) -> Vec<Result<Vec<Log>>> ⓘ
pub async fn get_logs_parallel( &self, filters: Vec<Filter>, ) -> Vec<Result<Vec<Log>>> ⓘ
Fetch logs from multiple filters in parallel
Sourcepub fn effective_max_block_range(&self, url: &str) -> u64
pub fn effective_max_block_range(&self, url: &str) -> u64
Get effective max block range for an endpoint
Sourcepub fn min_block_range(&self) -> u64
pub fn min_block_range(&self) -> u64
Get the smallest max block range across all endpoints
Sourcepub fn max_block_range(&self) -> u64
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
Sourcepub fn get_endpoint_health(&self) -> Vec<(String, u8, Option<EndpointHealth>)>
pub fn get_endpoint_health(&self) -> Vec<(String, u8, Option<EndpointHealth>)>
Get health info for all endpoints
Sourcepub fn list_endpoints(&self) -> Vec<&str>
pub fn list_endpoints(&self) -> Vec<&str>
List all endpoint URLs
Sourcepub fn archive_endpoint_count(&self) -> usize
pub fn archive_endpoint_count(&self) -> usize
Get count of archive endpoints
Sourcepub fn debug_endpoint_count(&self) -> usize
pub fn debug_endpoint_count(&self) -> usize
Get count of debug-capable endpoints
Auto Trait Implementations§
impl Freeze for RpcPool
impl !RefUnwindSafe for RpcPool
impl Send for RpcPool
impl Sync for RpcPool
impl Unpin for RpcPool
impl UnsafeUnpin for RpcPool
impl !UnwindSafe for RpcPool
Blanket Implementations§
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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