solver-multirpc 3.1.7__tar.gz → 3.1.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: solver-multirpc
3
- Version: 3.1.7
3
+ Version: 3.1.10
4
4
  Summary: A robust Python library for interacting with Ethereum smart contracts via multiple RPC endpoints, ensuring reliability, availability, and load distribution with automatic retries on failure.
5
5
  License: MIT
6
6
  Author: rorschach
@@ -16,7 +16,7 @@ from requests import ConnectionError, HTTPError, ReadTimeout
16
16
  from web3 import AsyncWeb3, Web3
17
17
  from web3._utils.contracts import encode_transaction_data # noqa
18
18
  from web3.contract import Contract
19
- from web3.exceptions import BadResponseFormat, BlockNotFound, TimeExhausted, TransactionNotFound
19
+ from web3.exceptions import BadResponseFormat, BlockNotFound, TimeExhausted, TransactionNotFound, Web3RPCError
20
20
  from web3.types import BlockData, BlockIdentifier, TxReceipt
21
21
 
22
22
  from .constants import EstimateGasLimitBuffer, GasLimit, GasUpperBound, MultiRPCLogger, ViewPolicy
@@ -311,7 +311,7 @@ class BaseMultiRpc(ABC):
311
311
  self._logger_params(**{f"{rpc_label_prefix}_post_send_time": get_unix_time()})
312
312
  self._logger_params(tx_send_time=int(time.time() * 1000))
313
313
  return provider, transaction
314
- except ValueError as e:
314
+ except (ValueError, Web3RPCError) as e:
315
315
  MultiRPCLogger.error(f"RPC({rpc_url}) value error: {str(e)}")
316
316
  t_bnb_flag = "transaction would cause overdraft" in str(e).lower() and (await provider.eth.chain_id) == 97
317
317
  if not (
@@ -492,7 +492,7 @@ class BaseMultiRpc(ABC):
492
492
  ]
493
493
  result = await self.__execute_batch_tasks(
494
494
  execution_tx_list,
495
- [ValueError, ConnectionError, ReadTimeout, HTTPError],
495
+ [ValueError, ConnectionError, ReadTimeout, HTTPError, Web3RPCError],
496
496
  FailedOnAllRPCs
497
497
  )
498
498
  provider, tx = result
@@ -5,6 +5,8 @@ BaseException_ = Exception
5
5
 
6
6
  class Web3InterfaceException(BaseException_):
7
7
  def __str__(self):
8
+ if not self.args:
9
+ return f"{self.__class__.__name__}()"
8
10
  return f"{self.__class__.__name__}({self.args[0]})"
9
11
 
10
12
 
@@ -14,7 +14,7 @@ from eth_typing import URI
14
14
  from web3 import AsyncHTTPProvider, AsyncWeb3, Web3, WebSocketProvider
15
15
  from web3._utils.http import DEFAULT_HTTP_TIMEOUT
16
16
  from web3._utils.http_session_manager import HTTPSessionManager
17
- from web3.middleware import ExtraDataToPOAMiddleware, Web3Middleware
17
+ from web3.middleware import ExtraDataToPOAMiddleware
18
18
 
19
19
  from .constants import MaxRPCInEachBracket, MultiRPCLogger
20
20
  from .exceptions import AtLastProvideOneValidRPCInEachBracket, MaximumRPCInEachBracketReached
@@ -202,58 +202,21 @@ class MultiRpcAsyncHTTPProvider(AsyncHTTPProvider):
202
202
  self._request_session_manager = MultiRpcHTTPSessionManager()
203
203
 
204
204
 
205
- class SimpleCacheMiddleware(Web3Middleware):
206
- rpc_whitelist = {
207
- "web3_clientVersion",
208
- "net_version",
209
- "eth_chainId",
210
- }
211
-
212
- def __init__(self, w3):
213
- super().__init__(w3)
214
- self.cache = {}
215
-
216
- def wrap_make_request(self, make_request):
217
- def middleware(method, params: Any):
218
- cache_key = (method, tuple(params))
219
- if method in self.rpc_whitelist and cache_key in self.cache:
220
- return self.cache[cache_key] # Return cached response
221
-
222
- response = make_request(method, params) # Make actual RPC request
223
-
224
- if method in self.rpc_whitelist:
225
- self.cache[cache_key] = response # Store response in cache
226
-
227
- return response
228
-
229
- return middleware
230
-
231
- async def async_wrap_make_request(self, make_request):
232
- async def middleware(method, params: Any):
233
- cache_key = (method, tuple(params))
234
- if method in self.rpc_whitelist and cache_key in self.cache:
235
- return self.cache[cache_key] # Return cached response
236
-
237
- response = await make_request(method, params) # Make actual RPC request
238
-
239
- if method in self.rpc_whitelist:
240
- self.cache[cache_key] = response # Store response in cache
241
-
242
- return response
243
-
244
- return middleware
245
-
246
-
247
205
  async def create_web3_from_rpc(rpc_urls: NestedDict, is_proof_of_authority: bool) -> NestedDict:
248
206
  async def create_web3(rpc_: str):
249
207
  async_w3: AsyncWeb3
208
+ provider_share_configs = dict(
209
+ cache_allowed_requests=True,
210
+ cacheable_requests={'eth_chainId',
211
+ 'web3_clientVersion',
212
+ 'net_version'},
213
+ )
250
214
  if rpc_.startswith("http"):
251
- async_w3 = AsyncWeb3(MultiRpcAsyncHTTPProvider(rpc_))
215
+ async_w3 = AsyncWeb3(MultiRpcAsyncHTTPProvider(rpc_, **provider_share_configs))
252
216
  else:
253
- async_w3 = AsyncWeb3(WebSocketProvider(rpc_))
217
+ async_w3 = AsyncWeb3(WebSocketProvider(rpc_, **provider_share_configs))
254
218
  if is_proof_of_authority:
255
219
  async_w3.middleware_onion.inject(ExtraDataToPOAMiddleware, layer=0)
256
- async_w3.middleware_onion.add(SimpleCacheMiddleware, 'simple_cache')
257
220
  try:
258
221
  status = await async_w3.is_connected()
259
222
  except (asyncio.exceptions.TimeoutError, aiohttp.client_exceptions.ClientResponseError):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "solver-multirpc"
3
- version = "3.1.7"
3
+ version = "3.1.10"
4
4
  description = "A robust Python library for interacting with Ethereum smart contracts via multiple RPC endpoints, ensuring reliability, availability, and load distribution with automatic retries on failure."
5
5
  authors = ["rorschach <rorschach45001@gmail.com>"]
6
6
  license = "MIT"