Skip to content

Commit

Permalink
feat: improve doppelganger protection logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Sep 23, 2023
1 parent 9618dd1 commit ac28bbd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/validator/src/services/doppelgangerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,26 @@ export class DoppelgangerService {
metrics.doppelganger.statusCount.addCollect(() => this.onScrapeMetrics(metrics));
}

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

registerValidator(pubkeyHex: PubkeyHex): void {
const {currentEpoch} = this.clock;
// Disable doppelganger protection when the validator was initialized before genesis.
// There's no activity before genesis, so doppelganger is pointless.
const remainingEpochs = currentEpoch <= 0 ? 0 : DEFAULT_REMAINING_DETECTION_EPOCHS;
const nextEpochToCheck = this.clock.currentEpoch + 1;

// Log here to alert that validation won't be active until remainingEpochs == 0
if (remainingEpochs > 0) {
this.logger.info("Registered validator for doppelganger", {remainingEpochs, pubkeyHex});
this.logger.info("Registered validator for doppelganger", {remainingEpochs, nextEpochToCheck, pubkeyHex});
}

this.doppelgangerStateByPubkey.set(pubkeyHex, {
nextEpochToCheck: this.clock.currentEpoch + 1,
nextEpochToCheck,
remainingEpochs,
});
}
Expand Down Expand Up @@ -118,11 +122,12 @@ export class DoppelgangerService {
}
}

this.logger.debug("doppelganger pollLiveness", {currentEpoch, indicesCount: indicesToCheckMap.size});
if (indicesToCheckMap.size === 0) {
return;
}

this.logger.info("Doppelganger liveness check", {currentEpoch, indicesCount: indicesToCheckMap.size});

// in the current epoch also request for liveness check for past epoch in case a validator index was live
// in the remaining 25% of the last slot of the previous epoch
const indicesToCheck = Array.from(indicesToCheckMap.keys());
Expand Down

0 comments on commit ac28bbd

Please sign in to comment.