-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from lidofinance/develop
Dev to main
- Loading branch information
Showing
17 changed files
with
221 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { Inject, LoggerService, Module, OnModuleInit } from '@nestjs/common'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
import { HealthController } from './health.controller'; | ||
import { ExecutionProviderHealthIndicator } from './execution-provider.indicator'; | ||
import { ConsensusProviderIndicator } from './consensus-provider.indicator'; | ||
import { GenesisTimeModule } from '../genesis-time'; | ||
import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; | ||
|
||
@Module({ | ||
providers: [ExecutionProviderHealthIndicator, ConsensusProviderIndicator], | ||
controllers: [HealthController], | ||
imports: [TerminusModule, GenesisTimeModule], | ||
}) | ||
export class HealthModule {} | ||
export class HealthModule implements OnModuleInit { | ||
constructor( | ||
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService, | ||
protected readonly consensusProviderIndicator: ConsensusProviderIndicator, | ||
protected readonly executionProviderIndicator: ExecutionProviderHealthIndicator, | ||
) {} | ||
|
||
async onModuleInit() { | ||
await this.startUpChecks(); | ||
} | ||
|
||
async startUpChecks() { | ||
try { | ||
await this.consensusProviderIndicator.isHealthy('consensusProvider'); | ||
await this.executionProviderIndicator.isHealthy('executionProvider'); | ||
this.logger.log(`Start up checks passed successfully`); | ||
} catch (e) { | ||
this.logger.error(`Start up checks failed with error: ${e}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
|
||
export function stringifyFrameBalances(frameBalances: Record<string, BigNumber>) { | ||
return JSON.stringify( | ||
Object.keys(frameBalances).reduce((acc, key) => { | ||
return { ...acc, [key]: frameBalances[key].toString() }; | ||
}, {}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './validators.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class ValidatorsDto { | ||
@ApiProperty({ | ||
example: 1658650005, | ||
description: 'ms time when data was last updated at', | ||
}) | ||
lastUpdatedAt: number; | ||
|
||
@ApiProperty({ | ||
example: 1724856617, | ||
description: 'max exit epoch over all CL network', | ||
}) | ||
maxExitEpoch: number; | ||
|
||
@ApiProperty({ | ||
example: '{}', | ||
description: 'sum of balances Lido validators with withdrawable_epoch by frame', | ||
}) | ||
frameBalances: Record<string, string>; | ||
|
||
@ApiProperty({ | ||
example: 100000, | ||
description: 'total number of validators in network', | ||
}) | ||
totalValidators: number; | ||
|
||
@ApiProperty({ | ||
example: 100000, | ||
description: 'current frame', | ||
}) | ||
currentFrame: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './validators.controller'; | ||
export * from './validators.module'; | ||
export * from './validators.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
ClassSerializerInterceptor, | ||
Controller, | ||
Get, | ||
HttpStatus, | ||
UseInterceptors, | ||
Version, | ||
CacheTTL, | ||
} from '@nestjs/common'; | ||
import { ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { HTTP_PATHS } from 'http/http.constants'; | ||
import { ValidatorsService } from './validators.service'; | ||
import { ValidatorsDto } from './dto'; | ||
|
||
@Controller() | ||
@ApiTags('Validators') | ||
@UseInterceptors(ClassSerializerInterceptor) | ||
export class ValidatorsController { | ||
constructor(protected readonly validatorsService: ValidatorsService) {} | ||
|
||
@Version('1') | ||
@Get(HTTP_PATHS[1]['validators-info']) | ||
@CacheTTL(20 * 1000) | ||
@ApiResponse({ status: HttpStatus.OK, type: ValidatorsDto }) | ||
async validatorsV1(): Promise<ValidatorsDto> { | ||
return this.validatorsService.getValidatorsInfo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from 'common/config'; | ||
import { ValidatorsController } from './validators.controller'; | ||
import { ValidatorsService } from './validators.service'; | ||
import { ValidatorsStorageModule } from '../../storage'; | ||
import { GenesisTimeModule } from '../../common/genesis-time'; | ||
|
||
@Module({ | ||
imports: [ConfigModule, ValidatorsStorageModule, GenesisTimeModule], | ||
controllers: [ValidatorsController], | ||
providers: [ValidatorsService], | ||
}) | ||
export class ValidatorsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from 'common/config'; | ||
import { ValidatorsStorageService } from '../../storage'; | ||
import { GenesisTimeService } from '../../common/genesis-time'; | ||
|
||
@Injectable() | ||
export class ValidatorsService { | ||
constructor( | ||
protected readonly configService: ConfigService, | ||
protected readonly validatorsServiceStorage: ValidatorsStorageService, | ||
protected readonly genesisTimeService: GenesisTimeService, | ||
) {} | ||
|
||
getValidatorsInfo() { | ||
const lastUpdatedAt = this.validatorsServiceStorage.getLastUpdate(); | ||
const maxExitEpoch = Number(this.validatorsServiceStorage.getMaxExitEpoch()); | ||
const frameBalancesBigNumber = this.validatorsServiceStorage.getFrameBalances(); | ||
const totalValidators = this.validatorsServiceStorage.getTotal(); | ||
const currentFrame = this.genesisTimeService.getFrameOfEpoch(this.genesisTimeService.getCurrentEpoch()); | ||
|
||
const frameBalances = Object.keys(frameBalancesBigNumber).reduce((acc, item) => { | ||
acc[item] = frameBalancesBigNumber[item].toString(); | ||
return acc; | ||
}, {} as Record<string, string>); | ||
|
||
return { | ||
lastUpdatedAt, | ||
maxExitEpoch, | ||
frameBalances, | ||
totalValidators, | ||
currentFrame, | ||
}; | ||
} | ||
} |
Oops, something went wrong.