Skip to content

Commit

Permalink
Revert "fix: revert napi bls (#6853)"
Browse files Browse the repository at this point in the history
This reverts commit cbb8946.
  • Loading branch information
matthewkeil committed Jun 20, 2024
1 parent a122876 commit 36be944
Show file tree
Hide file tree
Showing 114 changed files with 765 additions and 821 deletions.
1 change: 1 addition & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ orchestrator
osx
overriden
params
peerDependency
pid
plaintext
pre
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"test-coverage:e2e": "c8 --config .c8rc.json --report-dir coverage/e2e/ --all npm run test:e2e",
"test-coverage:e2e-sim": "c8 --config .c8rc.json --report-dir coverage/e2e-sim/ --all npm run test:e2e:sim",
"test-coverage:spec": "c8 --config .c8rc.json --report-dir coverage/spec/ --all npm run test:spec",
"benchmark": "yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
"benchmark:files": "NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable",
"benchmark": "UV_THREADPOOL_SIZE=$(node -e 'console.log(require(`os`).availableParallelism())') yarn benchmark:files 'packages/*/test/perf/**/*.test.ts'",
"benchmark:files": "UV_THREADPOOL_SIZE=$(node -e 'console.log(require(`os`).availableParallelism())') NODE_OPTIONS='--max-old-space-size=4096 --loader=ts-node/esm' benchmark --config .benchrc.yaml --defaultBranch unstable",
"release:create-rc": "node scripts/release/create_rc.mjs",
"release:tag-rc": "node scripts/release/tag_rc.mjs",
"release:tag-stable": "node scripts/release/tag_stable.mjs",
Expand Down
3 changes: 1 addition & 2 deletions packages/beacon-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@
},
"dependencies": {
"@chainsafe/as-sha256": "^0.4.1",
"@chainsafe/bls": "7.1.3",
"@chainsafe/blst": "^0.2.11",
"@chainsafe/blst": "^1.0.1",
"@chainsafe/discv5": "^9.0.0",
"@chainsafe/enr": "^3.0.0",
"@chainsafe/libp2p-gossipsub": "^13.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/beacon-node/src/chain/bls/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type {IBlsVerifier} from "./interface.js";
export type {BlsMultiThreadWorkerPoolModules, JobQueueItemType} from "./multithread/index.js";
export {BlsMultiThreadWorkerPool} from "./multithread/index.js";
export type {JobQueueItemType} from "./jobItem.js";
export type {BlsMultiThreadWorkerPoolModules} from "./multiThread.js";
export {BlsMultiThreadWorkerPool} from "./multiThread.js";
export {BlsSingleThreadVerifier} from "./singleThread.js";
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/bls/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PublicKey} from "@chainsafe/bls/types";
import {PublicKey} from "@chainsafe/blst";
import {ISignatureSet} from "@lodestar/state-transition";

export type VerifySignatureOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import bls from "@chainsafe/bls";
import {CoordType, PointFormat, PublicKey} from "@chainsafe/bls/types";
import {PublicKey, aggregatePublicKeys, aggregateSignatures, randomBytesNonZero} from "@chainsafe/blst";
import {signatureFromBytes} from "@lodestar/utils";
import {ISignatureSet, SignatureSetType} from "@lodestar/state-transition";
import {VerifySignatureOpts} from "../interface.js";
import {getAggregatedPubkey} from "../utils.js";
import {LinkedList} from "../../../util/array.js";
import {Metrics} from "../../../metrics/metrics.js";
import {LinkedList} from "../../util/array.js";
import {Metrics} from "../../metrics/metrics.js";
import {VerifySignatureOpts} from "./interface.js";
import {getAggregatedPubkey} from "./utils.js";
import {BlsWorkReq} from "./types.js";

export type JobQueueItem = JobQueueItemDefault | JobQueueItemSameMessage;
Expand Down Expand Up @@ -49,14 +49,14 @@ export function jobItemSigSets(job: JobQueueItem): number {
* Prepare BlsWorkReq from JobQueueItem
* WARNING: May throw with untrusted user input
*/
export function jobItemWorkReq(job: JobQueueItem, format: PointFormat, metrics: Metrics | null): BlsWorkReq {
export function jobItemWorkReq(job: JobQueueItem, metrics: Metrics | null): BlsWorkReq {
switch (job.type) {
case JobQueueItemType.default:
return {
opts: job.opts,
sets: job.sets.map((set) => ({
// this can throw, handled in the consumer code
publicKey: getAggregatedPubkey(set, metrics).toBytes(format),
publicKey: getAggregatedPubkey(set, metrics),
signature: set.signature,
message: set.signingRoot,
})),
Expand All @@ -70,16 +70,20 @@ export function jobItemWorkReq(job: JobQueueItem, format: PointFormat, metrics:
// and not a problem in the near future
// this is monitored on v1.11.0 https://github.com/ChainSafe/lodestar/pull/5912#issuecomment-1700320307
const timer = metrics?.blsThreadPool.signatureDeserializationMainThreadDuration.startTimer();
const signatures = job.sets.map((set) => bls.Signature.fromBytes(set.signature, CoordType.affine, true));
const signatures = job.sets.map((set) => signatureFromBytes(set.signature));
timer?.();

const randomness: Uint8Array[] = [];
for (let i = 0; i < job.sets.length; i++) {
randomness.push(randomBytesNonZero(8));
}
return {
opts: job.opts,
sets: [
{
publicKey: bls.PublicKey.aggregate(job.sets.map((set) => set.publicKey)).toBytes(format),
signature: bls.Signature.aggregate(signatures).toBytes(format),
message: job.message,
publicKey: aggregatePublicKeys(job.sets.map((set, i) => set.publicKey.multiplyBy(randomness[i]))),
signature: aggregateSignatures(signatures.map((sig, i) => sig.multiplyBy(randomness[i]))),
},
],
};
Expand Down
46 changes: 0 additions & 46 deletions packages/beacon-node/src/chain/bls/maybeBatch.ts

This file was deleted.

Loading

0 comments on commit 36be944

Please sign in to comment.