Skip to content

Commit a538389

Browse files
committed
Multicall single call retry now is not forever. Makes sure that calls taking infinite gas don't get retried forever.
1 parent 26e1ad0 commit a538389

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

IceCreamSwapWeb3/Multicall.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,22 @@ def _inner_call(
126126
)
127127
except Exception as e:
128128
if len(calls_with_calldata) == 1:
129-
print(f"Multicall with single call got Exception '{repr(e)}', retrying in 1 sec")
129+
print(f"Multicall with single call got Exception '{repr(e)}', last retry")
130130
sleep(1)
131-
return self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata)
132-
print(f"Multicall got Exception '{repr(e)}', splitting and retrying")
133-
left_results, left_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[:len(calls_with_calldata) // 2])
134-
right_results, right_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[len(calls_with_calldata) // 2:])
135-
return left_results + right_results, left_gas_usages + right_gas_usages
131+
try:
132+
raw_returns, gas_usages = self._call_multicall(
133+
multicall_call=multicall_call,
134+
retry=len(calls_with_calldata) == 1
135+
)
136+
except Exception as e:
137+
print(f"Multicall with single call got Exception '{repr(e)}', returning Exception")
138+
raw_returns = [e]
139+
gas_usages = [None]
140+
else:
141+
print(f"Multicall got Exception '{repr(e)}', splitting and retrying")
142+
left_results, left_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[:len(calls_with_calldata) // 2])
143+
right_results, right_gas_usages = self._inner_call(**kwargs, calls_with_calldata=calls_with_calldata[len(calls_with_calldata) // 2:])
144+
return left_results + right_results, left_gas_usages + right_gas_usages
136145
results = self.decode_contract_function_results(raw_returns=raw_returns, contract_functions=[call for call, _ in calls_with_calldata])
137146
if len(results) == len(calls_with_calldata):
138147
return results, gas_usages

0 commit comments

Comments
 (0)