Skip to content

Commit 0b0d878

Browse files
Fix indexes in realtime status missing head relation (#129)
1 parent c146f77 commit 0b0d878

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/dipdup/datasources/tzkt/datasource.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ def level(self) -> Optional[int]:
359359
def sync_level(self) -> Optional[int]:
360360
return self._sync_level
361361

362+
@property
363+
def head(self) -> Optional[Head]:
364+
return self._head
365+
362366
async def get_similar_contracts(self, address: str, strict: bool = False) -> List[str]:
363367
"""Get list of contracts sharing the same code hash or type hash"""
364368
entrypoint = 'same' if strict else 'similar'
@@ -716,6 +720,7 @@ async def _on_head_message(self, message: List[Dict[str, Any]]) -> None:
716720
created = False
717721
if self._head is None:
718722
self._head, created = await Head.get_or_create(
723+
# NOTE: It would be better to use datasource name but it's not available
719724
name=self._http._url,
720725
defaults=dict(
721726
level=block.level,

src/dipdup/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def __aenter__(self) -> None:
7272
"""Create underlying aiohttp session"""
7373
self.__session = aiohttp.ClientSession(
7474
connector=aiohttp.TCPConnector(limit=self._config.connection_limit or 100),
75-
timeout=aiohttp.ClientTimeout(self._config.connection_timeout or 60),
75+
timeout=aiohttp.ClientTimeout(connect=self._config.connection_timeout or 60),
7676
)
7777

7878
async def __aexit__(self, exc_type, exc, tb):

src/dipdup/index.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,12 @@ def __init__(self, ctx: DipDupContext, config: ResolvedIndexConfigT, datasource:
4040
self._datasource = datasource
4141

4242
self._logger = FormattedLogger('dipdup.index', fmt=f'{config.name}: ' + '{}')
43-
self._head: Optional[models.Head] = None
4443
self._state: Optional[models.Index] = None
4544

4645
@property
4746
def datasource(self) -> TzktDatasource:
4847
return self._datasource
4948

50-
@property
51-
def head(self) -> Optional[models.Head]:
52-
return self._head
53-
5449
@property
5550
def state(self) -> models.Index:
5651
if self._state is None:
@@ -124,6 +119,7 @@ async def _enter_sync_state(self, last_level: int) -> Optional[int]:
124119

125120
async def _exit_sync_state(self, last_level: int) -> None:
126121
self._logger.info('Index is synchronized to level %s', last_level)
122+
# NOTE: No head yet, wait for realtime messages to be processed
127123
await self.state.update_status(IndexStatus.REALTIME, last_level)
128124

129125

@@ -231,9 +227,11 @@ async def _process_level_operations(self, level: int, operations: List[Operation
231227
self._logger.info('Processing %s operations of level %s', len(operations), level)
232228
await self._process_operations(operations)
233229

234-
status = IndexStatus.REALTIME if block else IndexStatus.SYNCING
235-
# FIXME: Not obvious: receiving `BlockData`, sending `Head`
236-
await self.state.update_status(status, level, self.head if block else None)
230+
if block:
231+
status, head = IndexStatus.REALTIME, self.datasource.head
232+
else:
233+
status, head = IndexStatus.SYNCING, None
234+
await self.state.update_status(status, level, head)
237235

238236
async def _match_operation(self, pattern_config: OperationHandlerPatternConfigT, operation: OperationData) -> bool:
239237
"""Match single operation with pattern"""
@@ -459,8 +457,11 @@ async def _process_level_big_maps(self, level: int, big_maps: List[BigMapData],
459457
self._logger.info('Processing %s big map diffs of level %s', len(big_maps), level)
460458
await self._process_big_maps(big_maps)
461459

462-
status = IndexStatus.REALTIME if block else IndexStatus.SYNCING
463-
await self.state.update_status(status, level, self.datasource.block if block else None)
460+
if block:
461+
status, head = IndexStatus.REALTIME, self.datasource.head
462+
else:
463+
status, head = IndexStatus.SYNCING, None
464+
await self.state.update_status(status, level, head)
464465

465466
async def _match_big_map(self, handler_config: BigMapHandlerConfig, big_map: BigMapData) -> bool:
466467
"""Match single big map diff with pattern"""

0 commit comments

Comments
 (0)