Skip to content

Commit

Permalink
fix: simplify the main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
aimxhaisse committed Apr 4, 2024
1 parent 3dc3ace commit dab0dba
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions eth_validator_watcher/entrypoint_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,31 +205,24 @@ def run(self) -> None:
"""Run the Ethereum Validator Watcher.
"""
watched_validators = WatchedValidators()

epoch = self._clock.get_current_epoch(time.time())
slot = self._clock.get_current_slot(time.time())

# Before entering the processing loop, make sure we have a
# beacon state in the watched validators as this is what
# ensures we know about validators.
logging.info(f'Initializing watcher at epoch {epoch}')
beacon_validators = self._beacon.get_validators(self._clock.epoch_to_slot(epoch))
watched_validators.process_epoch(beacon_validators)
rewards = self._beacon.get_rewards(epoch - 2)
process_rewards(watched_validators, rewards)
beacon_validators = None
rewards = None

slot = self._clock.get_current_slot(time.time())
while True:
logging.info(f'Processing slot {slot}')
if slot % self._spec.data.SLOTS_PER_EPOCH == 0:
logging.info(f'Processing new epoch {epoch}')

if beacon_validators == None or (slot % self._spec.data.SLOTS_PER_EPOCH == 0):
logging.info(f'Processing epoch {epoch}')
beacon_validators = self._beacon.get_validators(self._clock.epoch_to_slot(epoch))
watched_validators.process_epoch(beacon_validators)

if slot % SLOT_FOR_MISSED_ATTESTATIONS_PROCESS == 0:
logging.info('Processing missed attestations')

if slot % SLOT_FOR_REWARDS_PROCESS == 0:
if rewards == None or (slot % SLOT_FOR_REWARDS_PROCESS == 0):
logging.info('Processing rewards')
rewards = self._beacon.get_rewards(epoch - 2)
process_rewards(watched_validators, rewards)
Expand All @@ -238,6 +231,7 @@ def run(self) -> None:
self._reload_config()
watched_validators.process_config(self._cfg)

logging.info('Updating Prometheus metrics')
self._update_metrics(watched_validators, epoch, slot)

self._clock.maybe_wait_for_slot(slot + 1, time.time())
Expand Down

0 comments on commit dab0dba

Please sign in to comment.