Skip to content

Commit

Permalink
fix: tune getAttestationCommittees (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko authored Mar 23, 2023
1 parent 1771600 commit 883ae85
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/duty/attestation/attestation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,27 @@ 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();
}
});
return new Promise((resolve, reject) => {
pipeline.on('data', (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)),
);
});
pipeline.on('error', (error) => reject(error));
pipeline.on('end', () => resolve(true));
}).finally(() => pipeline.destroy());
Expand Down

0 comments on commit 883ae85

Please sign in to comment.