Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 4f0e8a3

Browse files
Merge pull request #287 from BalancerMaxis/fix/block-fetch-retries
add retry logic to block fetching
2 parents 9000de5 + 1759e83 commit 4f0e8a3

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

fee_allocator/accounting/chains.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from decimal import Decimal
44
from pathlib import Path
55
import os
6+
import time
67
from dotenv import load_dotenv
78

89
from web3 import Web3
@@ -211,9 +212,22 @@ def __init__(self, chains: CorePoolRunConfig, name: str, fees: int, web3: Web3):
211212
self.partner_pools_map: Dict[str, Partner] = {} # pool_id -> Partner mapping
212213
self.partner_noncore_fee_data: List[PoolFeeData] = []
213214

215+
def _fetch_block_with_retries(self, timestamp: int, max_attempts: int = 3) -> int:
216+
for attempt in range(max_attempts):
217+
try:
218+
block = self.subgraph.get_first_block_after_utc_timestamp(timestamp)
219+
if block is not None:
220+
return block
221+
raise Exception(f"No block found for timestamp {timestamp} on {self.name}")
222+
except Exception:
223+
if attempt < max_attempts - 1:
224+
time.sleep((attempt + 1) * 2)
225+
else:
226+
raise
227+
214228
def _set_block_range(self) -> tuple[int, int]:
215-
start = self.subgraph.get_first_block_after_utc_timestamp(self.chains.date_range[0])
216-
end = self.subgraph.get_first_block_after_utc_timestamp(self.chains.date_range[1])
229+
start = self._fetch_block_with_retries(self.chains.date_range[0])
230+
end = self._fetch_block_with_retries(self.chains.date_range[1])
217231
logger.info(f"set blocks for {self.name}: {start} - {end}")
218232
return (start, end)
219233

0 commit comments

Comments
 (0)