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

fix: tune chunks size #142

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 16 additions & 17 deletions src/duty/attestation/attestation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { chain } from 'stream-chain';
import { parser } from 'stream-json';
import { pick } from 'stream-json/filters/Pick';
import { streamArray } from 'stream-json/streamers/StreamArray';
import { batch } from 'stream-json/utils/Batch';

import { ConfigService } from 'common/config';
import { ConsensusProviderService } from 'common/eth-providers';
import { AttestationCommitteeInfo, ConsensusProviderService } from 'common/eth-providers';
import { Epoch, Slot } from 'common/eth-providers/consensus-provider/types';
import { allSettled } from 'common/functions/allSettled';
import { range } from 'common/functions/range';
Expand Down Expand Up @@ -53,7 +54,7 @@ export class AttestationService {
this.logger.log(`Getting attestation duties info`);
const committees = await this.getAttestationCommittees(stateSlot);
this.logger.log(`Processing attestation duty info`);
const maxBatchSize = 1000;
const maxBatchSize = 5;
let index = 0;
for (const attestation of attestations) {
// Each attestation corresponds to committee. Committee may have several aggregate attestations
Expand Down Expand Up @@ -163,25 +164,23 @@ export class AttestationService {

@TrackTask('get-attestation-committees')
protected async getAttestationCommittees(stateSlot: Slot): Promise<Map<string, number[]>> {
const maxBatchSize = 1000;
let index = 0;
const committees = new Map<string, number[]>();
const processCommittees = async (epoch: Epoch) => {
const stream = await this.clClient.getAttestationCommitteesInfo(stateSlot, epoch);
const pipeline = chain([stream, parser(), pick({ filter: 'data' }), streamArray(), (data) => data.value]);
pipeline.on('data', async (committee) => {
// validator doesn't attests by default
committee.validators.forEach((index) =>
this.summary.epoch(epoch).set({ epoch: epoch, val_id: Number(index), att_happened: false }),
);
committees.set(
`${committee.index}_${committee.slot}`,
committee.validators.map((v) => Number(v)),
);
index++;
if (index % maxBatchSize == 0) {
await unblock();
const pipeline = chain([stream, parser(), pick({ filter: 'data' }), streamArray(), batch({ batchSize: 5 })]);
pipeline.on('data', async (batch) => {
for (const data of batch) {
const committee: AttestationCommitteeInfo = data.value;
// validator doesn't attests by default
committee.validators.forEach((index) =>
this.summary.epoch(epoch).set({ epoch: epoch, val_id: Number(index), att_happened: false }),
);
committees.set(
`${committee.index}_${committee.slot}`,
committee.validators.map((v) => Number(v)),
);
}
await unblock();
});
return new Promise((resolve, reject) => {
pipeline.on('error', (error) => reject(error));
Expand Down
7 changes: 1 addition & 6 deletions src/duty/duty.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ export class DutyService {
@TrackTask('fill-prop-reward-epoch-metadata')
protected async fillProposalRewardsMetadata(epoch: Epoch): Promise<any> {
const meta = this.summary.epoch(epoch).getMeta();
const maxBatchSize = 1000;
let index = 0;
for (const [block, attestations] of meta.attestation.blocks_attestations.entries()) {
// There is only one right way to calculate proposal reward - calculate it from each aggregated attestation
// And attestation flag should be included for the first time. `AttestationService.processAttestation` is responsible for this
Expand All @@ -178,10 +176,7 @@ export class DutyService {
}
rewards = Math.floor(proposerAttPartReward(rewards));
meta.attestation.blocks_rewards.set(block, meta.attestation.blocks_rewards.get(block) + BigInt(rewards));
index++;
if (index % maxBatchSize == 0) {
await unblock();
}
await unblock();
}
}
this.summary.epoch(epoch).setMeta(meta);
Expand Down