From 7f0252273ebd8a39e84dba25250a28f1a26e0c93 Mon Sep 17 00:00:00 2001 From: Vladimir Gorkavenko <32727352+vgorkavenko@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:26:27 +0400 Subject: [PATCH] fix: unused module init (#182) * fix: structure, unused import * fix: test * fix: stub registry source * fix: stub registry source --- .github/workflows/test-e2e.yml | 3 +- README.md | 2 +- src/app/app.module.ts | 15 +---- src/app/app.service.ts | 5 +- src/common/alertmanager/alerts/BasicAlert.ts | 4 +- .../alerts/CriticalMissedAttestations.ts | 4 +- .../alerts/CriticalMissedProposes.ts | 4 +- .../alerts/CriticalNegativeDelta.ts | 4 +- .../alertmanager/alerts/CriticalSlashing.ts | 4 +- .../alertmanager/critical-alerts.module.ts | 3 +- .../alertmanager/critical-alerts.service.ts | 4 +- src/common/config/env.validation.ts | 8 +-- .../block-cache/block-cache.module.ts | 0 .../block-cache/block-cache.service.ts | 0 .../consensus-provider/block-cache/index.ts | 0 .../consensus-provider.module.ts | 0 .../consensus-provider.service.ts | 0 .../consensus-provider/errors/index.ts | 0 .../errors/maxdeep.error.ts | 0 .../errors/response.error.ts | 0 .../consensus-provider/index.ts | 0 .../consensus-provider/intefaces/index.ts | 0 .../intefaces/response.interface.ts | 0 .../consensus-provider/types/index.ts | 0 .../types/primitive.type.ts | 0 src/common/contracts/contracts.module.ts | 17 ----- src/common/contracts/index.ts | 1 - .../eth-providers/eth-providers.module.ts | 12 ---- src/common/eth-providers/index.ts | 3 - .../execution-provider.module.ts | 0 .../execution-provider.service.ts | 0 .../execution-provider/index.ts | 0 src/common/prometheus/prometheus.constants.ts | 2 +- src/common/prometheus/prometheus.service.ts | 2 +- .../validators-registry/registry.module.ts | 40 ------------ src/duty/attestation/attestation.metrics.ts | 4 +- src/duty/attestation/attestation.module.ts | 7 +- src/duty/attestation/attestation.rewards.ts | 4 +- src/duty/attestation/attestation.service.ts | 6 +- src/duty/duty.metrics.ts | 2 +- src/duty/duty.module.ts | 6 +- src/duty/duty.rewards.ts | 2 +- src/duty/duty.service.ts | 6 +- src/duty/propose/propose.metrics.ts | 4 +- src/duty/propose/propose.module.ts | 7 +- src/duty/propose/propose.rewards.ts | 5 +- src/duty/propose/propose.service.ts | 7 +- src/duty/state/state.metrics.ts | 6 +- src/duty/state/state.module.ts | 7 +- src/duty/state/state.service.ts | 9 ++- src/duty/summary/summary.metrics.ts | 6 +- src/duty/summary/summary.module.ts | 5 +- src/duty/summary/summary.service.ts | 4 +- src/duty/sync/sync.metrics.ts | 5 +- src/duty/sync/sync.module.ts | 7 +- src/duty/sync/sync.rewards.ts | 5 +- src/duty/sync/sync.service.ts | 6 +- src/duty/withdrawal/withdrawals.metrics.ts | 4 +- src/duty/withdrawal/withdrawals.module.ts | 7 +- src/duty/withdrawal/withdrawals.service.ts | 9 ++- src/inspector/inspector.module.ts | 8 +-- src/inspector/inspector.service.ts | 6 +- src/main.ts | 3 +- .../clickhouse/clickhouse.constants.ts | 4 +- src/storage/clickhouse/clickhouse.service.ts | 2 +- src/storage/clickhouse/clickhouse.types.ts | 2 +- .../file-source/file-source.module.ts | 0 .../file-source/file-source.service.ts | 0 .../validators-registry/file-source/index.ts | 0 src/{common => }/validators-registry/index.ts | 0 .../keysapi-source/index.ts | 0 .../keysapi-source/keysapi-source.client.ts | 2 +- .../keysapi-source/keysapi-source.module.ts | 0 .../keysapi-source/keysapi-source.service.ts | 3 +- .../lido-source}/database/database.module.ts | 0 .../lido-source}/database/database.service.ts | 0 .../lido-source}/database/index.ts | 0 .../validators-registry/lido-source/index.ts | 0 .../lido-source/lido-source.module.ts | 5 +- .../lido-source/lido-source.service.ts | 3 +- .../registry-source.interface.ts | 0 src/validators-registry/registry.module.ts | 65 +++++++++++++++++++ .../validators-registry/registry.service.ts | 0 test/duties.e2e-spec.ts | 62 ++---------------- test/jest-e2e.json | 5 +- 85 files changed, 179 insertions(+), 268 deletions(-) rename src/common/{eth-providers => }/consensus-provider/block-cache/block-cache.module.ts (100%) rename src/common/{eth-providers => }/consensus-provider/block-cache/block-cache.service.ts (100%) rename src/common/{eth-providers => }/consensus-provider/block-cache/index.ts (100%) rename src/common/{eth-providers => }/consensus-provider/consensus-provider.module.ts (100%) rename src/common/{eth-providers => }/consensus-provider/consensus-provider.service.ts (100%) rename src/common/{eth-providers => }/consensus-provider/errors/index.ts (100%) rename src/common/{eth-providers => }/consensus-provider/errors/maxdeep.error.ts (100%) rename src/common/{eth-providers => }/consensus-provider/errors/response.error.ts (100%) rename src/common/{eth-providers => }/consensus-provider/index.ts (100%) rename src/common/{eth-providers => }/consensus-provider/intefaces/index.ts (100%) rename src/common/{eth-providers => }/consensus-provider/intefaces/response.interface.ts (100%) rename src/common/{eth-providers => }/consensus-provider/types/index.ts (100%) rename src/common/{eth-providers => }/consensus-provider/types/primitive.type.ts (100%) delete mode 100644 src/common/contracts/contracts.module.ts delete mode 100644 src/common/contracts/index.ts delete mode 100644 src/common/eth-providers/eth-providers.module.ts delete mode 100644 src/common/eth-providers/index.ts rename src/common/{eth-providers => }/execution-provider/execution-provider.module.ts (100%) rename src/common/{eth-providers => }/execution-provider/execution-provider.service.ts (100%) rename src/common/{eth-providers => }/execution-provider/index.ts (100%) delete mode 100644 src/common/validators-registry/registry.module.ts rename src/{common => }/validators-registry/file-source/file-source.module.ts (100%) rename src/{common => }/validators-registry/file-source/file-source.service.ts (100%) rename src/{common => }/validators-registry/file-source/index.ts (100%) rename src/{common => }/validators-registry/index.ts (100%) rename src/{common => }/validators-registry/keysapi-source/index.ts (100%) rename src/{common => }/validators-registry/keysapi-source/keysapi-source.client.ts (98%) rename src/{common => }/validators-registry/keysapi-source/keysapi-source.module.ts (100%) rename src/{common => }/validators-registry/keysapi-source/keysapi-source.service.ts (98%) rename src/{storage => validators-registry/lido-source}/database/database.module.ts (100%) rename src/{storage => validators-registry/lido-source}/database/database.service.ts (100%) rename src/{storage => validators-registry/lido-source}/database/index.ts (100%) rename src/{common => }/validators-registry/lido-source/index.ts (100%) rename src/{common => }/validators-registry/lido-source/lido-source.module.ts (72%) rename src/{common => }/validators-registry/lido-source/lido-source.service.ts (97%) rename src/{common => }/validators-registry/registry-source.interface.ts (100%) create mode 100644 src/validators-registry/registry.module.ts rename src/{common => }/validators-registry/registry.service.ts (100%) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index d1070e89..49555eb5 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -33,5 +33,4 @@ jobs: TEST_EPOCH_NUMBER: 152978 TEST_STATE_SLOT: 4895327 # stub - ETH_NETWORK: 1 - EL_RPC_URLS: localhost + VALIDATOR_REGISTRY_SOURCE: file diff --git a/README.md b/README.md index 94154ff9..34f96be0 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ By default, monitoring bot fetches validator keys from Lido contract, but you ca 2. Create file with keys by example [here](docker/validators/custom_mainnet.yaml) 3. Set `VALIDATOR_REGISTRY_FILE_SOURCE_PATH` env var to `` -If you want to implement your own source, it must match [RegistrySource interface](src/common/validators-registry/registry-source.interface.ts) and be included in [RegistryModule providers](src/common/validators-registry/registry.module.ts) +If you want to implement your own source, it must match [RegistrySource interface](src/validators-registry/registry-source.interface.ts) and be included in [RegistryModule providers](src/validators-registry/registry.module.ts) ## Application Env variables diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 08047917..9ddca17f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,29 +1,16 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from 'common/config'; -import { ContractsModule } from 'common/contracts'; -import { EthProvidersModule } from 'common/eth-providers'; import { HealthModule } from 'common/health'; import { LoggerModule } from 'common/logger'; import { PrometheusModule } from 'common/prometheus'; import { ClickhouseModule } from 'storage/clickhouse'; -import { DatabaseModule } from 'storage/database'; import { InspectorModule } from '../inspector'; import { AppService } from './app.service'; @Module({ - imports: [ - LoggerModule, - HealthModule, - PrometheusModule, - ConfigModule, - DatabaseModule, - ClickhouseModule, - InspectorModule, - ContractsModule, - EthProvidersModule, - ], + imports: [LoggerModule, HealthModule, ConfigModule, PrometheusModule, ClickhouseModule, InspectorModule], providers: [AppService], }) export class AppModule {} diff --git a/src/app/app.service.ts b/src/app/app.service.ts index 1b189cd9..54bd0bc1 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -3,7 +3,6 @@ import { Inject, Injectable, LoggerService, OnApplicationBootstrap, OnModuleInit import * as buildInfo from 'build-info'; import { ConfigService } from 'common/config'; -import { ExecutionProviderService } from 'common/eth-providers'; import { PrometheusService } from 'common/prometheus'; import { InspectorService } from '../inspector'; @@ -16,20 +15,18 @@ export class AppService implements OnModuleInit, OnApplicationBootstrap { protected readonly configService: ConfigService, protected readonly prometheus: PrometheusService, protected readonly inspectorService: InspectorService, - protected readonly executionProviderService: ExecutionProviderService, ) {} public async onModuleInit(): Promise { const env = this.configService.get('NODE_ENV'); const startEpoch = this.configService.get('START_EPOCH'); - const network = await this.executionProviderService.getNetworkName(); const version = buildInfo.version; const commit = buildInfo.commit; const branch = buildInfo.branch; const name = APP_NAME; this.prometheus.buildInfo.labels({ env, name, version, commit, branch }).inc(); - this.logger.log('Init app', { env, network, name, version, startEpoch }); + this.logger.log('Init app', { env, name, version, startEpoch }); this.logger.log(`DRY RUN ${this.configService.get('DRY_RUN') ? 'enabled' : 'disabled'}`); this.logger.log(`Slot time: ${this.configService.get('CHAIN_SLOT_TIME_SECONDS')} seconds`); this.logger.log(`Epoch size: ${this.configService.get('FETCH_INTERVAL_SLOTS')} slots`); diff --git a/src/common/alertmanager/alerts/BasicAlert.ts b/src/common/alertmanager/alerts/BasicAlert.ts index 4532f2b7..7299518f 100644 --- a/src/common/alertmanager/alerts/BasicAlert.ts +++ b/src/common/alertmanager/alerts/BasicAlert.ts @@ -1,7 +1,7 @@ import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; -import { RegistrySourceOperator } from 'common/validators-registry'; +import { Epoch } from 'common/consensus-provider/types'; import { ClickhouseService } from 'storage'; +import { RegistrySourceOperator } from 'validators-registry'; export interface AlertRequestBody { startsAt: string; diff --git a/src/common/alertmanager/alerts/CriticalMissedAttestations.ts b/src/common/alertmanager/alerts/CriticalMissedAttestations.ts index 9b9109ed..5d061271 100644 --- a/src/common/alertmanager/alerts/CriticalMissedAttestations.ts +++ b/src/common/alertmanager/alerts/CriticalMissedAttestations.ts @@ -2,9 +2,9 @@ import { join } from 'lodash'; import { sentAlerts } from 'common/alertmanager'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; -import { RegistrySourceOperator } from 'common/validators-registry'; +import { Epoch } from 'common/consensus-provider/types'; import { ClickhouseService } from 'storage'; +import { RegistrySourceOperator } from 'validators-registry'; import { Alert, AlertRequestBody, AlertRuleResult } from './BasicAlert'; diff --git a/src/common/alertmanager/alerts/CriticalMissedProposes.ts b/src/common/alertmanager/alerts/CriticalMissedProposes.ts index a2d98993..e041bcef 100644 --- a/src/common/alertmanager/alerts/CriticalMissedProposes.ts +++ b/src/common/alertmanager/alerts/CriticalMissedProposes.ts @@ -2,9 +2,9 @@ import { join } from 'lodash'; import { sentAlerts } from 'common/alertmanager'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; -import { RegistrySourceOperator } from 'common/validators-registry'; +import { Epoch } from 'common/consensus-provider/types'; import { ClickhouseService } from 'storage'; +import { RegistrySourceOperator } from 'validators-registry'; import { Alert, AlertRequestBody, AlertRuleResult } from './BasicAlert'; diff --git a/src/common/alertmanager/alerts/CriticalNegativeDelta.ts b/src/common/alertmanager/alerts/CriticalNegativeDelta.ts index 50a82a87..ad8647b4 100644 --- a/src/common/alertmanager/alerts/CriticalNegativeDelta.ts +++ b/src/common/alertmanager/alerts/CriticalNegativeDelta.ts @@ -2,9 +2,9 @@ import { join } from 'lodash'; import { sentAlerts } from 'common/alertmanager'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; -import { RegistrySourceOperator } from 'common/validators-registry'; +import { Epoch } from 'common/consensus-provider/types'; import { ClickhouseService } from 'storage'; +import { RegistrySourceOperator } from 'validators-registry'; import { Alert, AlertRequestBody, AlertRuleResult } from './BasicAlert'; diff --git a/src/common/alertmanager/alerts/CriticalSlashing.ts b/src/common/alertmanager/alerts/CriticalSlashing.ts index a4732d31..0ad43d62 100644 --- a/src/common/alertmanager/alerts/CriticalSlashing.ts +++ b/src/common/alertmanager/alerts/CriticalSlashing.ts @@ -1,9 +1,9 @@ import { join } from 'lodash'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; -import { RegistrySourceOperator } from 'common/validators-registry'; +import { Epoch } from 'common/consensus-provider/types'; import { ClickhouseService } from 'storage'; +import { RegistrySourceOperator } from 'validators-registry'; import { Alert, AlertRequestBody, AlertRuleResult } from './BasicAlert'; diff --git a/src/common/alertmanager/critical-alerts.module.ts b/src/common/alertmanager/critical-alerts.module.ts index 3e935aef..7706dba9 100644 --- a/src/common/alertmanager/critical-alerts.module.ts +++ b/src/common/alertmanager/critical-alerts.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; -import { RegistryModule } from 'common/validators-registry'; import { ClickhouseModule } from 'storage/clickhouse'; import { CriticalAlertsService } from './critical-alerts.service'; @Module({ - imports: [RegistryModule, ClickhouseModule], + imports: [ClickhouseModule], providers: [CriticalAlertsService], exports: [CriticalAlertsService], }) diff --git a/src/common/alertmanager/critical-alerts.service.ts b/src/common/alertmanager/critical-alerts.service.ts index 79bb5161..aea0d9a6 100644 --- a/src/common/alertmanager/critical-alerts.service.ts +++ b/src/common/alertmanager/critical-alerts.service.ts @@ -3,10 +3,10 @@ import { Inject, Injectable } from '@nestjs/common'; import { got } from 'got-cjs'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { PrometheusService } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; import { AlertRequestBody, PreparedToSendAlert } from './alerts/BasicAlert'; import { CriticalMissedAttestations } from './alerts/CriticalMissedAttestations'; diff --git a/src/common/config/env.validation.ts b/src/common/config/env.validation.ts index 23be4068..200ef7f0 100644 --- a/src/common/config/env.validation.ts +++ b/src/common/config/env.validation.ts @@ -125,14 +125,14 @@ export class EnvironmentVariables { @Min(1) @Max(5000000) @Transform(({ value }) => parseInt(value, 10), { toClassOnly: true }) - @ValidateIf((vars) => vars.NODE_ENV != Environment.test) + @ValidateIf((vars) => vars.VALIDATOR_REGISTRY_SOURCE == ValidatorRegistrySource.Lido && vars.NODE_ENV != Environment.test) public ETH_NETWORK!: Network; @IsArray() @ArrayMinSize(1) @Transform(({ value }) => value.split(',')) - @ValidateIf((vars) => vars.NODE_ENV != Environment.test) - public EL_RPC_URLS!: string[]; + @ValidateIf((vars) => vars.VALIDATOR_REGISTRY_SOURCE == ValidatorRegistrySource.Lido && vars.NODE_ENV != Environment.test) + public EL_RPC_URLS: string[] = []; @IsArray() @ArrayMinSize(1) @@ -185,7 +185,7 @@ export class EnvironmentVariables { @ArrayMinSize(1) @Transform(({ value }) => value.split(',')) @ValidateIf((vars) => vars.VALIDATOR_REGISTRY_SOURCE == ValidatorRegistrySource.KeysAPI && vars.NODE_ENV != Environment.test) - public VALIDATOR_REGISTRY_KEYSAPI_SOURCE_URLS = []; + public VALIDATOR_REGISTRY_KEYSAPI_SOURCE_URLS!: string[]; @IsInt() @Transform(({ value }) => parseInt(value, 10), { toClassOnly: true }) diff --git a/src/common/eth-providers/consensus-provider/block-cache/block-cache.module.ts b/src/common/consensus-provider/block-cache/block-cache.module.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/block-cache/block-cache.module.ts rename to src/common/consensus-provider/block-cache/block-cache.module.ts diff --git a/src/common/eth-providers/consensus-provider/block-cache/block-cache.service.ts b/src/common/consensus-provider/block-cache/block-cache.service.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/block-cache/block-cache.service.ts rename to src/common/consensus-provider/block-cache/block-cache.service.ts diff --git a/src/common/eth-providers/consensus-provider/block-cache/index.ts b/src/common/consensus-provider/block-cache/index.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/block-cache/index.ts rename to src/common/consensus-provider/block-cache/index.ts diff --git a/src/common/eth-providers/consensus-provider/consensus-provider.module.ts b/src/common/consensus-provider/consensus-provider.module.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/consensus-provider.module.ts rename to src/common/consensus-provider/consensus-provider.module.ts diff --git a/src/common/eth-providers/consensus-provider/consensus-provider.service.ts b/src/common/consensus-provider/consensus-provider.service.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/consensus-provider.service.ts rename to src/common/consensus-provider/consensus-provider.service.ts diff --git a/src/common/eth-providers/consensus-provider/errors/index.ts b/src/common/consensus-provider/errors/index.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/errors/index.ts rename to src/common/consensus-provider/errors/index.ts diff --git a/src/common/eth-providers/consensus-provider/errors/maxdeep.error.ts b/src/common/consensus-provider/errors/maxdeep.error.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/errors/maxdeep.error.ts rename to src/common/consensus-provider/errors/maxdeep.error.ts diff --git a/src/common/eth-providers/consensus-provider/errors/response.error.ts b/src/common/consensus-provider/errors/response.error.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/errors/response.error.ts rename to src/common/consensus-provider/errors/response.error.ts diff --git a/src/common/eth-providers/consensus-provider/index.ts b/src/common/consensus-provider/index.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/index.ts rename to src/common/consensus-provider/index.ts diff --git a/src/common/eth-providers/consensus-provider/intefaces/index.ts b/src/common/consensus-provider/intefaces/index.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/intefaces/index.ts rename to src/common/consensus-provider/intefaces/index.ts diff --git a/src/common/eth-providers/consensus-provider/intefaces/response.interface.ts b/src/common/consensus-provider/intefaces/response.interface.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/intefaces/response.interface.ts rename to src/common/consensus-provider/intefaces/response.interface.ts diff --git a/src/common/eth-providers/consensus-provider/types/index.ts b/src/common/consensus-provider/types/index.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/types/index.ts rename to src/common/consensus-provider/types/index.ts diff --git a/src/common/eth-providers/consensus-provider/types/primitive.type.ts b/src/common/consensus-provider/types/primitive.type.ts similarity index 100% rename from src/common/eth-providers/consensus-provider/types/primitive.type.ts rename to src/common/consensus-provider/types/primitive.type.ts diff --git a/src/common/contracts/contracts.module.ts b/src/common/contracts/contracts.module.ts deleted file mode 100644 index 20670787..00000000 --- a/src/common/contracts/contracts.module.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { LidoContractModule } from '@lido-nestjs/contracts'; -import { Global, Module } from '@nestjs/common'; - -import { ExecutionProvider } from 'common/eth-providers'; - -@Global() -@Module({ - imports: [ - LidoContractModule.forRootAsync({ - async useFactory(provider: ExecutionProvider) { - return { provider }; - }, - inject: [ExecutionProvider], - }), - ], -}) -export class ContractsModule {} diff --git a/src/common/contracts/index.ts b/src/common/contracts/index.ts deleted file mode 100644 index 3b9f7e97..00000000 --- a/src/common/contracts/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './contracts.module'; diff --git a/src/common/eth-providers/eth-providers.module.ts b/src/common/eth-providers/eth-providers.module.ts deleted file mode 100644 index e79c9c07..00000000 --- a/src/common/eth-providers/eth-providers.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from '@nestjs/common'; - -import { ConsensusProviderModule, ConsensusProviderService } from './consensus-provider'; -import { BlockCacheModule } from './consensus-provider/block-cache'; -import { ExecutionProviderModule, ExecutionProviderService } from './execution-provider'; - -@Module({ - imports: [ExecutionProviderModule, ConsensusProviderModule, BlockCacheModule], - providers: [ExecutionProviderService, ConsensusProviderService], - exports: [ExecutionProviderService, ConsensusProviderService], -}) -export class EthProvidersModule {} diff --git a/src/common/eth-providers/index.ts b/src/common/eth-providers/index.ts deleted file mode 100644 index 7830f10c..00000000 --- a/src/common/eth-providers/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './execution-provider'; -export * from './consensus-provider'; -export * from './eth-providers.module'; diff --git a/src/common/eth-providers/execution-provider/execution-provider.module.ts b/src/common/execution-provider/execution-provider.module.ts similarity index 100% rename from src/common/eth-providers/execution-provider/execution-provider.module.ts rename to src/common/execution-provider/execution-provider.module.ts diff --git a/src/common/eth-providers/execution-provider/execution-provider.service.ts b/src/common/execution-provider/execution-provider.service.ts similarity index 100% rename from src/common/eth-providers/execution-provider/execution-provider.service.ts rename to src/common/execution-provider/execution-provider.service.ts diff --git a/src/common/eth-providers/execution-provider/index.ts b/src/common/execution-provider/index.ts similarity index 100% rename from src/common/eth-providers/execution-provider/index.ts rename to src/common/execution-provider/index.ts diff --git a/src/common/prometheus/prometheus.constants.ts b/src/common/prometheus/prometheus.constants.ts index e5ab7330..f7b88f40 100644 --- a/src/common/prometheus/prometheus.constants.ts +++ b/src/common/prometheus/prometheus.constants.ts @@ -1,4 +1,4 @@ -import { APP_NAME } from '../../app'; +import { APP_NAME } from 'app'; export const METRICS_URL = '/metrics'; export const METRICS_PREFIX = `${APP_NAME.replace(/[- ]/g, '_')}_`; diff --git a/src/common/prometheus/prometheus.service.ts b/src/common/prometheus/prometheus.service.ts index 97471f85..f00bba59 100644 --- a/src/common/prometheus/prometheus.service.ts +++ b/src/common/prometheus/prometheus.service.ts @@ -5,8 +5,8 @@ import { join } from 'lodash'; import { LabelValues } from 'prom-client'; import { ConfigService } from 'common/config'; +import { RegistrySourceOperator } from 'validators-registry'; -import { RegistrySourceOperator } from '../validators-registry'; import { Metric, Options } from './interfaces'; import { METRICS_PREFIX, diff --git a/src/common/validators-registry/registry.module.ts b/src/common/validators-registry/registry.module.ts deleted file mode 100644 index acd1b8c0..00000000 --- a/src/common/validators-registry/registry.module.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; -import { LoggerService, Module } from '@nestjs/common'; - -import { ConfigService, ValidatorRegistrySource } from 'common/config'; - -import { FileSourceModule, FileSourceService } from './file-source'; -import { KeysapiSourceModule, KeysapiSourceService } from './keysapi-source'; -import { LidoSourceModule, LidoSourceService } from './lido-source'; -import { REGISTRY_SOURCE, RegistrySource } from './registry-source.interface'; -import { RegistryService } from './registry.service'; - -@Module({ - imports: [LidoSourceModule, FileSourceModule, KeysapiSourceModule], - providers: [ - RegistryService, - { - provide: REGISTRY_SOURCE, - useFactory: async ( - logger: LoggerService, - config: ConfigService, - lido: LidoSourceService, - file: FileSourceService, - keysapi: KeysapiSourceService, - ): Promise => { - switch (config.get('VALIDATOR_REGISTRY_SOURCE')) { - case ValidatorRegistrySource.Lido: - logger.warn('DEPRECATED: VALIDATOR_REGISTRY_SOURCE=lido. Use VALIDATOR_REGISTRY_SOURCE=keysapi instead'); - return lido; - case ValidatorRegistrySource.File: - return file; - case ValidatorRegistrySource.KeysAPI: - return keysapi; - } - }, - inject: [LOGGER_PROVIDER, ConfigService, LidoSourceService, FileSourceService, KeysapiSourceService], - }, - ], - exports: [RegistryService], -}) -export class RegistryModule {} diff --git a/src/duty/attestation/attestation.metrics.ts b/src/duty/attestation/attestation.metrics.ts index 20595556..83caf6ae 100644 --- a/src/duty/attestation/attestation.metrics.ts +++ b/src/duty/attestation/attestation.metrics.ts @@ -2,11 +2,11 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask, setOtherOperatorsMetric, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage/clickhouse'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; enum BadAttReason { HighIncDelay = 'high_inclusion_delay', diff --git a/src/duty/attestation/attestation.module.ts b/src/duty/attestation/attestation.module.ts index 06106fe9..8ab89aee 100644 --- a/src/duty/attestation/attestation.module.ts +++ b/src/duty/attestation/attestation.module.ts @@ -1,16 +1,15 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { SummaryModule } from 'duty/summary'; import { ClickhouseModule } from 'storage/clickhouse'; -import { SummaryModule } from '../summary'; import { AttestationMetrics } from './attestation.metrics'; import { AttestationRewards } from './attestation.rewards'; import { AttestationService } from './attestation.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], + imports: [ConsensusProviderModule, ClickhouseModule, SummaryModule], providers: [AttestationService, AttestationMetrics, AttestationRewards], exports: [AttestationService, AttestationMetrics, AttestationRewards], }) diff --git a/src/duty/attestation/attestation.rewards.ts b/src/duty/attestation/attestation.rewards.ts index 24e97cf3..3e079477 100644 --- a/src/duty/attestation/attestation.rewards.ts +++ b/src/duty/attestation/attestation.rewards.ts @@ -3,11 +3,11 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { unblock } from 'common/functions/unblock'; import { PrometheusService } from 'common/prometheus'; +import { SummaryService } from 'duty/summary'; -import { SummaryService } from '../summary'; import { getPenalties, getRewards } from './attestation.constants'; @Injectable() diff --git a/src/duty/attestation/attestation.service.ts b/src/duty/attestation/attestation.service.ts index a4e5e8fb..198568e4 100644 --- a/src/duty/attestation/attestation.service.ts +++ b/src/duty/attestation/attestation.service.ts @@ -8,14 +8,14 @@ import { streamArray } from 'stream-json/streamers/StreamArray'; import { batch } from 'stream-json/utils/Batch'; import { ConfigService } from 'common/config'; -import { AttestationCommitteeInfo, ConsensusProviderService } from 'common/eth-providers'; -import { Epoch, Slot } from 'common/eth-providers/consensus-provider/types'; +import { AttestationCommitteeInfo, ConsensusProviderService } from 'common/consensus-provider'; +import { Epoch, Slot } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { range } from 'common/functions/range'; import { unblock } from 'common/functions/unblock'; import { PrometheusService, TrackTask } from 'common/prometheus'; +import { SummaryService } from 'duty/summary'; -import { SummaryService } from '../summary'; import { getFlags } from './attestation.constants'; interface SlotAttestation { diff --git a/src/duty/duty.metrics.ts b/src/duty/duty.metrics.ts index a7f2bb65..cb57703b 100644 --- a/src/duty/duty.metrics.ts +++ b/src/duty/duty.metrics.ts @@ -2,10 +2,10 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask } from 'common/prometheus'; +import { Epoch } from '../common/consensus-provider/types'; import { ClickhouseService } from '../storage'; import { AttestationMetrics } from './attestation'; import { ProposeMetrics } from './propose'; diff --git a/src/duty/duty.module.ts b/src/duty/duty.module.ts index 29110934..c8bce21b 100644 --- a/src/duty/duty.module.ts +++ b/src/duty/duty.module.ts @@ -1,8 +1,7 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { BlockCacheModule } from 'common/eth-providers/consensus-provider/block-cache'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { BlockCacheModule } from 'common/consensus-provider/block-cache'; import { ClickhouseModule } from 'storage/clickhouse'; import { AttestationModule } from './attestation'; @@ -26,7 +25,6 @@ import { WithdrawalsModule } from './withdrawal'; ConsensusProviderModule, BlockCacheModule, ClickhouseModule, - RegistryModule, ], providers: [DutyService, DutyMetrics, DutyRewards], exports: [DutyService, DutyMetrics], diff --git a/src/duty/duty.rewards.ts b/src/duty/duty.rewards.ts index 5e00bf5d..3f87e892 100644 --- a/src/duty/duty.rewards.ts +++ b/src/duty/duty.rewards.ts @@ -2,10 +2,10 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask } from 'common/prometheus'; +import { Epoch } from '../common/consensus-provider/types'; import { AttestationRewards } from './attestation'; import { ProposeRewards } from './propose'; import { SyncRewards } from './sync'; diff --git a/src/duty/duty.service.ts b/src/duty/duty.service.ts index 72e10355..b2027ab8 100644 --- a/src/duty/duty.service.ts +++ b/src/duty/duty.service.ts @@ -2,9 +2,9 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { BlockHeaderResponse, ConsensusProviderService } from 'common/eth-providers'; -import { BlockCacheService } from 'common/eth-providers/consensus-provider/block-cache'; -import { Epoch, Slot } from 'common/eth-providers/consensus-provider/types'; +import { BlockHeaderResponse, ConsensusProviderService } from 'common/consensus-provider'; +import { BlockCacheService } from 'common/consensus-provider/block-cache'; +import { Epoch, Slot } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { range } from 'common/functions/range'; import { unblock } from 'common/functions/unblock'; diff --git a/src/duty/propose/propose.metrics.ts b/src/duty/propose/propose.metrics.ts index a9dd2ac2..febec00e 100644 --- a/src/duty/propose/propose.metrics.ts +++ b/src/duty/propose/propose.metrics.ts @@ -2,11 +2,11 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask, setOtherOperatorsMetric, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; @Injectable() export class ProposeMetrics { diff --git a/src/duty/propose/propose.module.ts b/src/duty/propose/propose.module.ts index 5e44214f..0392faa9 100644 --- a/src/duty/propose/propose.module.ts +++ b/src/duty/propose/propose.module.ts @@ -1,16 +1,15 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { SummaryModule } from 'duty/summary'; import { ClickhouseModule } from 'storage/clickhouse'; -import { SummaryModule } from '../summary'; import { ProposeMetrics } from './propose.metrics'; import { ProposeRewards } from './propose.rewards'; import { ProposeService } from './propose.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], + imports: [ConsensusProviderModule, ClickhouseModule, SummaryModule], providers: [ProposeService, ProposeMetrics, ProposeRewards], exports: [ProposeService, ProposeMetrics, ProposeRewards], }) diff --git a/src/duty/propose/propose.rewards.ts b/src/duty/propose/propose.rewards.ts index e4081bc2..1cb0f480 100644 --- a/src/duty/propose/propose.rewards.ts +++ b/src/duty/propose/propose.rewards.ts @@ -3,10 +3,9 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { PrometheusService } from 'common/prometheus'; - -import { SummaryService } from '../summary'; +import { SummaryService } from 'duty/summary'; @Injectable() export class ProposeRewards { diff --git a/src/duty/propose/propose.service.ts b/src/duty/propose/propose.service.ts index d7bf80a4..3cef1d2a 100644 --- a/src/duty/propose/propose.service.ts +++ b/src/duty/propose/propose.service.ts @@ -2,11 +2,10 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { ConsensusProviderService } from 'common/eth-providers'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { ConsensusProviderService } from 'common/consensus-provider'; +import { Epoch } from 'common/consensus-provider/types'; import { PrometheusService, TrackTask } from 'common/prometheus'; - -import { SummaryService } from '../summary'; +import { SummaryService } from 'duty/summary'; @Injectable() export class ProposeService { diff --git a/src/duty/state/state.metrics.ts b/src/duty/state/state.metrics.ts index ff7d9d04..5b926b14 100644 --- a/src/duty/state/state.metrics.ts +++ b/src/duty/state/state.metrics.ts @@ -3,12 +3,12 @@ import { RegistryOperator } from '@lido-nestjs/registry'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { Owner, PrometheusService, PrometheusValStatus, TrackTask, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; -import { LidoSourceService } from 'common/validators-registry/lido-source'; import { ClickhouseService } from 'storage/clickhouse'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; +import { LidoSourceService } from 'validators-registry/lido-source'; const GWEI_WEI_RATIO = 1e9; const ETH_GWEI_RATIO = 1e9; diff --git a/src/duty/state/state.module.ts b/src/duty/state/state.module.ts index a1a2a335..1fde4f9e 100644 --- a/src/duty/state/state.module.ts +++ b/src/duty/state/state.module.ts @@ -1,15 +1,14 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { SummaryModule } from 'duty/summary'; import { ClickhouseModule } from 'storage/clickhouse'; -import { SummaryModule } from '../summary'; import { StateMetrics } from './state.metrics'; import { StateService } from './state.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], + imports: [ConsensusProviderModule, ClickhouseModule, SummaryModule], providers: [StateService, StateMetrics], exports: [StateService, StateMetrics], }) diff --git a/src/duty/state/state.service.ts b/src/duty/state/state.service.ts index b422e851..9d10ff61 100644 --- a/src/duty/state/state.service.ts +++ b/src/duty/state/state.service.ts @@ -8,15 +8,14 @@ import { streamArray } from 'stream-json/streamers/StreamArray'; import { batch } from 'stream-json/utils/Batch'; import { ConfigService } from 'common/config'; -import { ConsensusProviderService, StateValidatorResponse, ValStatus } from 'common/eth-providers'; -import { Epoch, Slot } from 'common/eth-providers/consensus-provider/types'; +import { ConsensusProviderService, StateValidatorResponse, ValStatus } from 'common/consensus-provider'; +import { Epoch, Slot } from 'common/consensus-provider/types'; import { bigNumberSqrt } from 'common/functions/bigNumberSqrt'; import { unblock } from 'common/functions/unblock'; import { PrometheusService, TrackTask } from 'common/prometheus'; -import { RegistryService } from 'common/validators-registry'; +import { SummaryService } from 'duty/summary'; import { ClickhouseService } from 'storage/clickhouse'; - -import { SummaryService } from '../summary'; +import { RegistryService } from 'validators-registry'; @Injectable() export class StateService { diff --git a/src/duty/summary/summary.metrics.ts b/src/duty/summary/summary.metrics.ts index 83fbf4c4..35c87bdb 100644 --- a/src/duty/summary/summary.metrics.ts +++ b/src/duty/summary/summary.metrics.ts @@ -2,12 +2,12 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { ConsensusProviderService } from 'common/eth-providers'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { ConsensusProviderService } from 'common/consensus-provider'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; enum Duty { Proposal = 'proposal', diff --git a/src/duty/summary/summary.module.ts b/src/duty/summary/summary.module.ts index 56c208c2..757e30b2 100644 --- a/src/duty/summary/summary.module.ts +++ b/src/duty/summary/summary.module.ts @@ -1,14 +1,13 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; import { ClickhouseModule } from 'storage/clickhouse'; import { SummaryMetrics } from './summary.metrics'; import { SummaryService } from './summary.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule], + imports: [ConsensusProviderModule, ClickhouseModule], providers: [SummaryService, SummaryMetrics], exports: [SummaryService, SummaryMetrics], }) diff --git a/src/duty/summary/summary.service.ts b/src/duty/summary/summary.service.ts index b1e0fa51..243e5435 100644 --- a/src/duty/summary/summary.service.ts +++ b/src/duty/summary/summary.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; import { merge } from 'lodash'; -import { ValStatus } from 'common/eth-providers'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { ValStatus } from 'common/consensus-provider'; +import { Epoch } from 'common/consensus-provider/types'; import { range } from 'common/functions/range'; type BlockNumber = number; diff --git a/src/duty/sync/sync.metrics.ts b/src/duty/sync/sync.metrics.ts index 1def0d2b..e8379722 100644 --- a/src/duty/sync/sync.metrics.ts +++ b/src/duty/sync/sync.metrics.ts @@ -2,11 +2,12 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask, setOtherOperatorsMetric, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; + +import { Epoch } from '../../common/consensus-provider/types'; @Injectable() export class SyncMetrics { diff --git a/src/duty/sync/sync.module.ts b/src/duty/sync/sync.module.ts index c0fcbb6a..1322f3b6 100644 --- a/src/duty/sync/sync.module.ts +++ b/src/duty/sync/sync.module.ts @@ -1,16 +1,15 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { SummaryModule } from 'duty/summary'; import { ClickhouseModule } from 'storage/clickhouse'; -import { SummaryModule } from '../summary'; import { SyncMetrics } from './sync.metrics'; import { SyncRewards } from './sync.rewards'; import { SyncService } from './sync.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], + imports: [ConsensusProviderModule, ClickhouseModule, SummaryModule], providers: [SyncService, SyncMetrics, SyncRewards], exports: [SyncService, SyncMetrics, SyncRewards], }) diff --git a/src/duty/sync/sync.rewards.ts b/src/duty/sync/sync.rewards.ts index 592ab284..966b80d9 100644 --- a/src/duty/sync/sync.rewards.ts +++ b/src/duty/sync/sync.rewards.ts @@ -2,10 +2,9 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { PrometheusService } from 'common/prometheus'; - -import { SummaryService } from '../summary'; +import { SummaryService } from 'duty/summary'; @Injectable() export class SyncRewards { diff --git a/src/duty/sync/sync.service.ts b/src/duty/sync/sync.service.ts index 091cb8d4..eb8342b0 100644 --- a/src/duty/sync/sync.service.ts +++ b/src/duty/sync/sync.service.ts @@ -3,11 +3,11 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { BlockInfoResponse, ConsensusProviderService, SyncCommitteeValidator } from 'common/eth-providers'; -import { Epoch, Slot, StateId } from 'common/eth-providers/consensus-provider/types'; +import { BlockInfoResponse, ConsensusProviderService, SyncCommitteeValidator } from 'common/consensus-provider'; +import { Epoch, Slot, StateId } from 'common/consensus-provider/types'; import { PrometheusService, TrackTask } from 'common/prometheus'; +import { SummaryService } from 'duty/summary'; -import { SummaryService } from '../summary'; import { SYNC_COMMITTEE_SIZE } from './sync.constants'; @Injectable() diff --git a/src/duty/withdrawal/withdrawals.metrics.ts b/src/duty/withdrawal/withdrawals.metrics.ts index 9540546e..5ed5994b 100644 --- a/src/duty/withdrawal/withdrawals.metrics.ts +++ b/src/duty/withdrawal/withdrawals.metrics.ts @@ -2,11 +2,11 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { PrometheusService, TrackTask, setUserOperatorsMetric } from 'common/prometheus'; -import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; import { ClickhouseService } from 'storage/clickhouse'; +import { RegistryService, RegistrySourceOperator } from 'validators-registry'; enum WithdrawalType { Partial = 'partial', diff --git a/src/duty/withdrawal/withdrawals.module.ts b/src/duty/withdrawal/withdrawals.module.ts index beb7c56d..310f1cbb 100644 --- a/src/duty/withdrawal/withdrawals.module.ts +++ b/src/duty/withdrawal/withdrawals.module.ts @@ -1,15 +1,14 @@ import { Module } from '@nestjs/common'; -import { ConsensusProviderModule } from 'common/eth-providers'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { SummaryModule } from 'duty/summary'; import { ClickhouseModule } from 'storage/clickhouse'; -import { SummaryModule } from '../summary'; import { WithdrawalsMetrics } from './withdrawals.metrics'; import { WithdrawalsService } from './withdrawals.service'; @Module({ - imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], + imports: [ConsensusProviderModule, ClickhouseModule, SummaryModule], providers: [WithdrawalsService, WithdrawalsMetrics], exports: [WithdrawalsService, WithdrawalsMetrics], }) diff --git a/src/duty/withdrawal/withdrawals.service.ts b/src/duty/withdrawal/withdrawals.service.ts index aa8cabb6..0bb8690e 100644 --- a/src/duty/withdrawal/withdrawals.service.ts +++ b/src/duty/withdrawal/withdrawals.service.ts @@ -2,15 +2,14 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { BlockInfoResponse, ConsensusProviderService } from 'common/eth-providers'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { BlockInfoResponse, ConsensusProviderService } from 'common/consensus-provider'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { range } from 'common/functions/range'; import { PrometheusService, TrackTask } from 'common/prometheus'; -import { RegistryService } from 'common/validators-registry'; +import { SummaryService } from 'duty/summary'; import { ClickhouseService } from 'storage/clickhouse'; - -import { SummaryService } from '../summary'; +import { RegistryService } from 'validators-registry'; @Injectable() export class WithdrawalsService { diff --git a/src/inspector/inspector.module.ts b/src/inspector/inspector.module.ts index 2b278173..cdac10b9 100644 --- a/src/inspector/inspector.module.ts +++ b/src/inspector/inspector.module.ts @@ -1,16 +1,16 @@ import { Module } from '@nestjs/common'; import { CriticalAlertsModule } from 'common/alertmanager/critical-alerts.module'; -import { EthProvidersModule } from 'common/eth-providers'; -import { BlockCacheModule } from 'common/eth-providers/consensus-provider/block-cache'; -import { RegistryModule } from 'common/validators-registry'; +import { ConsensusProviderModule } from 'common/consensus-provider'; +import { BlockCacheModule } from 'common/consensus-provider/block-cache'; import { DutyModule } from 'duty'; import { ClickhouseModule } from 'storage/clickhouse'; +import { RegistryModule } from 'validators-registry'; import { InspectorService } from './inspector.service'; @Module({ - imports: [EthProvidersModule, BlockCacheModule, CriticalAlertsModule, ClickhouseModule, RegistryModule, DutyModule], + imports: [BlockCacheModule, CriticalAlertsModule, ClickhouseModule, RegistryModule, DutyModule, ConsensusProviderModule], providers: [InspectorService], exports: [InspectorService], }) diff --git a/src/inspector/inspector.service.ts b/src/inspector/inspector.service.ts index eaa61ed8..7968824f 100644 --- a/src/inspector/inspector.service.ts +++ b/src/inspector/inspector.service.ts @@ -3,9 +3,9 @@ import { Inject, Injectable, LoggerService, OnModuleInit } from '@nestjs/common' import { CriticalAlertsService } from 'common/alertmanager'; import { ConfigService } from 'common/config'; -import { BlockHeaderResponse, ConsensusProviderService } from 'common/eth-providers'; -import { BlockCacheService } from 'common/eth-providers/consensus-provider/block-cache'; -import { Slot } from 'common/eth-providers/consensus-provider/types'; +import { BlockHeaderResponse, ConsensusProviderService } from 'common/consensus-provider'; +import { BlockCacheService } from 'common/consensus-provider/block-cache'; +import { Slot } from 'common/consensus-provider/types'; import { sleep } from 'common/functions/sleep'; import { PrometheusService, TrackTask } from 'common/prometheus'; import { DutyMetrics, DutyService } from 'duty'; diff --git a/src/main.ts b/src/main.ts index 95876209..9e866329 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,8 +3,9 @@ import { VersioningType } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'; +import { ConfigService } from 'common/config'; + import { AppModule } from './app'; -import { ConfigService } from './common/config'; async function bootstrap() { const app = await NestFactory.create(AppModule, new FastifyAdapter({ trustProxy: true }), { bufferLogs: true }); diff --git a/src/storage/clickhouse/clickhouse.constants.ts b/src/storage/clickhouse/clickhouse.constants.ts index f8ae8422..1ca7e20b 100644 --- a/src/storage/clickhouse/clickhouse.constants.ts +++ b/src/storage/clickhouse/clickhouse.constants.ts @@ -1,5 +1,5 @@ -import { ValStatus } from 'common/eth-providers'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { ValStatus } from 'common/consensus-provider'; +import { Epoch } from 'common/consensus-provider/types'; export const avgValidatorBalanceDelta = (epoch: Epoch): string => ` SELECT diff --git a/src/storage/clickhouse/clickhouse.service.ts b/src/storage/clickhouse/clickhouse.service.ts index 8a9a1698..539a0b8d 100644 --- a/src/storage/clickhouse/clickhouse.service.ts +++ b/src/storage/clickhouse/clickhouse.service.ts @@ -5,7 +5,7 @@ import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { Inject, Injectable, LoggerService, OnModuleInit } from '@nestjs/common'; import { ConfigService } from 'common/config'; -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; import { allSettled } from 'common/functions/allSettled'; import { retrier } from 'common/functions/retrier'; import { unblock } from 'common/functions/unblock'; diff --git a/src/storage/clickhouse/clickhouse.types.ts b/src/storage/clickhouse/clickhouse.types.ts index e243546a..bbd51ccf 100644 --- a/src/storage/clickhouse/clickhouse.types.ts +++ b/src/storage/clickhouse/clickhouse.types.ts @@ -1,4 +1,4 @@ -import { Epoch } from 'common/eth-providers/consensus-provider/types'; +import { Epoch } from 'common/consensus-provider/types'; export interface ValidatorsStatusStats { val_nos_module_id?: string; diff --git a/src/common/validators-registry/file-source/file-source.module.ts b/src/validators-registry/file-source/file-source.module.ts similarity index 100% rename from src/common/validators-registry/file-source/file-source.module.ts rename to src/validators-registry/file-source/file-source.module.ts diff --git a/src/common/validators-registry/file-source/file-source.service.ts b/src/validators-registry/file-source/file-source.service.ts similarity index 100% rename from src/common/validators-registry/file-source/file-source.service.ts rename to src/validators-registry/file-source/file-source.service.ts diff --git a/src/common/validators-registry/file-source/index.ts b/src/validators-registry/file-source/index.ts similarity index 100% rename from src/common/validators-registry/file-source/index.ts rename to src/validators-registry/file-source/index.ts diff --git a/src/common/validators-registry/index.ts b/src/validators-registry/index.ts similarity index 100% rename from src/common/validators-registry/index.ts rename to src/validators-registry/index.ts diff --git a/src/common/validators-registry/keysapi-source/index.ts b/src/validators-registry/keysapi-source/index.ts similarity index 100% rename from src/common/validators-registry/keysapi-source/index.ts rename to src/validators-registry/keysapi-source/index.ts diff --git a/src/common/validators-registry/keysapi-source/keysapi-source.client.ts b/src/validators-registry/keysapi-source/keysapi-source.client.ts similarity index 98% rename from src/common/validators-registry/keysapi-source/keysapi-source.client.ts rename to src/validators-registry/keysapi-source/keysapi-source.client.ts index 5f43d7e7..2d7bb487 100644 --- a/src/common/validators-registry/keysapi-source/keysapi-source.client.ts +++ b/src/validators-registry/keysapi-source/keysapi-source.client.ts @@ -3,7 +3,7 @@ import { Inject, Injectable, LoggerService } from '@nestjs/common'; import { HTTPError, Response, got } from 'got-cjs'; import { ConfigService } from 'common/config'; -import { ResponseError, errCommon, errRequest } from 'common/eth-providers'; +import { ResponseError, errCommon, errRequest } from 'common/consensus-provider'; import { rejectDelay } from 'common/functions/rejectDelay'; import { retrier } from 'common/functions/retrier'; import { urljoin } from 'common/functions/urljoin'; diff --git a/src/common/validators-registry/keysapi-source/keysapi-source.module.ts b/src/validators-registry/keysapi-source/keysapi-source.module.ts similarity index 100% rename from src/common/validators-registry/keysapi-source/keysapi-source.module.ts rename to src/validators-registry/keysapi-source/keysapi-source.module.ts diff --git a/src/common/validators-registry/keysapi-source/keysapi-source.service.ts b/src/validators-registry/keysapi-source/keysapi-source.service.ts similarity index 98% rename from src/common/validators-registry/keysapi-source/keysapi-source.service.ts rename to src/validators-registry/keysapi-source/keysapi-source.service.ts index 0eeab04f..7a623620 100644 --- a/src/common/validators-registry/keysapi-source/keysapi-source.service.ts +++ b/src/validators-registry/keysapi-source/keysapi-source.service.ts @@ -5,7 +5,8 @@ import { pick } from 'stream-json/filters/Pick'; import { streamArray } from 'stream-json/streamers/StreamArray'; import { batch } from 'stream-json/utils/Batch'; -import { unblock } from '../../functions/unblock'; +import { unblock } from 'common/functions/unblock'; + import { RegistrySource, RegistrySourceKey, RegistrySourceOperator } from '../registry-source.interface'; import { KeysapiSourceClient } from './keysapi-source.client'; diff --git a/src/storage/database/database.module.ts b/src/validators-registry/lido-source/database/database.module.ts similarity index 100% rename from src/storage/database/database.module.ts rename to src/validators-registry/lido-source/database/database.module.ts diff --git a/src/storage/database/database.service.ts b/src/validators-registry/lido-source/database/database.service.ts similarity index 100% rename from src/storage/database/database.service.ts rename to src/validators-registry/lido-source/database/database.service.ts diff --git a/src/storage/database/index.ts b/src/validators-registry/lido-source/database/index.ts similarity index 100% rename from src/storage/database/index.ts rename to src/validators-registry/lido-source/database/index.ts diff --git a/src/common/validators-registry/lido-source/index.ts b/src/validators-registry/lido-source/index.ts similarity index 100% rename from src/common/validators-registry/lido-source/index.ts rename to src/validators-registry/lido-source/index.ts diff --git a/src/common/validators-registry/lido-source/lido-source.module.ts b/src/validators-registry/lido-source/lido-source.module.ts similarity index 72% rename from src/common/validators-registry/lido-source/lido-source.module.ts rename to src/validators-registry/lido-source/lido-source.module.ts index 8971d521..158fed4a 100644 --- a/src/common/validators-registry/lido-source/lido-source.module.ts +++ b/src/validators-registry/lido-source/lido-source.module.ts @@ -1,12 +1,15 @@ import { ValidatorRegistryModule } from '@lido-nestjs/registry'; import { Module } from '@nestjs/common'; -import { ExecutionProvider } from 'common/eth-providers'; +import { ExecutionProvider, ExecutionProviderModule } from 'common/execution-provider'; +import { DatabaseModule } from './database'; import { LidoSourceService } from './lido-source.service'; @Module({ imports: [ + DatabaseModule, + ExecutionProviderModule, ValidatorRegistryModule.forFeatureAsync({ async useFactory(provider: ExecutionProvider) { return { provider }; diff --git a/src/common/validators-registry/lido-source/lido-source.service.ts b/src/validators-registry/lido-source/lido-source.service.ts similarity index 97% rename from src/common/validators-registry/lido-source/lido-source.service.ts rename to src/validators-registry/lido-source/lido-source.service.ts index a1b6c896..def82684 100644 --- a/src/common/validators-registry/lido-source/lido-source.service.ts +++ b/src/validators-registry/lido-source/lido-source.service.ts @@ -7,7 +7,8 @@ import { } from '@lido-nestjs/registry'; import { Inject, Injectable } from '@nestjs/common'; -import { unblock } from '../../functions/unblock'; +import { unblock } from 'common/functions/unblock'; + import { RegistrySource, RegistrySourceKey, RegistrySourceOperator } from '../registry-source.interface'; @Injectable() diff --git a/src/common/validators-registry/registry-source.interface.ts b/src/validators-registry/registry-source.interface.ts similarity index 100% rename from src/common/validators-registry/registry-source.interface.ts rename to src/validators-registry/registry-source.interface.ts diff --git a/src/validators-registry/registry.module.ts b/src/validators-registry/registry.module.ts new file mode 100644 index 00000000..3bd9f401 --- /dev/null +++ b/src/validators-registry/registry.module.ts @@ -0,0 +1,65 @@ +import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; +import { Global, LoggerService, Module } from '@nestjs/common'; + +import { ValidatorRegistrySource } from 'common/config'; + +import { FileSourceModule, FileSourceService } from './file-source'; +import { KeysapiSourceModule, KeysapiSourceService } from './keysapi-source'; +import { LidoSourceModule, LidoSourceService } from './lido-source'; +import { REGISTRY_SOURCE, RegistrySource } from './registry-source.interface'; +import { RegistryService } from './registry.service'; + +const selectSource = () => { + switch (process.env['VALIDATOR_REGISTRY_SOURCE']) { + case ValidatorRegistrySource.Lido: + return { + imports: [LidoSourceModule], + providers: [ + RegistryService, + { + provide: REGISTRY_SOURCE, + useFactory: async (logger: LoggerService, lido: LidoSourceService): Promise => { + logger.warn('DEPRECATED: VALIDATOR_REGISTRY_SOURCE=lido. Use VALIDATOR_REGISTRY_SOURCE=keysapi instead'); + return lido; + }, + inject: [LOGGER_PROVIDER, LidoSourceService], + }, + ], + exports: [RegistryService], + }; + case ValidatorRegistrySource.File: + return { + imports: [FileSourceModule], + providers: [ + RegistryService, + { + provide: REGISTRY_SOURCE, + useFactory: async (file: FileSourceService): Promise => { + return file; + }, + inject: [FileSourceService], + }, + ], + exports: [RegistryService], + }; + case ValidatorRegistrySource.KeysAPI: + return { + imports: [KeysapiSourceModule], + providers: [ + RegistryService, + { + provide: REGISTRY_SOURCE, + useFactory: async (keysapi: KeysapiSourceService): Promise => { + return keysapi; + }, + inject: [KeysapiSourceService], + }, + ], + exports: [RegistryService], + }; + } +}; + +@Global() +@Module(selectSource()) +export class RegistryModule {} diff --git a/src/common/validators-registry/registry.service.ts b/src/validators-registry/registry.service.ts similarity index 100% rename from src/common/validators-registry/registry.service.ts rename to src/validators-registry/registry.service.ts diff --git a/test/duties.e2e-spec.ts b/test/duties.e2e-spec.ts index c7e9dfda..0f44529e 100644 --- a/test/duties.e2e-spec.ts +++ b/test/duties.e2e-spec.ts @@ -1,60 +1,17 @@ import * as process from 'process'; -import { getNetwork } from '@ethersproject/providers'; -import { createMock } from '@golevelup/ts-jest'; -import { FallbackProviderModule, SimpleFallbackJsonRpcBatchProvider } from '@lido-nestjs/execution'; import { LoggerModule, nullTransport } from '@lido-nestjs/logger'; -import { RegistryKeyRepository } from '@lido-nestjs/registry'; -import { EntityManager, MikroORM } from '@mikro-orm/core'; -import { SqlEntityManager } from '@mikro-orm/knex'; -import { MikroOrmModule } from '@mikro-orm/nestjs'; import { Test } from '@nestjs/testing'; -import { NonEmptyArray } from 'fp-ts/NonEmptyArray'; -import { ConfigModule, ConfigService } from 'common/config'; +import { ConfigModule } from 'common/config'; import { PrometheusModule } from 'common/prometheus/prometheus.module'; -import { RegistryService } from 'common/validators-registry'; import { ClickhouseService } from 'storage'; +import { RegistryModule, RegistryService } from 'validators-registry'; -import { ValStatus } from '../src/common/eth-providers'; +import { ValStatus } from '../src/common/consensus-provider'; import { allSettled } from '../src/common/functions/allSettled'; import { DutyModule, DutyService } from '../src/duty'; -const MikroORMMockProvider = { - provide: MikroORM, - useValue: createMock(), -}; - -const EntityManagerMockProvider = { - provide: EntityManager, - useFactory: jest.fn(() => ({ - flush: jest.fn(), - getRepository: jest.fn(), - })), -}; - -const SqlEntityManagerMockProvider = { - provide: SqlEntityManager, - useFactory: jest.fn(() => ({ - flush: jest.fn(), - getRepository: jest.fn(), - })), -}; - -const RegistryKeyRepositoryStub = { - global: true, // crucial for DI to work - module: RegistryKeyRepository, - providers: [EntityManagerMockProvider, SqlEntityManagerMockProvider], - exports: [EntityManagerMockProvider, SqlEntityManagerMockProvider], -}; - -const MikroORMStub = { - global: true, // crucial for DI to work - module: MikroOrmModule, - providers: [MikroORMMockProvider], - exports: [MikroORMMockProvider], -}; - const testSyncMember = { index: 285113, pubkey: '0x82750f01239832e15f0706f38cbbe35bed4cdfa4537391c14af00d8c2ae8dd695f1db09a1fbe81956ade016b245a2343', @@ -160,7 +117,6 @@ describe('Duties', () => { const getOperatorKeyMock = jest.fn().mockImplementation((key: string) => { return keysMap.get(key); }); - jest.spyOn(SimpleFallbackJsonRpcBatchProvider.prototype, 'detectNetwork').mockImplementation(async () => getNetwork('mainnet')); jest.spyOn(ClickhouseService.prototype, 'writeSummary'); beforeAll(async () => { @@ -169,20 +125,10 @@ describe('Duties', () => { LoggerModule.forRoot({ transports: [nullTransport()], }), - FallbackProviderModule.forRootAsync({ - async useFactory(configService: ConfigService) { - return { - urls: configService.get('EL_RPC_URLS') as NonEmptyArray, - network: configService.get('ETH_NETWORK'), - }; - }, - inject: [ConfigService], - }), ConfigModule, PrometheusModule, - MikroORMStub, - RegistryKeyRepositoryStub, DutyModule, + RegistryModule, ], }).compile(); diff --git a/test/jest-e2e.json b/test/jest-e2e.json index 41bc75cc..40c7cb5e 100644 --- a/test/jest-e2e.json +++ b/test/jest-e2e.json @@ -1,10 +1,7 @@ { "moduleFileExtensions": ["js", "json", "ts"], "rootDir": "..", - "moduleDirectories": [ - "node_modules", - "src" - ], + "moduleDirectories": ["node_modules", "src"], "moduleNameMapper": { "^build-info$": "/build-info.json" },