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

MAX_CYCLE_LIFETIME_IN_SECONDS only for cycle logic #523

Open
wants to merge 1 commit into
base: develop
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
37 changes: 24 additions & 13 deletions src/modules/submodules/oracle_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from src import variables
from src.types import SlotNumber, BlockStamp, BlockRoot


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -57,25 +56,37 @@ def run_as_daemon(self):
logger.debug({'msg': 'Startup new cycle.'})
self.cycle_handler()

@timeout(variables.MAX_CYCLE_LIFETIME_IN_SECONDS)
def cycle_handler(self):
blockstamp = self._receive_last_finalized_slot()
self._cycle()
self._sleep_cycle()

if blockstamp.slot_number > self._slot_threshold:
if self.w3.lido_contracts.has_contract_address_changed():
clear_global_cache()
self.refresh_contracts()
result = self.run_cycle(blockstamp)
@timeout(variables.MAX_CYCLE_LIFETIME_IN_SECONDS)
def _cycle(self):
blockstamp = self._receive_last_finalized_slot()

if result is ModuleExecuteDelay.NEXT_FINALIZED_EPOCH:
self._slot_threshold = blockstamp.slot_number
else:
# Check if the blockstamp is below the threshold and exit early
if blockstamp.slot_number <= self._slot_threshold:
logger.info({
'msg': 'Skipping the report. Wait for new finalized slot.',
'msg': 'Skipping the report. Waiting for new finalized slot.',
'slot_threshold': self._slot_threshold,
})
self._sleep_cycle()
return

# Refresh contracts if the address has changed
if self.w3.lido_contracts.has_contract_address_changed():
clear_global_cache()
self.refresh_contracts()

result = self.run_cycle(blockstamp)
if result is ModuleExecuteDelay.NEXT_FINALIZED_EPOCH:
self._slot_threshold = blockstamp.slot_number

logger.info({'msg': f'Cycle end. Sleeping for {variables.CYCLE_SLEEP_IN_SECONDS} seconds.'})

logger.info({'msg': f'Cycle end. Sleep for {variables.CYCLE_SLEEP_IN_SECONDS} seconds.'})
@staticmethod
def _sleep_cycle():
"""Handles sleeping between cycles based on the configured cycle sleep time."""
time.sleep(variables.CYCLE_SLEEP_IN_SECONDS)

def _receive_last_finalized_slot(self) -> BlockStamp:
Expand Down
Loading