Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch provider in case of rate limit #171

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions eth_defi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,33 @@
- See also :py:mod:`eth_defi.provider.broken_provider`.
"""

from web3 import Web3
import time
from typing import Callable, Any, Collection, Type, Tuple, Optional, TypeAlias, Union, Counter
import logging
import time
from typing import (
Any,
Callable,
Collection,
Counter,
Optional,
Tuple,
Type,
TypeAlias,
Union,
)

from eth_utils.toolz import assoc
from requests.exceptions import (
ChunkedEncodingError,
ConnectionError,
HTTPError,
Timeout,
TooManyRedirects,
ChunkedEncodingError,
)
from web3 import Web3
from web3._utils.transactions import get_buffered_gas_estimate
from eth_utils.toolz import assoc
from web3.exceptions import ContractLogicError, BlockNotFound

from web3.exceptions import BlockNotFound, ContractLogicError
from web3.middleware.exception_retry_request import check_if_retry_on_failure
from web3.types import RPCEndpoint, RPCResponse, Middleware
from web3.types import Middleware, RPCEndpoint, RPCResponse

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -100,6 +109,9 @@
# Some error we are getting from LlamaNodes eth_getLogs RPC that we do not know what it is all about
# {'code': -32043, 'message': 'Requested data is not available'}
-32043,
# Rate limit exceeded from some provider like LlamaNodes
# {'code': -32005, 'message': 'limit exceeded'}
-32005,
)


Expand Down Expand Up @@ -305,20 +317,10 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
#
#

from web3._utils.transactions import (
fill_nonce,
fill_transaction_defaults,
)
from web3.middleware.signing import gen_normalized_accounts, format_transaction
from web3.types import (
Middleware,
RPCEndpoint,
RPCResponse,
)

from eth_utils.toolz import (
compose,
)
from eth_utils.toolz import compose
from web3._utils.transactions import fill_nonce, fill_transaction_defaults
from web3.middleware.signing import format_transaction, gen_normalized_accounts
from web3.types import Middleware, RPCEndpoint, RPCResponse


def construct_sign_and_send_raw_middleware_anvil(
Expand Down