middleware

Documentation for eth_defi.middleware Python module.

Web3 middleware.

Most are for dealing with JSON-RPC unreliability issues with retries.

  • Taken from exception_retry_request.py from Web3.py

  • Modified to support sleep and throttling

  • Logs warnings to Python logging subsystem in the case there is need to retry

  • See also eth_defi.provider.broken_provider.

Module Attributes

DEFAULT_RETRYABLE_EXCEPTIONS

List of Web3 exceptions we know we should retry after some timeout

DEFAULT_RETRYABLE_HTTP_STATUS_CODES

List of HTTP status codes we know we might want to retry after a timeout

DEFAULT_RETRYABLE_RPC_ERROR_CODES

List of ValueError status codes we know we might want to retry after a timeout

DEFAULT_RETRYABLE_RPC_ERROR_MESSAGES

Because Ethreum JSON-RPC API is horribly broken, we also need to check for error messages besides error codes.

STATIC_CALL_LIST

Ethereum JSON-RPC calls where the value never changes

Functions

construct_sign_and_send_raw_middleware_anvil(...)

Capture transactions sign and send as raw transactions

exception_retry_middleware(make_request, ...)

Creates middleware that retries failed HTTP requests.

http_retry_request_with_sleep_middleware(...)

A HTTP retry middleware with sleep and backoff.

is_retryable_http_exception(exc[, ...])

Helper to check retryable errors from JSON-RPC calls.

raise_on_revert_middleware(make_request, web3)

Automatically show the transaction revert reason in Python traceback.

static_call_cache_middleware(make_request, web3)

Cache JSON-RPC call values that never change.

Exceptions

ProbablyNodeHasNoBlock

A special exception raised when we suspect JSON-RPC node does not yet have data for a block we asked.