Skip to content

Commit

Permalink
feat(main): Skip fetching specific duties under certain circumstances
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiWo committed Dec 23, 2022
1 parent 480609a commit 94e6f8f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions duties/duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@

from time import sleep
from typing import List, Callable
from logging import getLogger
from logging import getLogger, Logger
from fetcher import fetcher
from fetcher.data_types import ValidatorDuty, DutyType
from fetcher.logger import log_time_to_next_duties
from cli.cli import get_arguments
from protocol.protocol import get_current_slot
from constants.program import GRACEFUL_KILLER
from constants import logging

__sort_duties: Callable[[ValidatorDuty], int] = lambda duty: duty.slot


def __fetch_validator_duties(duties: List[ValidatorDuty]) -> List[ValidatorDuty]:
def __fetch_validator_duties(
duties: List[ValidatorDuty], logger: Logger
) -> List[ValidatorDuty]:
"""Fetches upcoming validator duties
Args:
Expand All @@ -25,9 +28,14 @@ def __fetch_validator_duties(duties: List[ValidatorDuty]) -> List[ValidatorDuty]
"""
if not __is_current_data_outdated(duties):
return duties
next_attestation_duties = fetcher.get_next_attestation_duties()
next_attestation_duties: dict[int, ValidatorDuty] = {}
next_sync_committee_duties: dict[int, ValidatorDuty] = {}
if fetcher.is_provided_validator_count_too_high():
logger.warning(logging.TOO_MANY_PROVIDED_VALIDATORS_MESSAGE)
else:
next_attestation_duties = fetcher.get_next_attestation_duties()
next_sync_committee_duties = fetcher.get_next_sync_committee_duties()
next_proposing_duties = fetcher.get_next_proposing_duties()
next_sync_committee_duties = fetcher.get_next_sync_committee_duties()
duties = [
duty
for duties in [
Expand Down Expand Up @@ -65,11 +73,11 @@ def __is_current_data_outdated(current_duties: List[ValidatorDuty]) -> bool:


if __name__ == "__main__":
main_logger = getLogger(__name__)
args = get_arguments()
upcoming_duties: List[ValidatorDuty] = []
while not GRACEFUL_KILLER.kill_now:
upcoming_duties = __fetch_validator_duties(upcoming_duties)
upcoming_duties = __fetch_validator_duties(upcoming_duties, main_logger)
log_time_to_next_duties(upcoming_duties)
sleep(args.interval)
logger = getLogger(__name__)
logger.info("Happy staking. See you for next maintenance \U0001F642 !")
main_logger.info("Happy staking. See you for next maintenance \U0001F642 !")

0 comments on commit 94e6f8f

Please sign in to comment.