Skip to content

Commit

Permalink
Use finality endpoint (#362)
Browse files Browse the repository at this point in the history
* Use finality endpoint

* Fetch first block proposals
  • Loading branch information
pablomendezroyo authored Sep 27, 2024
1 parent 5038fd4 commit c958e28
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export async function trackValidatorsPerformanceCron({
consensusClient: ConsensusClient;
}): Promise<void> {
try {
const currentEpoch = await beaconchainApi.getEpochHeader({ blockId: "finalized" });
// Get finalized epoch from finality endpoint instead of from header endpoint.
// The header endpoint might jump two epochs in one call (due to missed block proposals), which would cause the cron to skip an epoch.
const currentEpoch = parseInt(
(
await beaconchainApi.getStateFinalityCheckpoints({
stateId: "finalized"
})
).data.finalized.epoch
);

// If the current epoch is different from the last processed epoch, or epoch is the same but the last epoch was processed with an error
// then fetch and insert the performance data
Expand Down Expand Up @@ -88,13 +96,13 @@ export async function fetchAndInsertPerformanceCron({
if (is_syncing) throw new NodeSyncingError("Node is syncing");
if (el_offline) throw new ExecutionOfflineError("Execution layer is offline");

validatorsAttestationsTotalRewards = await getAttestationsTotalRewards({
validatorBlockStatusMap = await getBlockProposalStatusMap({
beaconchainApi,
epoch: currentEpoch.toString(),
activeValidatorsIndexes
});

validatorBlockStatusMap = await getBlockProposalStatusMap({
validatorsAttestationsTotalRewards = await getAttestationsTotalRewards({
beaconchainApi,
epoch: currentEpoch.toString(),
activeValidatorsIndexes
Expand Down

0 comments on commit c958e28

Please sign in to comment.