From 93d6c15df33ec0959607f115912f22e231cefaed Mon Sep 17 00:00:00 2001 From: Joonkyo Kim Date: Tue, 12 Dec 2023 07:36:40 +0000 Subject: [PATCH 1/2] Support changing Effective Balance by config. --- .env.example | 3 +++ src/app/app.service.ts | 1 + src/common/config/env.validation.ts | 8 ++++++++ src/duty/attestation/attestation.rewards.ts | 8 +++++--- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index e91e20cc..4910ba07 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,9 @@ CL_API_URLS=https:// # Validator registry source will be "lido" or "file" (optional). VALIDATOR_REGISTRY_SOURCE=lido +# Effective Balance is 32 by default. +# EFFECTIVE_BALANCE=32 + # Critical alerts (optional). # CRITICAL_ALERTS_ALERTMANAGER_URL=http://alertmanager:9093 # CRITICAL_ALERTS_MIN_VAL_COUNT=1 diff --git a/src/app/app.service.ts b/src/app/app.service.ts index 54bd0bc1..c4a81e28 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -30,6 +30,7 @@ export class AppService implements OnModuleInit, OnApplicationBootstrap { this.logger.log(`DRY RUN ${this.configService.get('DRY_RUN') ? 'enabled' : 'disabled'}`); this.logger.log(`Slot time: ${this.configService.get('CHAIN_SLOT_TIME_SECONDS')} seconds`); this.logger.log(`Epoch size: ${this.configService.get('FETCH_INTERVAL_SLOTS')} slots`); + this.logger.log(`Effective Balance: ${this.configService.get('EFFECTIVE_BALANCE')} ETH`); } public async onApplicationBootstrap(): Promise { diff --git a/src/common/config/env.validation.ts b/src/common/config/env.validation.ts index b3eb83cc..6d24a28a 100644 --- a/src/common/config/env.validation.ts +++ b/src/common/config/env.validation.ts @@ -277,6 +277,14 @@ export class EnvironmentVariables { @IsEnum(WorkingMode) public WORKING_MODE = WorkingMode.Finalized; + + /** + * Effective balance. + */ + @IsNumber() + @Min(32) + @Transform(({ value }) => parseInt(value, 10), { toClassOnly: true }) + public EFFECTIVE_BALANCE = 32; } export function validate(config: Record) { diff --git a/src/duty/attestation/attestation.rewards.ts b/src/duty/attestation/attestation.rewards.ts index 3e079477..287ab4c7 100644 --- a/src/duty/attestation/attestation.rewards.ts +++ b/src/duty/attestation/attestation.rewards.ts @@ -38,11 +38,13 @@ export class AttestationRewards { .toString(), ); // Perfect attestation (with multipliers). Need for calculating missed reward + const effectiveBalance = this.config.get('EFFECTIVE_BALANCE'); + const perfect = getRewards({ source: true, target: true, head: true }); const perfectAttestationRewards = - Math.trunc(perfect.source * epochMeta.state.base_reward * 32 * sourceParticipation) + - Math.trunc(perfect.target * epochMeta.state.base_reward * 32 * targetParticipation) + - Math.trunc(perfect.head * epochMeta.state.base_reward * 32 * headParticipation); + Math.trunc(perfect.source * epochMeta.state.base_reward * effectiveBalance * sourceParticipation) + + Math.trunc(perfect.target * epochMeta.state.base_reward * effectiveBalance * targetParticipation) + + Math.trunc(perfect.head * epochMeta.state.base_reward * effectiveBalance * headParticipation); const maxBatchSize = 1000; let index = 0; for (const v of this.summary.epoch(epoch).values()) { From 173055b7f2d8d4f3ff19b6992fb0d2e479fb6c45 Mon Sep 17 00:00:00 2001 From: Joonkyo Kim Date: Wed, 13 Dec 2023 06:15:33 +0000 Subject: [PATCH 2/2] Change env name of Effective balance --- .env.example | 2 +- src/app/app.service.ts | 2 +- src/common/config/env.validation.ts | 2 +- src/duty/attestation/attestation.rewards.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 4910ba07..780a567b 100644 --- a/.env.example +++ b/.env.example @@ -30,7 +30,7 @@ CL_API_URLS=https:// VALIDATOR_REGISTRY_SOURCE=lido # Effective Balance is 32 by default. -# EFFECTIVE_BALANCE=32 +# EFFECTIVE_BALANCE_INCREMENTS=32 # Critical alerts (optional). # CRITICAL_ALERTS_ALERTMANAGER_URL=http://alertmanager:9093 diff --git a/src/app/app.service.ts b/src/app/app.service.ts index c4a81e28..254740e3 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -30,7 +30,7 @@ export class AppService implements OnModuleInit, OnApplicationBootstrap { this.logger.log(`DRY RUN ${this.configService.get('DRY_RUN') ? 'enabled' : 'disabled'}`); this.logger.log(`Slot time: ${this.configService.get('CHAIN_SLOT_TIME_SECONDS')} seconds`); this.logger.log(`Epoch size: ${this.configService.get('FETCH_INTERVAL_SLOTS')} slots`); - this.logger.log(`Effective Balance: ${this.configService.get('EFFECTIVE_BALANCE')} ETH`); + this.logger.log(`Effective Balance: ${this.configService.get('EFFECTIVE_BALANCE_INCREMENTS')} ETH`); } public async onApplicationBootstrap(): Promise { diff --git a/src/common/config/env.validation.ts b/src/common/config/env.validation.ts index 6d24a28a..14faf59b 100644 --- a/src/common/config/env.validation.ts +++ b/src/common/config/env.validation.ts @@ -284,7 +284,7 @@ export class EnvironmentVariables { @IsNumber() @Min(32) @Transform(({ value }) => parseInt(value, 10), { toClassOnly: true }) - public EFFECTIVE_BALANCE = 32; + public EFFECTIVE_BALANCE_INCREMENTS = 32; } export function validate(config: Record) { diff --git a/src/duty/attestation/attestation.rewards.ts b/src/duty/attestation/attestation.rewards.ts index 287ab4c7..0d59de85 100644 --- a/src/duty/attestation/attestation.rewards.ts +++ b/src/duty/attestation/attestation.rewards.ts @@ -38,7 +38,7 @@ export class AttestationRewards { .toString(), ); // Perfect attestation (with multipliers). Need for calculating missed reward - const effectiveBalance = this.config.get('EFFECTIVE_BALANCE'); + const effectiveBalance = this.config.get('EFFECTIVE_BALANCE_INCREMENTS'); const perfect = getRewards({ source: true, target: true, head: true }); const perfectAttestationRewards =