Overview
Provider selection in Lasso operates as a multi-stage pipeline that transforms a pool of candidate providers into an ordered execution list. The pipeline balances performance, reliability, and load distribution based on real-time health metrics and historical performance data.Pipeline Architecture
High-Level Flow
- Candidate Pool: All providers configured in profile for the chain
- 7-Stage Filters: Exclude ineligible providers (see below)
- Strategy Ranking: Order by strategy (fastest, latency_weighted, etc.)
- Health Tiering: Reorder into 4 tiers by circuit breaker and rate limit state
- Execution: Sequential attempts with automatic failover
7-Stage Filter Pipeline
Implemented inLasso.Providers.CandidateListing.list_candidates/3:
Stage 1: Transport Availability
Purpose: Filter providers based on required transport (HTTP/WebSocket) Logic:- HTTP requests exclude providers without
url - WebSocket requests exclude providers without active WebSocket connection
- Checks
:transport_channel_cacheETS table for WebSocket liveness
Stage 2: WebSocket Liveness
Purpose: Verify WebSocket channels are actively connected Logic:- Providers with
ws_urlconfigured but no active connection - Prevents routing to providers mid-reconnection
Stage 3: Circuit Breaker State
Purpose: Exclude providers with open circuit breakers Logic:- Providers with
:opencircuit breakers are always excluded - Providers with
:half_opencircuit breakers excluded unlessinclude_half_open: true
- :closed - Healthy, provider is eligible
- :half_open - Recovering, excluded by default (configurable)
- :open - Failing, always excluded
Stage 4: Rate Limit State
Purpose: Optionally exclude rate-limited providers Logic:- Only when
exclude_rate_limited: truefilter is set - Checks
:lasso_instance_stateETS table for rate limit flags - Rate limit state is set by error classification (see error rules in profiles)
By default, rate-limited providers are not excluded, only deprioritized to Tier 2/4 during health tiering.
Stage 5: Lag Filtering
Purpose: Exclude providers that are behind consensus by more than threshold Logic:- Providers with
optimistic_lag < -max_lag_blocks - Example:
max_lag_blocks: 5excludes providers more than 5 blocks behind - Accounts for observation delay using block time (prevents false lag detection)
Stage 6: Archival Filtering
Purpose: Require archival providers for historical queries Logic:- Providers with
archival: falsewhenrequires_archival: true - Typically used for
eth_getLogswith historical block ranges
Stage 7: Exclude List
Purpose: Explicitly exclude specific providers Logic:- Providers in the
excludefilter list - Useful for temporary provider blacklisting
- Used during failover to avoid retrying failed providers
Candidate Structure
Filtered candidates include metadata for downstream ranking:Strategy Ranking
After filtering, candidates are ranked by the selected strategy:Fastest
Ranks by measured latency (ascending):Latency Weighted
Weighted random selection:Load Balanced
Random shuffle:Priority
Static priority from configuration:Health-Based Tiering
After strategy ranking, providers are reordered into 4 tiers:Tier Definitions
- Tier 1: Closed circuit + not rate-limited (preferred)
- Tier 2: Closed circuit + rate-limited
- Tier 3: Half-open circuit + not rate-limited
- Tier 4: Half-open circuit + rate-limited
Tiering Logic
Tiering preserves strategy ranking within each tier:Why Tiering Matters
Tiering ensures healthy providers receive traffic first: Scenario: 3 providers withfastest strategy
- Provider A: 200ms latency, half-open circuit → Tier 3
- Provider B: 350ms latency, closed circuit → Tier 1
- Provider C: 500ms latency, closed circuit → Tier 1
Execution and Failover
Providers are attempted sequentially until success or exhaustion:Sequential Execution
Success Criteria
- 2xx HTTP status
- Valid JSON-RPC structure
- No RPC error code (unless expected)
Failure Handling
Retriable Errors (try next provider)::rate_limit- Provider throttling:network_error- Connection failure:server_error- 5xx status:capability_violation- Method not supported:method_not_found- Method not available
:invalid_params- User error:user_error- Client mistake:client_error- 4xx status
All Providers Exhausted
Returns503 Service Unavailable with details:
Filter Configuration
Via Selection Filters
Via Profile Configuration
ETS State Management
The filter pipeline reads from three ETS tables::lasso_instance_state
Circuit Breaker State:
:transport_channel_cache
WebSocket Channel Liveness:
:lasso_config_store
Provider Configuration:
Performance Characteristics
Filter Pipeline Latency
Optimization Techniques
Batch Metrics Fetching:Next Steps
Routing Strategies
Understand strategy ranking algorithms
Circuit Breakers
Learn about state machine and recovery
Profiles
Configure provider selection policies
Architecture
Explore the OTP supervision tree