provider.fallback
Documentation for eth_defi.provider.fallback Python module.
JSON-RPC provider fallback and redundancy mechanisms.
See
FallbackProvider
Functions
|
Get the fallback provider of a Wen3 instance. |
Classes
Fault-tolerance for JSON-RPC requests with multiple providers. |
|
Different supported fallback strategies. |
Exceptions
A ValueError that is used to signal that the RPC response was not valid. |
- exception ExtraValueError
Bases:
ValueErrorA ValueError that is used to signal that the RPC response was not valid.
Add extra debugging.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class FallbackStrategy
Bases:
enum.EnumDifferent supported fallback strategies.
- cycle_on_error = 'cycle_on_error'
Automatically switch to the next provider on an error
- class FallbackProvider
Bases:
eth_defi.provider.named.BaseNamedProviderFault-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
FallbackProviderdoes not call any middlewares installed on the providers themselves.- Parameters
providers – 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 – Seconds between retries.
backoff – Multiplier to increase sleep.
retries – How many retries we attempt before giving up.
switchover_noisiness – How loud we are about switchover issues.
state_missing_switch_over_delay –
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.
- __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'>, <class 'http.client.RemoteDisconnected'>, <class 'eth_defi.middleware.SomeCrappyRPCProviderException'>, <class 'requests.exceptions.ContentDecodingError'>), retryable_status_codes=(429, 500, 502, 503, 504, 525, 520, 410, 403, 400), retryable_rpc_error_codes=(-32003, -32043, -32005, -32701, 42903, -32002, -32603, -32052, -32601), sleep=5.0, backoff=1.6, retries=6, state_missing_switch_over_delay=12.0, switchover_noisiness=30)
- Parameters
providers (list[eth_defi.provider.named.BaseNamedProvider | web3.providers.rpc.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
HTTPProvidercompatibility.
- reset_switch()
Reset the provider switch to the first provider.
Assume we have main provider and more expensive backup providers
Try to switch back to the main provider if we have switched away due to a temporary error
Used in batch scan tasks
- switch_provider(log_level=None, randomise=False, cause='<not specified>')
Switch to next available provider.
- get_active_provider()
Get currently active provider.
If this provider fails, we are automatically recycled to the next one.
- Return type
eth_defi.provider.named.BaseNamedProvider | web3.providers.rpc.rpc.HTTPProvider
- make_request(method, params)
Make a request.
By default use the current active provider
If there are errors try cycle through providers and sleep between cycles until one provider works
Use a special “ignore_error” parameter to skip retries, if given in
eth_callpayload.
- Parameters
method (web3.types.RPCEndpoint) –
params (Any) –
- Return type
web3.types.RPCResponse
- property call_endpoint_uri: str
Return the active node URI where call JSON-RPCs go.
Warning
Endpoint URIs often contain API keys. They should be never publicly displayed as is.
- request_func(w3, middleware_onion)
@param w3 is the web3 instance @param middleware_onion is an iterable of middleware,
ordered by first to execute
- @returns a function that calls all the middleware and
eventually self.make_request()
- get_fallback_provider(web3)
Get the fallback provider of a Wen3 instance.
Can be nested in
eth_defi.provider.mev_block.MEVBlockerProvider.- Parameters
web3 (web3.main.Web3) – Web3 instance
- Raises
AssertionError – If there is no fallback provider available
- Return type