Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: add timeoutheight_sync_interval parameter to finetune sync frequency or abort it completely #361

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
network: Network,
insecure: Optional[bool] = None,
credentials=None,
timeoutheight_sync_interval: Optional[int] = DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL,
):
# the `insecure` parameter is ignored and will be deprecated soon. The value is taken directly from `network`
if insecure is not None:
Expand Down Expand Up @@ -154,6 +155,7 @@ def __init__(
self.chain_stream_stub = stream_rpc_grpc.StreamStub(channel=self.chain_stream_channel)

self._timeout_height_sync_task = None
self._timeoutheight_sync_interval = timeoutheight_sync_interval
self._initialize_timeout_height_sync_task()

self._tokens_and_markets_initialization_lock = asyncio.Lock()
Expand Down Expand Up @@ -3450,13 +3452,14 @@ async def _tokens_from_official_lists(
return tokens_by_symbol, tokens_by_denom

def _initialize_timeout_height_sync_task(self):
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process())
if self._timeoutheight_sync_interval is not None:
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.get_event_loop().create_task(self._timeout_height_sync_process())

async def _timeout_height_sync_process(self):
while True:
await self.sync_timeout_height()
await asyncio.sleep(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL)
await asyncio.sleep(self._timeoutheight_sync_interval)

def _cancel_timeout_height_sync_task(self):
if self._timeout_height_sync_task is not None:
Expand Down
Loading