Skip to content

Commit f269d73

Browse files
committed
made retry optional for entire Web3Advanced instance
1 parent 24378cf commit f269d73

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

IceCreamSwapWeb3/EthAdvanced.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class EthAdvanced(Eth):
5151
]
5252

5353
FILTER_RANGES_TO_TRY = sorted([
54-
100_000,
55-
50_000,
56-
20_000,
5754
10_000,
5855
5_000,
5956
2_000,
@@ -73,7 +70,8 @@ class EthAdvanced(Eth):
7370
def __init__(self, w3):
7471
super().__init__(w3=w3)
7572

76-
self._wrap_methods_with_retry()
73+
if self.w3.should_retry:
74+
self._wrap_methods_with_retry()
7775

7876
self.filter_block_range = self._find_max_filter_range()
7977

@@ -120,7 +118,9 @@ def get_logs(self, filter_params: FilterParams, show_progress_bar=False, p_bar=N
120118
try:
121119
events = self._get_logs(filter_params)
122120
except Exception:
123-
pass
121+
# if errors should not be retried, still do splitting but not retry if it can not be split further
122+
if not self.w3.should_retry and num_blocks == 1:
123+
raise
124124
else:
125125
if p_bar is not None:
126126
p_bar.update(num_blocks)

IceCreamSwapWeb3/Web3Advanced.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from web3 import Web3, JSONBaseProvider
1+
from web3 import Web3
22
from web3.main import get_default_modules
33
from web3.middleware import geth_poa_middleware
44

5-
from EthAdvanced import EthAdvanced
5+
from .EthAdvanced import EthAdvanced
66

77

88
class Web3Advanced(Web3):
@@ -11,7 +11,10 @@ class Web3Advanced(Web3):
1111
def __init__(
1212
self,
1313
node_url: str,
14+
should_retry=True,
1415
):
16+
self.should_retry = should_retry
17+
1518
provider = self._construct_provider(node_url=node_url)
1619

1720
# use the EthAdvanced class instead of the Eth class for w3.eth
@@ -24,7 +27,7 @@ def __init__(
2427
self._chain_id = self.eth.chain_id # avoids many RPC calls to get chain ID
2528

2629
@staticmethod
27-
def _construct_provider(node_url) -> JSONBaseProvider:
30+
def _construct_provider(node_url):
2831
assert "://" in node_url
2932
protocol = node_url.split("://")[0]
3033
if protocol in ("https", "http"):

0 commit comments

Comments
 (0)