Skip to content

Commit

Permalink
fix: only check doppelganger liveness for relevant epochs
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Sep 29, 2023
1 parent 1397834 commit 4ad6603
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/validator/src/services/doppelgangerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ export class DoppelgangerService {
metrics.doppelganger.statusCount.addCollect(() => this.onScrapeMetrics(metrics));
}

this.logger.info("Doppelganger protection enabled", {
currentEpoch: this.clock.currentEpoch,
detectionEpochs: DEFAULT_REMAINING_DETECTION_EPOCHS,
});
this.logger.info("Doppelganger protection enabled", {detectionEpochs: DEFAULT_REMAINING_DETECTION_EPOCHS});
}

registerValidator(pubkeyHex: PubkeyHex): void {
Expand Down Expand Up @@ -103,7 +100,7 @@ export class DoppelgangerService {
const indicesToCheckMap = new Map<ValidatorIndex, PubkeyHex>();

for (const [pubkeyHex, state] of this.doppelgangerStateByPubkey.entries()) {
if (state.remainingEpochs > 0) {
if (state.remainingEpochs > 0 && state.nextEpochToCheck <= currentEpoch) {
const index = this.indicesService.pubkey2index.get(pubkeyHex);
if (index !== undefined) {
indicesToCheckMap.set(index, pubkeyHex);
Expand Down Expand Up @@ -226,11 +223,11 @@ export class DoppelgangerService {
state.nextEpochToCheck = currentEpoch;
this.metrics?.doppelganger.epochsChecked.inc(1);

const {remainingEpochs} = state;
const {remainingEpochs, nextEpochToCheck} = state;
if (remainingEpochs <= 0) {
this.logger.info("Doppelganger detection complete", {index: response.index});
} else {
this.logger.info("Found no doppelganger", {remainingEpochs, index: response.index});
this.logger.info("Found no doppelganger", {remainingEpochs, nextEpochToCheck, index: response.index});
}
}
}
Expand Down

0 comments on commit 4ad6603

Please sign in to comment.