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

do cron each 1/4th of epoch #356

Merged
merged 4 commits into from
Sep 26, 2024
Merged

Conversation

Marketen
Copy link
Contributor

@Marketen Marketen commented Sep 26, 2024

We execute performance cron each 1/4 of epoch duration. Also simplified trackValidatorsPerformanceCron

  • Store in a variable outside the cron the lastProcessedEpoch so we dont retry once an epoch has been processed
  • Get rid of helper trackValidatorsPerformance. Everything is done inside trackValidatorsPerformanceCron.
  • Use finallyafter try-catch block of trackValidatorsPerformanceCron to write to db the data (everything went well) or the error (sometthing happened)

@Marketen Marketen requested a review from a team as a code owner September 26, 2024 11:03
packages/brain/src/index.ts Outdated Show resolved Hide resolved
// execute the performance cron task every 1/4 of an epoch
const secondsPerEpoch = slotsPerEpoch * secondsPerSlot;
const oneFourthEpochInSeconds = secondsPerEpoch / 4;
let lastProcessedEpoch: number | undefined = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not moving

let lastProcessedEpoch: number | undefined = undefined;

to the file trackValidatorsPerformanceCron and do there the logic of

    const currentEpoch = await beaconchainApi.getEpochHeader({ blockId: "finalized" });

    if (currentEpoch !== lastProcessedEpoch) {
      await trackValidatorsPerformanceCron({
        brainDb,
        postgresClient,
        beaconchainApi,
        executionClient,
        consensusClient,
        currentEpoch
      });
      lastProcessedEpoch = currentEpoch;
    }
  } catch (error) {
    logger.error(`Failed to fetch or process epoch:`, error);
  }

This way the index.ts would look cleaner. You can wrap this logic in a new function and call just this function in the cron

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@pablomendezroyo pablomendezroyo merged commit d3dcbe2 into main Sep 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants