Skip to content

Commit

Permalink
Fix TON monitoring - stop trying to pull not existing blocks (#144)
Browse files Browse the repository at this point in the history
* Fix TON monitoring - stop trying to pull not existing blocks

* change logic of next block

---------

Co-authored-by: Oleksandr Prudnikov <[email protected]>
  • Loading branch information
Grommash9 and Oleksandr Prudnikov authored Jan 25, 2025
1 parent bf9bb41 commit 19c42b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [9.1.0]
- Fix TON monitoring - stop trying to pull not existing blocks

## [9.0.0]
- Added shard sequence tracking for TON monitoring
- Now processing all intermediate shard blocks between masterchain references
Expand Down
12 changes: 9 additions & 3 deletions aiotx/clients/_ton_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,14 @@ async def poll_blocks(self, timeout_between_blocks: int):
if self.client.workchain is None:
self.client.workchain = workchain

target_block = seqno if self._latest_block is None else self._latest_block
if target_block > seqno:
# If _latest_block is None, process the current seqno
if self._latest_block is None:
target_block = seqno
# If behind network, process next block
elif self._latest_block < seqno:
target_block = self._latest_block + 1
# No new blocks, sleep
else:
await asyncio.sleep(timeout_between_blocks)
return

Expand All @@ -487,7 +493,7 @@ async def poll_blocks(self, timeout_between_blocks: int):
await asyncio.gather(*shard_tasks)

await self.process_master_block(target_block)
self._latest_block = target_block + 1
self._latest_block = target_block

async def process_master_block(self, block):
for handler in self.block_handlers:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ton/test_ton_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def handle_transaction(transaction):
transactions.append(transaction)

asyncio.create_task(
ton_client.start_monitoring(27411722, timeout_between_blocks=0.1)
ton_client.start_monitoring(27411721, timeout_between_blocks=0.1)
)
# master block 27411723 have shard with seqno 29177784
# master block 27411724 have shard with seqno 29177786
Expand Down Expand Up @@ -62,7 +62,7 @@ async def handle_transaction(transaction):
transactions.append(transaction)

asyncio.create_task(
ton_client.start_monitoring(19627950, timeout_between_blocks=0.1)
ton_client.start_monitoring(19627949, timeout_between_blocks=0.1)
)
try:
await asyncio.sleep(3)
Expand Down

0 comments on commit 19c42b8

Please sign in to comment.