Skip to content

Commit

Permalink
Support changing Effective Balance by config.
Browse files Browse the repository at this point in the history
  • Loading branch information
rootwarp committed Dec 12, 2023
1 parent fcd53a3 commit 93d6c15
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ CL_API_URLS=https://<consensus-layer-api-url>
# 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
Expand Down
1 change: 1 addition & 0 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
8 changes: 8 additions & 0 deletions src/common/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>) {
Expand Down
8 changes: 5 additions & 3 deletions src/duty/attestation/attestation.rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 93d6c15

Please sign in to comment.