Skip to content

Commit

Permalink
feat: add finalizedUsedSigningKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Dec 18, 2023
1 parent 1fdc99a commit d5247d5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/common/registry/fetch/interfaces/operator.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface RegistryOperator {
totalSigningKeys: number;
usedSigningKeys: number;
moduleAddress: string;
finalizedUsedSigningKeys: number;
}
6 changes: 6 additions & 0 deletions src/common/registry/fetch/operator.fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export class RegistryOperatorFetchService {
): Promise<RegistryOperator> {
const fullInfo = true;
const operator = await this.getContract(moduleAddress).getNodeOperator(operatorIndex, fullInfo, overrides as any);
const finalizedOperator = await this.getContract(moduleAddress).getNodeOperator(operatorIndex, fullInfo, {
blockTag: 'finalized',
});

const {
name,
Expand All @@ -84,6 +87,8 @@ export class RegistryOperatorFetchService {
totalDepositedValidators,
} = operator;

const { totalDepositedValidators: finalizedUsedSigningKeys } = finalizedOperator;

return {
index: operatorIndex,
active,
Expand All @@ -94,6 +99,7 @@ export class RegistryOperatorFetchService {
totalSigningKeys: totalAddedValidators.toNumber(),
usedSigningKeys: totalDepositedValidators.toNumber(),
moduleAddress,
finalizedUsedSigningKeys: finalizedUsedSigningKeys.toNumber(),
};
}

Expand Down
39 changes: 36 additions & 3 deletions src/common/registry/main/abstract-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { RegistryOperator } from '../storage/operator.entity';

import { compareOperators } from '../utils/operator.utils';

import { REGISTRY_GLOBAL_OPTIONS_TOKEN } from './constants';
import { BLOCKS_OVERLAP, REGISTRY_GLOBAL_OPTIONS_TOKEN } from './constants';
import { RegistryOptions } from './interfaces/module.interface';
import { chunk } from '@lido-nestjs/utils';
import { RegistryKeyBatchFetchService } from '../fetch/key-batch.fetch';
Expand Down Expand Up @@ -71,10 +71,42 @@ export abstract class AbstractRegistryService {
* @returns Check if operators have been changed
*/
public async operatorsWereChanged(
moduleAddress: string,
{
fromBlockNumber,
toBlockNumber,
}: {
fromBlockNumber?: number;
toBlockNumber: number;
},
): Promise<boolean> {
if (fromBlockNumber === undefined) return true;

if (fromBlockNumber > toBlockNumber) {
throw new Error(`invalid blocks range: ${fromBlockNumber} (fromBlockNumber) > ${toBlockNumber} (toBlockNumber)`);
}
// check how big the difference between the blocks is, if it exceeds, we should update the state anyway
if (toBlockNumber - fromBlockNumber > BLOCKS_OVERLAP) return true;

return await this.operatorFetch.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber);
}

/**
*
* @param moduleAddress contract address
* @returns Check if operators have been changed
*/
public async keysWereChanged(
moduleAddress: string,
fromBlockNumber: number,
toBlockNumber: number,
): Promise<boolean> {
if (fromBlockNumber > toBlockNumber) {
throw new Error(`invalid blocks range: ${fromBlockNumber} (fromBlockNumber) > ${toBlockNumber} (toBlockNumber)`);
}
// check how big the difference between the blocks is, if it exceeds, we should update the state anyway
if (toBlockNumber - fromBlockNumber > BLOCKS_OVERLAP) return true;

return await this.operatorFetch.operatorsWereChanged(moduleAddress, fromBlockNumber, toBlockNumber);
}

Expand Down Expand Up @@ -110,7 +142,8 @@ export abstract class AbstractRegistryService {

// skip updating keys from 0 to `usedSigningKeys` of previous collected data
// since the contract guarantees that these keys cannot be changed
const unchangedKeysMaxIndex = isSameOperator ? prevOperator.usedSigningKeys : 0;
const unchangedKeysMaxIndex =
isSameOperator && prevOperator.finalizedUsedSigningKeys ? prevOperator.finalizedUsedSigningKeys : 0;
// get the right border up to which the keys should be updated
// it's different for different scenarios
const toIndex = this.getToIndex(currOperator);
Expand All @@ -121,7 +154,7 @@ export abstract class AbstractRegistryService {

const operatorIndex = currOperator.index;
const overrides = { blockTag: { blockHash } };
// TODO: use feature flag

const result = await this.keyBatchFetch.fetch(moduleAddress, operatorIndex, fromIndex, toIndex, overrides);

const operatorKeys = result.filter((key) => key);
Expand Down

0 comments on commit d5247d5

Please sign in to comment.