Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support changing Effective Balance by config. #227

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion!

I would say it is

Suggested change
# EFFECTIVE_BALANCE=32
# EFFECTIVE_BALANCE_INCREMENTS=32

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgorkavenko thanks for reviewing this PR and I agree with that.
The new commit 93d6c15 pushed for applying your comment :)


# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a few words about the purpose. For example, it's used for ...

*/
@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