FallbackProvider
Documentation for eth_defi.provider.fallback.FallbackProvider Python class.
- class FallbackProvider[source]
Fault-tolerance for JSON-RPC requests with multiple providers.
Fall back to the next provider on the list if a JSON-RPC request fails. Contains build-in retry logic in round-robin manner. We will also recover from situations when we suspect the node does not have the block data we are asking yet (but should have shorty).
See also
eth_defi.middlware.exception_retry_middleware()
eth_defi.middlware.ProbablyNodeHasNoBlock()
Note
FallbackProvider
does not call any middlewares installed on the providers themselves.Attributes summary
call_endpoint_uri
Return the active node URI where call JSON-RPCs go.
ccip_read_max_redirects
Return the active node URI endpoint.
global_ccip_read_enabled
is_async
middlewares
Currently active provider
provider number-> api method name -> retry counts dict
Methods summary
__init__
(providers[, strategy, ...])- param providers
decode_rpc_response
(raw_response)encode_rpc_request
(method, params)Get currently active provider.
Get API call coubst across all providers
Have we configured multiple providers
is_connected
()make_request
(method, params)Make a request.
request_func
(w3, outer_middlewares)@param outer_middlewares is an iterable of middlewares,
Switch to next available provider.
- __init__(providers, strategy=FallbackStrategy.cycle_on_error, retryable_exceptions=(<class 'requests.exceptions.ConnectionError'>, <class 'requests.exceptions.HTTPError'>, <class 'requests.exceptions.Timeout'>, <class 'requests.exceptions.TooManyRedirects'>, <class 'web3.exceptions.BlockNotFound'>, <class 'requests.exceptions.ChunkedEncodingError'>), retryable_status_codes=(429, 500, 502, 503, 504), retryable_rpc_error_codes=(-32603, -32003, -32043, -32005, -32701), sleep=5.0, backoff=1.6, retries=6, state_missing_switch_over_delay=12.0, switchover_noisiness=30)[source]
- Parameters
providers (List[eth_defi.provider.named.BaseNamedProvider | web3.providers.rpc.HTTPProvider]) – List of provider we cycle through.
strategy –
What is the strategy to deal with errors.
Currently on cycling supported.
retryable_exceptions – List of exceptions we can retry.
retryable_status_codes – List of HTTP status codes we can retry.
retryable_rpc_error_codes – List of GoEthereum error codes we can retry.
sleep (float) – Seconds between retries.
backoff (float) – Multiplier to increase sleep.
retries (int) – How many retries we attempt before giving up.
switchover_noisiness – How loud we are about switchover issues.
state_missing_switch_over_delay (float) –
If we encounter state missing condition at node, what is the minimum time (seconds) we wait before trying to switch to next node.
See code comments for details.
- currently_active_provider
Currently active provider
- api_retry_counts
provider number-> api method name -> retry counts dict
- property endpoint_uri
Return the active node URI endpoint.
For
HTTPProvider
compatibility.
- get_active_provider()[source]
Get currently active provider.
If this provider fails, we are automatically recycled to the next one.