Skip to content

Commit

Permalink
chore: refactor to retryJobItemSameMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jul 19, 2023
1 parent 678f2db commit 589683a
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packages/beacon-node/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {chunkifyMaximizeChunkSize} from "./utils.js";
import {defaultPoolSize} from "./poolSize.js";
import {
JobQueueItem,
JobQueueItemSameMessage,
JobQueueItemType,
jobItemSameMessageToMultiSet,
jobItemSigSets,
Expand Down Expand Up @@ -394,16 +395,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
job.reject(e as Error);
} else {
// there could be an invalid pubkey/signature, retry each individually
// Create new jobs for each pubkey set, and Promise.all all the results
for (const j of jobItemSameMessageToMultiSet(job)) {
if (j.opts.priority) {
this.jobs.unshift(j);
} else {
this.jobs.push(j);
}
}
this.metrics?.blsThreadPool.sameMessageRetryJobs.inc(1);
this.metrics?.blsThreadPool.sameMessageRetrySets.inc(job.sets.length);
this.retryJobItemSameMessage(job);
}
continue;
}
Expand Down Expand Up @@ -465,16 +457,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
job.resolve(job.sets.map(() => true));
} else {
// Retry each individually
// Create new jobs for each pubkey set, and Promise.all all the results
for (const j of jobItemSameMessageToMultiSet(job)) {
if (j.opts.priority) {
this.jobs.unshift(j);
} else {
this.jobs.push(j);
}
}
this.metrics?.blsThreadPool.sameMessageRetryJobs.inc(1);
this.metrics?.blsThreadPool.sameMessageRetrySets.inc(job.sets.length);
this.retryJobItemSameMessage(job);
}
successCount += 1;
}
Expand Down Expand Up @@ -545,6 +528,19 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
}
};

private retryJobItemSameMessage(job: JobQueueItemSameMessage): void {
// Create new jobs for each pubkey set, and Promise.all all the results
for (const j of jobItemSameMessageToMultiSet(job)) {
if (j.opts.priority) {
this.jobs.unshift(j);
} else {
this.jobs.push(j);
}
}
this.metrics?.blsThreadPool.sameMessageRetryJobs.inc(1);
this.metrics?.blsThreadPool.sameMessageRetrySets.inc(job.sets.length);
}

/** For testing */
private async waitTillInitialized(): Promise<void> {
await Promise.all(
Expand Down

0 comments on commit 589683a

Please sign in to comment.