From 0e8b55ee747dee4af340bbf109fce294b62f929a Mon Sep 17 00:00:00 2001 From: matthewkeil Date: Tue, 29 Oct 2024 11:12:56 +0700 Subject: [PATCH] feat: make aggregateWithRandomness async --- packages/beacon-node/src/chain/bls/multithread/index.ts | 2 +- packages/beacon-node/src/chain/bls/multithread/jobItem.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/src/chain/bls/multithread/index.ts b/packages/beacon-node/src/chain/bls/multithread/index.ts index cb18ca86e42f..fc8ea7534ad7 100644 --- a/packages/beacon-node/src/chain/bls/multithread/index.ts +++ b/packages/beacon-node/src/chain/bls/multithread/index.ts @@ -394,7 +394,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier { try { // Note: This can throw, must be handled per-job. // Pubkey and signature aggregation is defered here - workReq = jobItemWorkReq(job, this.metrics); + workReq = await jobItemWorkReq(job, this.metrics); } catch (e) { this.metrics?.blsThreadPool.errorAggregateSignatureSetsCount.inc({type: job.type}); diff --git a/packages/beacon-node/src/chain/bls/multithread/jobItem.ts b/packages/beacon-node/src/chain/bls/multithread/jobItem.ts index 035d56e56df2..b03e6b17a489 100644 --- a/packages/beacon-node/src/chain/bls/multithread/jobItem.ts +++ b/packages/beacon-node/src/chain/bls/multithread/jobItem.ts @@ -1,4 +1,4 @@ -import {PublicKey, aggregateWithRandomness} from "@chainsafe/blst"; +import {PublicKey, asyncAggregateWithRandomness} from "@chainsafe/blst"; import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition"; import {VerifySignatureOpts} from "../interface.js"; import {getAggregatedPubkey} from "../utils.js"; @@ -48,7 +48,7 @@ export function jobItemSigSets(job: JobQueueItem): number { * Prepare BlsWorkReq from JobQueueItem * WARNING: May throw with untrusted user input */ -export function jobItemWorkReq(job: JobQueueItem, metrics: Metrics | null): BlsWorkReq { +export async function jobItemWorkReq(job: JobQueueItem, metrics: Metrics | null): Promise { switch (job.type) { case JobQueueItemType.default: return { @@ -70,7 +70,7 @@ export function jobItemWorkReq(job: JobQueueItem, metrics: Metrics | null): BlsW // and not a problem in the near future // this is monitored on v1.21.0 https://github.com/ChainSafe/lodestar/pull/6894/files#r1687359225 const timer = metrics?.blsThreadPool.aggregateWithRandomnessMainThreadDuration.startTimer(); - const {pk, sig} = aggregateWithRandomness(job.sets.map((set) => ({pk: set.publicKey, sig: set.signature}))); + const {pk, sig} = await asyncAggregateWithRandomness(job.sets.map((set) => ({pk: set.publicKey, sig: set.signature}))); timer?.(); return {