Skip to content

Commit

Permalink
fix: get rid of extra operator interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Amuhar committed Sep 7, 2023
1 parent fed3123 commit 2578341
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 95 deletions.
34 changes: 0 additions & 34 deletions src/http/common/entities/curated-operator.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/http/common/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export * from './sr-module';

// operators
export * from './operator';
export * from './curated-operator';

// query
export * from './module-id';
export * from './key-query';
3 changes: 1 addition & 2 deletions src/http/common/entities/key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
// import { SRModuleKey } from './sr-module-key';
import { RegistryKey } from 'common/registry';
import { RegistryKey } from '../../../common/registry';

// maybe Partial<RegistryKey> in future
export class Key implements RegistryKey {
Expand Down
38 changes: 34 additions & 4 deletions src/http/common/entities/operator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { RegistryOperator } from 'common/registry';

// TODO: when we get from storage this number of fields we get a narrowed operator
// maybe move to staking-module-service and here use in response type
export class Operator {
import { RegistryOperator } from '../../../common/registry';

export class Operator implements RegistryOperator {
constructor(operator: RegistryOperator) {
this.name = operator.name;
this.rewardAddress = operator.rewardAddress;
this.stakingLimit = operator.stakingLimit;
this.stoppedValidators = operator.stoppedValidators;
this.totalSigningKeys = operator.totalSigningKeys;
this.usedSigningKeys = operator.usedSigningKeys;
this.index = operator.index;
this.active = operator.active;
this.moduleAddress = operator.moduleAddress;
}

@ApiProperty({
Expand All @@ -18,4 +24,28 @@ export class Operator {
description: 'This value shows if node operator active',
})
active: boolean;

@ApiProperty({ description: 'Operator name' })
name: string;

@ApiProperty({ description: 'Ethereum 1 address which receives stETH rewards for this operator' })
rewardAddress: string;

@ApiProperty({ description: 'The maximum number of validators to stake for this operator' })
stakingLimit: number;

@ApiProperty({ description: 'Amount of stopped validators' })
stoppedValidators: number;

@ApiProperty({ description: 'Total signing keys amount' })
totalSigningKeys: number;

@ApiProperty({ description: 'Amount of used signing keys' })
usedSigningKeys: number;

@ApiProperty({
required: true,
description: 'Module address',
})
moduleAddress: string;
}
4 changes: 0 additions & 4 deletions src/http/common/entities/sr-module-operator.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import { ApiProperty, getSchemaPath, ApiExtraModels } from '@nestjs/swagger';
import { SRModule } from 'http/common/entities/';
import { CuratedKey } from 'http/common/entities/';
import { CuratedOperator } from 'http/common/entities/';
import { Key, Operator, SRModule } from 'http/common/entities/';
import { ELMeta } from 'http/common/entities/';

type SRModuleOperator = CuratedOperator;
type SRModuleKey = CuratedKey;

@ApiExtraModels(CuratedOperator)
@ApiExtraModels(CuratedKey)
@ApiExtraModels(Operator)
@ApiExtraModels(Key)
export class SROperatorsKeysModule {
@ApiProperty({
type: 'array',
items: { oneOf: [{ $ref: getSchemaPath(CuratedOperator) }] },
items: { oneOf: [{ $ref: getSchemaPath(Operator) }] },
description: 'Operators of staking router module',
})
operators!: SRModuleOperator[];
operators!: Operator[];

@ApiProperty({
type: 'array',
items: { oneOf: [{ $ref: getSchemaPath(CuratedKey) }] },
items: { oneOf: [{ $ref: getSchemaPath(Key) }] },
description: 'Keys of staking router module',
})
keys!: SRModuleKey[];
keys!: Key[];

@ApiProperty({
description: 'Detailed Staking Router information',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Inject, Injectable, LoggerService } from '@nestjs/common';
import { ELBlockSnapshot, Key, ModuleId, SRModule } from 'http/common/entities';
import { ELBlockSnapshot, Key, ModuleId, Operator, SRModule } from 'http/common/entities';
import { KeyQuery } from 'http/common/entities';
import { ConfigService } from 'common/config';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { StakingRouterService } from 'staking-router-modules/staking-router.service';
import { KeyEntity, OperatorEntity } from 'staking-router-modules/interfaces/staking-module.interface';
import { EntityManager } from '@mikro-orm/knex';

@Injectable()
Expand All @@ -20,8 +19,8 @@ export class SRModulesOperatorsKeysService {
moduleId: ModuleId,
filters: KeyQuery,
): Promise<{
keysGenerator: AsyncGenerator<KeyEntity>;
operators: OperatorEntity[];
keysGenerator: AsyncGenerator<Key>;
operators: Operator[];
module: SRModule;
meta: { elBlockSnapshot: ELBlockSnapshot };
}> {
Expand All @@ -31,7 +30,7 @@ export class SRModulesOperatorsKeysService {

const keysGenerator: AsyncGenerator<Key> = await moduleInstance.getKeysStream(module.stakingModuleAddress, filters);
const operatorsFilter = filters.operatorIndex ? { index: filters.operatorIndex } : {};
const operators: OperatorEntity[] = await moduleInstance.getOperators(module.stakingModuleAddress, operatorsFilter);
const operators: Operator[] = await moduleInstance.getOperators(module.stakingModuleAddress, operatorsFilter);

return { operators, keysGenerator, module, meta: { elBlockSnapshot } };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ApiProperty, getSchemaPath, ApiExtraModels } from '@nestjs/swagger';
import { SRModule, CuratedOperator, ELMeta } from '../../common/entities/';
import { SRModuleOperator } from '../../common/entities/sr-module-operator';
import { SRModule, ELMeta, Operator } from '../../common/entities/';

@ApiExtraModels(CuratedOperator)
@ApiExtraModels(Operator)
export class OperatorAndSRModule {
@ApiProperty({
oneOf: [{ $ref: getSchemaPath(CuratedOperator) }],
oneOf: [{ $ref: getSchemaPath(Operator) }],
description: 'Operator of staking router module',
})
operator!: SRModuleOperator;
operator!: Operator;

@ApiProperty({
description: 'Detailed Staking Router information',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { ApiProperty, getSchemaPath, ApiExtraModels } from '@nestjs/swagger';
import { SRModule, CuratedOperator, ELMeta } from '../../common/entities/';
import { SRModuleOperator } from '../../common/entities/sr-module-operator';
import { SRModule, ELMeta, Operator } from '../../common/entities/';

@ApiExtraModels(CuratedOperator)
@ApiExtraModels(Operator)
export class OperatorListAndSRModule {
@ApiProperty({
type: 'array',
items: { oneOf: [{ $ref: getSchemaPath(CuratedOperator) }] },
items: { oneOf: [{ $ref: getSchemaPath(Operator) }] },
description: 'Operators of staking router module',
})
operators!: SRModuleOperator[];
operators!: Operator[];

@ApiProperty({
description: 'Detailed Staking Router information',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
SRModuleOperatorListResponse,
SRModuleOperatorResponse,
} from './entities';
import { ModuleId } from 'http/common/entities/';
import { ModuleId } from '../common/entities/';
import { SRModulesOperatorsService } from './sr-modules-operators.service';
import { OperatorIdParam } from 'http/common/entities/operator-id-param';
import { TooEarlyResponse } from 'http/common/entities/http-exceptions';
import { OperatorIdParam } from '../common/entities/operator-id-param';
import { TooEarlyResponse } from '../common/entities/http-exceptions';

@Controller('/')
@ApiTags('operators')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from 'common/logger';
import { LoggerModule } from '../../common/logger';
import { SRModulesOperatorsController } from './sr-modules-operators.controller';
import { SRModulesOperatorsService } from './sr-modules-operators.service';

Expand Down
20 changes: 7 additions & 13 deletions src/http/sr-modules-operators/sr-modules-operators.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Inject, Injectable, LoggerService, NotFoundException } from '@nestjs/common';
import { ConfigService } from 'common/config';
import { ModuleId, SRModule } from 'http/common/entities/';
import { ConfigService } from '../../common/config';
import { ModuleId, Operator, SRModule } from '../common/entities/';
import {
GroupedByModuleOperatorListResponse,
SRModuleOperatorListResponse,
SRModuleOperatorResponse,
} from './entities';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { StakingRouterService } from 'staking-router-modules/staking-router.service';
import { StakingRouterService } from '../../staking-router-modules/staking-router.service';
import { EntityManager } from '@mikro-orm/knex';
import { OperatorEntity } from 'staking-router-modules/interfaces/staking-module.interface';
import { IsolationLevel } from '@mikro-orm/core';

@Injectable()
Expand All @@ -25,13 +24,11 @@ export class SRModulesOperatorsService {
const { operatorsByModules, elBlockSnapshot } = await this.entityManager.transactional(
async () => {
const { stakingModules, elBlockSnapshot } = await this.stakingRouterService.getStakingModulesAndMeta();
// TODO: have in http/entities/curated-operator
const operatorsByModules: { operators: OperatorEntity[]; module: SRModule }[] = [];
const operatorsByModules: { operators: Operator[]; module: SRModule }[] = [];

for (const module of stakingModules) {
const moduleInstance = this.stakingRouterService.getStakingRouterModuleImpl(module.type);
// /v1/operators return these common fields for all modules
const operators: OperatorEntity[] = await moduleInstance.getOperators(module.stakingModuleAddress, {});
const operators: Operator[] = await moduleInstance.getOperators(module.stakingModuleAddress, {});

operatorsByModules.push({ operators, module: new SRModule(module) });
}
Expand All @@ -52,7 +49,7 @@ export class SRModulesOperatorsService {
const moduleInstance = this.stakingRouterService.getStakingRouterModuleImpl(module.type);

// /v1/operators return these common fields for all modules
const operators: OperatorEntity[] = await moduleInstance.getOperators(module.stakingModuleAddress, {});
const operators: Operator[] = await moduleInstance.getOperators(module.stakingModuleAddress, {});

return { operators, module, elBlockSnapshot };
},
Expand All @@ -73,10 +70,7 @@ export class SRModulesOperatorsService {
const { module, elBlockSnapshot } = await this.stakingRouterService.getStakingModuleAndMeta(moduleId);
const moduleInstance = this.stakingRouterService.getStakingRouterModuleImpl(module.type);

const operator: OperatorEntity | null = await moduleInstance.getOperator(
module.stakingModuleAddress,
operatorIndex,
);
const operator: Operator | null = await moduleInstance.getOperator(module.stakingModuleAddress, operatorIndex);

return { operator, module, elBlockSnapshot };
},
Expand Down
1 change: 0 additions & 1 deletion src/jobs/keys-update/keys-update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export class KeysUpdateService {

if (prevElMeta && prevElMeta?.blockNumber > currElMeta.number) {
this.logger.warn('Previous data is newer than current data', prevElMeta);
console.log('curr', currElMeta);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface StakingModule {
active: boolean;
}

export type OperatorEntity = RegistryOperator;

export interface StakingModuleInterface {
update(moduleAddress: string, blockHash: string): Promise<void>;

Expand All @@ -43,9 +41,9 @@ export interface StakingModuleInterface {

getKeysByPubkey(moduleAddress: string, pubkey: string): Promise<RegistryKey[]>;

getOperators(moduleAddress: string, filters?: OperatorsFilter): Promise<OperatorEntity[]>;
getOperators(moduleAddress: string, filters?: OperatorsFilter): Promise<RegistryOperator[]>;

getOperator(moduleAddress: string, index: number): Promise<OperatorEntity | null>;
getOperator(moduleAddress: string, index: number): Promise<RegistryOperator | null>;

getCurrentNonce(moduleAddress: string, blockHash: string): Promise<number>;
}

0 comments on commit 2578341

Please sign in to comment.