Skip to content

Commit

Permalink
Switch provider in case of rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuh25 committed Oct 24, 2023
1 parent bfa97ca commit 94f15fe
Showing 1 changed file with 24 additions and 22 deletions.
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

0 comments on commit 94f15fe

Please sign in to comment.