Skip to content

Commit

Permalink
fix: undefined operators for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed Jul 20, 2023
1 parent 67f456f commit 3f6bd9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/inspector/inspector.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PrometheusService, TrackTask } from 'common/prometheus';
import { DutyMetrics, DutyService } from 'duty';
import { ClickhouseService } from 'storage';
import { EpochProcessingState } from 'storage/clickhouse';
import { RegistryService } from 'validators-registry';

@Injectable()
export class InspectorService implements OnModuleInit {
Expand All @@ -22,6 +23,7 @@ export class InspectorService implements OnModuleInit {
protected readonly prometheus: PrometheusService,
protected readonly criticalAlerts: CriticalAlertsService,
protected readonly blockCacheService: BlockCacheService,
protected readonly registryService: RegistryService,

protected readonly dutyService: DutyService,
protected readonly dutyMetrics: DutyMetrics,
Expand All @@ -42,7 +44,7 @@ export class InspectorService implements OnModuleInit {
try {
const toProcess = await this.getEpochDataToProcess();
if (toProcess) {
if (this.config.get('WORKING_MODE') === WorkingMode.Head) {
if (this.config.get('WORKING_MODE') == WorkingMode.Head) {
this.logger.warn(`Working in HEAD mode. This can cause calculation errors and inaccurate data!`);
}
const { epoch, slot, is_stored, is_calculated } = toProcess;
Expand All @@ -51,6 +53,10 @@ export class InspectorService implements OnModuleInit {
possibleHighRewardValidators = await this.dutyService.checkAndWrite({ epoch: epoch, stateSlot: slot });
}
if (!is_calculated) {
if (!this.registryService.isFilled()) {
const slotTime = await this.clClient.getSlotTime(epoch * this.config.get('FETCH_INTERVAL_SLOTS'));
await this.registryService.updateKeysRegistry(slotTime);
}
await this.dutyMetrics.calculate(epoch, possibleHighRewardValidators);
}
await this.criticalAlerts.send(epoch);
Expand Down
5 changes: 5 additions & 0 deletions src/validators-registry/registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class RegistryService {

@TrackTask('update-validators')
public async updateKeysRegistry(timestamp: number): Promise<void> {
this.logger.log('Updating validators registry data');
const tasks = await Promise.all([
this.source.update(),
this.config.get('VALIDATOR_USE_STUCK_KEYS_FILE') ? this.readStuckKeysFile() : (() => [])(),
Expand Down Expand Up @@ -57,6 +58,10 @@ export class RegistryService {
return this.stuckKeys;
}

public isFilled() {
return this.lastTimestamp > 0;
}

/**
* Returns keys of validators that are stuck and will not be monitored
* */
Expand Down

0 comments on commit 3f6bd9e

Please sign in to comment.