Skip to content

Commit

Permalink
feat: ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed May 18, 2023
1 parent d568cfb commit 85f10c7
Show file tree
Hide file tree
Showing 7 changed files with 740 additions and 475 deletions.
3 changes: 3 additions & 0 deletions docker/validators/ignore_list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this list of validators indexes is used to ignore some validators
# in metrics calculation
indexes: []
3 changes: 3 additions & 0 deletions src/common/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export class EnvironmentVariables {
@IsString()
public VALIDATOR_REGISTRY_LIDO_SOURCE_SQLITE_CACHE_PATH = './docker/validators/lido_mainnet.db';

@IsString()
public VALIDATOR_IGNORE_LIST = './docker/validators/ignore_list.yaml';

/**
* Distance (down) from Blockchain Sync Participation average after which we think that our sync participation is bad
* For example:
Expand Down
17 changes: 15 additions & 2 deletions src/duty/duty.metrics.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { readFile } from 'fs/promises';

import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { Inject, Injectable, LoggerService } from '@nestjs/common';
import { load } from 'js-yaml';

import { ConfigService } from 'common/config';
import { ConsensusProviderService } from 'common/eth-providers';
import { Epoch } from 'common/eth-providers/consensus-provider/types';
import { allSettled } from 'common/functions/allSettled';
import { PrometheusService, TrackTask } from 'common/prometheus';
Expand All @@ -21,7 +23,6 @@ export class DutyMetrics {
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService,
protected readonly config: ConfigService,
protected readonly prometheus: PrometheusService,
protected readonly clClient: ConsensusProviderService,

protected readonly stateMetrics: StateMetrics,
protected readonly attestationMetrics: AttestationMetrics,
Expand All @@ -34,6 +35,7 @@ export class DutyMetrics {

@TrackTask('calc-all-duties-metrics')
public async calculate(epoch: Epoch, possibleHighRewardValidators: string[]): Promise<any> {
await this.storage.setIndexesIgnoreListForMetrics(await this.getIndexesIgnoreListForMetrics());
this.logger.log('Calculating duties metrics of user validators');
await allSettled([
this.withPossibleHighReward(epoch, possibleHighRewardValidators),
Expand All @@ -52,4 +54,15 @@ export class DutyMetrics {
this.syncMetrics.calculate(epoch, possibleHighRewardValidators),
]);
}

private async getIndexesIgnoreListForMetrics(): Promise<string[] | undefined> {
try {
const fileContent = await readFile(this.config.get('VALIDATOR_IGNORE_LIST'), 'utf-8');
const { indexes } = <{ indexes: string[] }>load(fileContent);
return indexes;
} catch (e) {
this.logger.error(`Error while reading ignore list file: ${e.message}`);
return [];
}
}
}
15 changes: 13 additions & 2 deletions src/duty/sync/sync.metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ export class SyncMetrics {
}

private async goodSyncParticipationLastEpoch(chainAvgSyncPercent: number) {
const data = await this.storage.getValidatorsCountWithGoodSyncParticipationLastNEpoch(this.processedEpoch, 1, chainAvgSyncPercent);
const data = await this.storage.getValidatorsCountWithGoodSyncParticipationLastNEpoch(
this.processedEpoch,
1,
chainAvgSyncPercent,
this.storage.ignoreList,
);
setUserOperatorsMetric(this.prometheus.validatorsCountWithGoodSyncParticipation, data, this.operators);
setOtherOperatorsMetric(this.prometheus.otherValidatorsCountWithGoodSyncParticipation, data);
}

private async badSyncParticipationLastEpoch(chainAvgSyncPercent: number) {
const data = await this.storage.getValidatorsCountWithBadSyncParticipationLastNEpoch(this.processedEpoch, 1, chainAvgSyncPercent);
const data = await this.storage.getValidatorsCountWithBadSyncParticipationLastNEpoch(
this.processedEpoch,
1,
chainAvgSyncPercent,
this.storage.ignoreList,
);
setUserOperatorsMetric(this.prometheus.validatorsCountWithSyncParticipationLessAvg, data, this.operators);
setOtherOperatorsMetric(this.prometheus.otherValidatorsCountWithSyncParticipationLessAvg, data);
}
Expand All @@ -87,6 +97,7 @@ export class SyncMetrics {
this.processedEpoch,
this.epochInterval,
chainAvgSyncPercent,
this.storage.ignoreList,
);
setUserOperatorsMetric(this.prometheus.validatorsCountWithSyncParticipationLessAvgLastNEpoch, data, this.operators, {
epoch_interval: this.epochInterval,
Expand Down
Loading

0 comments on commit 85f10c7

Please sign in to comment.