-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: withdrawals * fix: block without withdrawals * fix: metric * fix: queries * fix: import
- Loading branch information
1 parent
1d3f2d1
commit e724d06
Showing
16 changed files
with
562 additions
and
86 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
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
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,3 @@ | ||
export * from './withdrawals.module'; | ||
export * from './withdrawals.service'; | ||
export * from './withdrawals.metrics'; |
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,74 @@ | ||
import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; | ||
import { Inject, Injectable, LoggerService } from '@nestjs/common'; | ||
|
||
import { ConfigService } from 'common/config'; | ||
import { Epoch } from 'common/eth-providers/consensus-provider/types'; | ||
import { PrometheusService, TrackTask, setUserOperatorsMetric } from 'common/prometheus'; | ||
import { RegistryService, RegistrySourceOperator } from 'common/validators-registry'; | ||
import { ClickhouseService } from 'storage/clickhouse'; | ||
|
||
enum WithdrawalType { | ||
Partial = 'partial', | ||
Full = 'full', | ||
} | ||
|
||
@Injectable() | ||
export class WithdrawalsMetrics { | ||
protected processedEpoch: number; | ||
protected operators: RegistrySourceOperator[]; | ||
public constructor( | ||
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService, | ||
protected readonly config: ConfigService, | ||
protected readonly prometheus: PrometheusService, | ||
protected readonly registryService: RegistryService, | ||
protected readonly storage: ClickhouseService, | ||
) {} | ||
|
||
@TrackTask('calc-withdrawals-metrics') | ||
public async calculate(epoch: Epoch) { | ||
this.logger.log('Calculating withdrawals metrics'); | ||
this.processedEpoch = epoch; | ||
this.operators = this.registryService.getOperators(); | ||
await Promise.all([this.userNodeOperatorsWithdrawalsStats(), this.otherChainWithdrawalsStats()]); | ||
} | ||
|
||
private async userNodeOperatorsWithdrawalsStats() { | ||
const data = await this.storage.getUserNodeOperatorsWithdrawalsStats(this.processedEpoch); | ||
setUserOperatorsMetric( | ||
this.prometheus.operatorWithdrawalsSum, | ||
data, | ||
this.operators, | ||
{ type: WithdrawalType.Partial }, | ||
(item) => item.partial_withdrawn_sum, | ||
); | ||
setUserOperatorsMetric( | ||
this.prometheus.operatorWithdrawalsSum, | ||
data, | ||
this.operators, | ||
{ type: WithdrawalType.Full }, | ||
(item) => item.full_withdrawn_sum, | ||
); | ||
setUserOperatorsMetric( | ||
this.prometheus.operatorWithdrawalsCount, | ||
data, | ||
this.operators, | ||
{ type: WithdrawalType.Partial }, | ||
(item) => item.partial_withdrawn_count, | ||
); | ||
setUserOperatorsMetric( | ||
this.prometheus.operatorWithdrawalsCount, | ||
data, | ||
this.operators, | ||
{ type: WithdrawalType.Full }, | ||
(item) => item.full_withdrawn_count, | ||
); | ||
} | ||
|
||
private async otherChainWithdrawalsStats() { | ||
const result = await this.storage.getOtherChainWithdrawalsStats(this.processedEpoch); | ||
this.prometheus.otherChainWithdrawalsSum.set({ type: WithdrawalType.Partial }, result.partial_withdrawn_sum); | ||
this.prometheus.otherChainWithdrawalsSum.set({ type: WithdrawalType.Full }, result.full_withdrawn_sum); | ||
this.prometheus.otherChainWithdrawalsCount.set({ type: WithdrawalType.Partial }, result.partial_withdrawn_count); | ||
this.prometheus.otherChainWithdrawalsCount.set({ type: WithdrawalType.Full }, result.full_withdrawn_count); | ||
} | ||
} |
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,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { ConsensusProviderModule } from 'common/eth-providers'; | ||
import { RegistryModule } from 'common/validators-registry'; | ||
import { ClickhouseModule } from 'storage/clickhouse'; | ||
|
||
import { SummaryModule } from '../summary'; | ||
import { WithdrawalsMetrics } from './withdrawals.metrics'; | ||
import { WithdrawalsService } from './withdrawals.service'; | ||
|
||
@Module({ | ||
imports: [RegistryModule, ConsensusProviderModule, ClickhouseModule, SummaryModule], | ||
providers: [WithdrawalsService, WithdrawalsMetrics], | ||
exports: [WithdrawalsService, WithdrawalsMetrics], | ||
}) | ||
export class WithdrawalsModule {} |
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,45 @@ | ||
import { LOGGER_PROVIDER } from '@lido-nestjs/logger'; | ||
import { Inject, Injectable, LoggerService } from '@nestjs/common'; | ||
|
||
import { ConfigService } from 'common/config'; | ||
import { BlockInfoResponse, ConsensusProviderService } from 'common/eth-providers'; | ||
import { Epoch } from 'common/eth-providers/consensus-provider/types'; | ||
import { PrometheusService, TrackTask } from 'common/prometheus'; | ||
import { RegistryService } from 'common/validators-registry'; | ||
import { ClickhouseService } from 'storage/clickhouse'; | ||
|
||
import { range } from '../../common/functions/range'; | ||
import { SummaryService } from '../summary'; | ||
|
||
@Injectable() | ||
export class WithdrawalsService { | ||
public constructor( | ||
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService, | ||
protected readonly config: ConfigService, | ||
protected readonly prometheus: PrometheusService, | ||
protected readonly clClient: ConsensusProviderService, | ||
protected readonly summary: SummaryService, | ||
protected readonly storage: ClickhouseService, | ||
protected readonly registry: RegistryService, | ||
) {} | ||
|
||
@TrackTask('check-withdrawals') | ||
public async check(epoch: Epoch): Promise<void> { | ||
this.logger.log('Getting withdrawals for epoch'); | ||
const slotsInEpoch = this.config.get('FETCH_INTERVAL_SLOTS'); | ||
const firstSlotInEpoch = epoch * slotsInEpoch; | ||
const slots: number[] = range(firstSlotInEpoch, firstSlotInEpoch + slotsInEpoch); | ||
const toFetch = slots.map((s) => this.clClient.getBlockInfo(s)); | ||
const blocks = (await Promise.all(toFetch)).filter((b) => b != undefined) as BlockInfoResponse[]; | ||
for (const block of blocks) { | ||
const withdrawals = block.message.body.execution_payload.withdrawals ?? []; | ||
for (const withdrawal of withdrawals) { | ||
this.summary.epoch(epoch).set({ | ||
epoch, | ||
val_id: Number(withdrawal.validator_index), | ||
val_balance_withdrawn: BigInt(withdrawal.amount), | ||
}); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.