diff --git a/src/common/registry/fetch/operator.fetch.ts b/src/common/registry/fetch/operator.fetch.ts index 72fcf4ed..21f22091 100644 --- a/src/common/registry/fetch/operator.fetch.ts +++ b/src/common/registry/fetch/operator.fetch.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Inject, Injectable } from '@nestjs/common'; +import { Inject, Injectable, LoggerService } from '@nestjs/common'; +import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; import { rangePromise } from '@lido-nestjs/utils'; import { REGISTRY_CONTRACT_TOKEN, Registry } from '@lido-nestjs/contracts'; import { CallOverrides } from './interfaces/overrides.interface'; @@ -8,7 +9,10 @@ import { REGISTRY_OPERATORS_BATCH_SIZE } from './operator.constants'; @Injectable() export class RegistryOperatorFetchService { - constructor(@Inject(REGISTRY_CONTRACT_TOKEN) private contract: Registry) {} + constructor( + @Inject(LOGGER_PROVIDER) protected logger: LoggerService, + @Inject(REGISTRY_CONTRACT_TOKEN) private contract: Registry, + ) {} private getContract(moduleAddress: string) { return this.contract.attach(moduleAddress); @@ -70,14 +74,28 @@ export class RegistryOperatorFetchService { return bigNumber.toNumber(); } - /** fetches finalized operator */ - public async getFinalizedNodeOperator(moduleAddress: string, operatorIndex: number) { + /** + * fetches finalized operator + * @param moduleAddress address of sr module + * @param operatorIndex index of sr module operator + * @returns used signing keys count, if error happened returns 0 (because of range error) + */ + public async getFinalizedNodeOperatorUsedSigningKeys(moduleAddress: string, operatorIndex: number): Promise { const fullInfo = true; const contract = this.getContract(moduleAddress); - const finalizedOperator = await contract.getNodeOperator(operatorIndex, fullInfo, { - blockTag: this.getFinalizedBlockTag(), - }); - return finalizedOperator; + try { + const { totalDepositedValidators } = await contract.getNodeOperator(3333, fullInfo, { + blockTag: this.getFinalizedBlockTag(), + }); + + return totalDepositedValidators.toNumber(); + } catch (error) { + this.logger.warn( + `an error occurred while trying to load the finalized state for operator ${operatorIndex} from module ${moduleAddress}`, + error, + ); + return 0; + } } /** fetches one operator */ @@ -101,10 +119,7 @@ export class RegistryOperatorFetchService { totalDepositedValidators, } = operator; - const { totalDepositedValidators: finalizedUsedSigningKeys } = await this.getFinalizedNodeOperator( - moduleAddress, - operatorIndex, - ); + const finalizedUsedSigningKeys = await this.getFinalizedNodeOperatorUsedSigningKeys(moduleAddress, operatorIndex); return { index: operatorIndex, @@ -116,7 +131,7 @@ export class RegistryOperatorFetchService { totalSigningKeys: totalAddedValidators.toNumber(), usedSigningKeys: totalDepositedValidators.toNumber(), moduleAddress, - finalizedUsedSigningKeys: finalizedUsedSigningKeys.toNumber(), + finalizedUsedSigningKeys, }; }