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 sync committee rest response object #89

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions duties/fetcher/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ValidatorDuty(BaseModel):
validator_sync_committee_indices: List[int] = Field(default_factory=list)
type: DutyType = Field(default=DutyType.NONE)
seconds_to_duty: int = Field(default=0)
seconds_left_in_current_sync_committee: int = Field(default=0)


@dataclass
Expand Down
8 changes: 3 additions & 5 deletions duties/fetcher/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""

from logging import getLogger
from math import ceil
from typing import List

from cli.arguments import ARGUMENTS
Expand Down Expand Up @@ -60,12 +59,11 @@ async def fetch_upcoming_sync_committee_duties() -> dict[str, ValidatorDuty]:
for all provided validators
"""
current_epoch = ethereum.get_current_epoch()
next_sync_committee_starting_epoch = (
ceil(current_epoch / ethereum.EPOCHS_PER_SYNC_COMMITTEE)
* ethereum.EPOCHS_PER_SYNC_COMMITTEE
current_sync_committee_epoch_boundaries = (
ethereum.get_sync_committee_epoch_boundaries(current_epoch)
)
validator_duties: dict[str, ValidatorDuty] = {}
for epoch in [current_epoch, next_sync_committee_starting_epoch]:
for epoch in [current_epoch, (current_sync_committee_epoch_boundaries[1] + 1)]:
response_data = await __fetch_duty_responses(epoch, DutyType.SYNC_COMMITTEE)
for data in response_data:
if data.validator_index not in validator_duties:
Expand Down
11 changes: 8 additions & 3 deletions duties/protocol/ethereum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Defines ethereum related constants and functions
"""

from asyncio import run
from logging import getLogger
from math import ceil, trunc
Expand Down Expand Up @@ -72,16 +73,20 @@ def set_time_to_duty(duty: ValidatorDuty) -> None:
current_sync_committee_epoch_boundaries = (
get_sync_committee_epoch_boundaries(current_epoch)
)
time_to_next_sync_committee = get_time_to_next_sync_committee(
current_sync_committee_epoch_boundaries, current_slot
)
if duty.epoch in range(
current_sync_committee_epoch_boundaries[0],
current_sync_committee_epoch_boundaries[1] + 1,
1,
):
duty.seconds_to_duty = 0
else:
duty.seconds_to_duty = get_time_to_next_sync_committee(
current_sync_committee_epoch_boundaries, current_slot
duty.seconds_left_in_current_sync_committee = (
time_to_next_sync_committee - 1
)
else:
duty.seconds_to_duty = time_to_next_sync_committee
case _:
duty.seconds_to_duty = int(duty.slot * SLOT_TIME + GENESIS_TIME - time())

Expand Down