Skip to content

Commit

Permalink
fix: VAL-606/out-of-range-error
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Jan 31, 2024
1 parent 999bcf4 commit f334f19
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/common/registry/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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<number> {
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 */
Expand All @@ -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,
Expand All @@ -116,7 +131,7 @@ export class RegistryOperatorFetchService {
totalSigningKeys: totalAddedValidators.toNumber(),
usedSigningKeys: totalDepositedValidators.toNumber(),
moduleAddress,
finalizedUsedSigningKeys: finalizedUsedSigningKeys.toNumber(),
finalizedUsedSigningKeys,
};
}

Expand Down

0 comments on commit f334f19

Please sign in to comment.