Skip to content

Commit 42366ac

Browse files
committed
added global rpc specific chain id caching with proper retry wrapping
1 parent c4ffae9 commit 42366ac

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

IceCreamSwapWeb3/EthAdvanced.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def inner(*args, no_retry: bool = False, **kwargs):
5353
return wrapper
5454

5555

56+
RPC_TO_CHAIN_ID_CACHE: dict[str, int] = {}
57+
58+
5659
class EthAdvanced(Eth):
5760
w3: Web3Advanced
5861

@@ -291,10 +294,13 @@ def get_logs_inner(self, filter_params: FilterParams, no_retry: bool = False):
291294
no_retry = True
292295
return exponential_retry(func_name="get_logs")(self._get_logs)(filter_params, no_retry=no_retry)
293296

294-
@lru_cache
295297
def _chain_id(self):
296-
# usually this causes an RPC call and is used in every eth_call. Getting it once and then caching it.
297-
return super()._chain_id()
298+
rpc = self.w3.node_url
299+
if rpc not in RPC_TO_CHAIN_ID_CACHE:
300+
RPC_TO_CHAIN_ID_CACHE[rpc] = exponential_retry(func_name="chain_id")(
301+
super()._chain_id
302+
)(no_retry=not self.w3.should_retry)
303+
return RPC_TO_CHAIN_ID_CACHE[rpc]
298304

299305

300306
def main(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.1.47'
3+
VERSION = '0.1.48'
44
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
55
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
66

0 commit comments

Comments
 (0)