@lodestar/native 1.52.0-dev.0ac7778d70 → 1.52.0-dev.3d90162721
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/package.json +31 -16
- package/src/bindings.js +8 -1
- package/src/bls-verifier.d.ts +20 -1
- package/src/committee-pubkeys.d.ts +27 -0
- package/src/committee-pubkeys.js +9 -0
- package/src/pubkeys.d.ts +4 -1
package/README.md
CHANGED
|
@@ -22,10 +22,11 @@ pnpm build
|
|
|
22
22
|
pnpm test:native
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
For native-only changes, rebuild with `pnpm build:native`.
|
|
26
|
-
`bindings/zig-out/lib/bindings
|
|
27
|
-
`pnpm --filter @lodestar/native prepare-
|
|
28
|
-
|
|
25
|
+
For native-only changes, rebuild with `pnpm build:native`. It builds one addon per preset
|
|
26
|
+
into `bindings/zig-out/lib/bindings-<preset>.node`, and `LODESTAR_PRESET` selects which one
|
|
27
|
+
is loaded (default `mainnet`). Use `pnpm --filter @lodestar/native prepare-mainnet`,
|
|
28
|
+
`prepare-minimal` or `prepare-gnosis` to rebuild a single preset. Do not run them
|
|
29
|
+
concurrently; they share an intermediate output file.
|
|
29
30
|
|
|
30
31
|
Bindings use their own Vitest configuration and the root workspace lockfile.
|
|
31
32
|
Consensus spec vectors are pinned in [`build.zig.zon`](../build.zig.zon).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lodestar/native",
|
|
3
|
-
"version": "1.52.0-dev.
|
|
3
|
+
"version": "1.52.0-dev.3d90162721",
|
|
4
4
|
"description": "Native consensus modules for Lodestar",
|
|
5
5
|
"files": [
|
|
6
6
|
"src/"
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"types": "./src/pubkeys.d.ts",
|
|
24
24
|
"import": "./src/pubkeys.js"
|
|
25
25
|
},
|
|
26
|
+
"./committee-pubkeys": {
|
|
27
|
+
"types": "./src/committee-pubkeys.d.ts",
|
|
28
|
+
"import": "./src/committee-pubkeys.js"
|
|
29
|
+
},
|
|
26
30
|
"./state-transition": {
|
|
27
31
|
"types": "./src/state-transition.d.ts",
|
|
28
32
|
"import": "./src/state-transition.js"
|
|
@@ -41,17 +45,17 @@
|
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"scripts": {
|
|
44
|
-
"prepare-mainnet": "
|
|
45
|
-
"prepare-minimal": "
|
|
46
|
-
"prepare-gnosis": "
|
|
48
|
+
"prepare-mainnet": "zapi build --variant mainnet --optimize ReleaseSafe --zig-cwd .. --prefix bindings/zig-out",
|
|
49
|
+
"prepare-minimal": "zapi build --variant minimal --optimize ReleaseSafe --zig-cwd .. --prefix bindings/zig-out",
|
|
50
|
+
"prepare-gnosis": "zapi build --variant gnosis --optimize ReleaseSafe --zig-cwd .. --prefix bindings/zig-out",
|
|
47
51
|
"lint": "biome check",
|
|
48
52
|
"test": "NODE_OPTIONS='--expose-gc' vitest run",
|
|
49
53
|
"benchmark": "NODE_OPTIONS='--import tsx' benchmark 'perf/**/*.test.ts' --isolate --config .benchrc.yaml --defaultBranch unstable",
|
|
50
|
-
"build": "pnpm run prepare
|
|
51
|
-
"build:watch": "
|
|
54
|
+
"build": "pnpm run prepare-mainnet && pnpm run prepare-minimal && pnpm run prepare-gnosis",
|
|
55
|
+
"build:watch": "preset=${LODESTAR_PRESET:-mainnet} && mkdir -p zig-out/lib && ln -sf bindings.node zig-out/lib/bindings-$preset.node && cd .. && zig build build-lib:bindings -Doptimize=ReleaseSafe -Dcpu=baseline -Dpreset=$preset --prefix bindings/zig-out --watch",
|
|
52
56
|
"build:release": "pnpm clean && pnpm build",
|
|
53
57
|
"clean": "rm -rf zig-out",
|
|
54
|
-
"check-build": "node -e \"import('./src/index.js')\"",
|
|
58
|
+
"check-build": "for preset in mainnet minimal gnosis; do LODESTAR_PRESET=$preset node -e \"import('./src/index.js')\" || exit 1; done",
|
|
55
59
|
"prepack": "zapi prepublish --main-only"
|
|
56
60
|
},
|
|
57
61
|
"keywords": [],
|
|
@@ -72,10 +76,21 @@
|
|
|
72
76
|
"x86_64-apple-darwin",
|
|
73
77
|
"x86_64-unknown-linux-gnu",
|
|
74
78
|
"x86_64-unknown-linux-musl"
|
|
75
|
-
]
|
|
79
|
+
],
|
|
80
|
+
"variants": {
|
|
81
|
+
"mainnet": [
|
|
82
|
+
"-Dpreset=mainnet"
|
|
83
|
+
],
|
|
84
|
+
"minimal": [
|
|
85
|
+
"-Dpreset=minimal"
|
|
86
|
+
],
|
|
87
|
+
"gnosis": [
|
|
88
|
+
"-Dpreset=gnosis"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
76
91
|
},
|
|
77
92
|
"dependencies": {
|
|
78
|
-
"@chainsafe/zapi": "4.
|
|
93
|
+
"@chainsafe/zapi": "4.5.0"
|
|
79
94
|
},
|
|
80
95
|
"devDependencies": {
|
|
81
96
|
"@chainsafe/benchmark": "2.1.0",
|
|
@@ -84,13 +99,13 @@
|
|
|
84
99
|
"publishConfig": {
|
|
85
100
|
"access": "public"
|
|
86
101
|
},
|
|
87
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "9cab33cd591fc0ea642c8062978c859b3ea3ab82",
|
|
88
103
|
"optionalDependencies": {
|
|
89
|
-
"@lodestar/native-aarch64-apple-darwin": "1.52.0-dev.
|
|
90
|
-
"@lodestar/native-aarch64-unknown-linux-gnu": "1.52.0-dev.
|
|
91
|
-
"@lodestar/native-aarch64-unknown-linux-musl": "1.52.0-dev.
|
|
92
|
-
"@lodestar/native-x86_64-apple-darwin": "1.52.0-dev.
|
|
93
|
-
"@lodestar/native-x86_64-unknown-linux-gnu": "1.52.0-dev.
|
|
94
|
-
"@lodestar/native-x86_64-unknown-linux-musl": "1.52.0-dev.
|
|
104
|
+
"@lodestar/native-aarch64-apple-darwin": "1.52.0-dev.3d90162721",
|
|
105
|
+
"@lodestar/native-aarch64-unknown-linux-gnu": "1.52.0-dev.3d90162721",
|
|
106
|
+
"@lodestar/native-aarch64-unknown-linux-musl": "1.52.0-dev.3d90162721",
|
|
107
|
+
"@lodestar/native-x86_64-apple-darwin": "1.52.0-dev.3d90162721",
|
|
108
|
+
"@lodestar/native-x86_64-unknown-linux-gnu": "1.52.0-dev.3d90162721",
|
|
109
|
+
"@lodestar/native-x86_64-unknown-linux-musl": "1.52.0-dev.3d90162721"
|
|
95
110
|
}
|
|
96
111
|
}
|
package/src/bindings.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import {join} from "node:path";
|
|
2
2
|
import {requireNapiLibrary} from "@chainsafe/zapi";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Consensus presets are compiled into the addon, so there is one binary per preset.
|
|
5
|
+
// The selection mirrors `ACTIVE_PRESET` in `@lodestar/params`.
|
|
6
|
+
const presets = ["mainnet", "minimal", "gnosis"];
|
|
7
|
+
const preset = process.env.LODESTAR_PRESET;
|
|
8
|
+
|
|
9
|
+
const bindings = requireNapiLibrary(join(import.meta.dirname, ".."), {
|
|
10
|
+
variant: preset !== undefined && presets.includes(preset) ? preset : "mainnet",
|
|
11
|
+
});
|
|
5
12
|
|
|
6
13
|
export default bindings;
|
package/src/bls-verifier.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare const BLS_VERIFIER_SET_TYPE: {
|
|
|
2
2
|
readonly indexed: 0;
|
|
3
3
|
readonly aggregate: 1;
|
|
4
4
|
readonly single: 2;
|
|
5
|
+
readonly committee: 3;
|
|
5
6
|
};
|
|
6
7
|
|
|
7
8
|
export declare const BLS_VERIFIER_MAX_BATCH_SIZE: 256;
|
|
@@ -30,7 +31,25 @@ export type SingleSignatureSet = {
|
|
|
30
31
|
signature: Uint8Array;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* An attestation over whole committees of one slot, verified with the committee pubkeys from
|
|
36
|
+
* `computeCommitteePubkeys()`. Its aggregation bits are concatenated in `committeeIndices` order. `indices` lists the
|
|
37
|
+
* participants and is aggregated instead when the entry is not cached. Only the participant count is checked, so
|
|
38
|
+
* callers must derive `indices` and the aggregation bits from the same attestation.
|
|
39
|
+
*/
|
|
40
|
+
export type CommitteeSignatureSet = {
|
|
41
|
+
type: typeof BLS_VERIFIER_SET_TYPE.committee;
|
|
42
|
+
indices: Uint32Array;
|
|
43
|
+
committeePubkeysId: number;
|
|
44
|
+
slot: number;
|
|
45
|
+
committeeIndices: Uint32Array;
|
|
46
|
+
aggregationBits: Uint8Array;
|
|
47
|
+
bitLen: number;
|
|
48
|
+
message: Uint8Array;
|
|
49
|
+
signature: Uint8Array;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type BlsSignatureSet = IndexedSignatureSet | AggregateSignatureSet | SingleSignatureSet | CommitteeSignatureSet;
|
|
34
53
|
|
|
35
54
|
export type SameMessageSignatureSet = {
|
|
36
55
|
index: number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregate pubkeys of the beacon committees of an epoch shuffling, held in native memory. Signature sets reference an
|
|
3
|
+
* entry by id, so BLS worker threads can use it too.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Entries the cache holds at most, counting computations in flight. */
|
|
7
|
+
export declare const COMMITTEE_PUBKEYS_MAX_ENTRIES: number;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Aggregate the pubkeys of every committee of a shuffling on a libuv worker thread and resolve to the entry id.
|
|
11
|
+
* `shuffling` is the shuffled active validator indices, and it is copied before this returns. Throws when
|
|
12
|
+
* `COMMITTEE_PUBKEYS_MAX_ENTRIES` entries are cached or being computed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function computeCommitteePubkeys(
|
|
15
|
+
shuffling: Uint32Array,
|
|
16
|
+
slotsPerEpoch: number,
|
|
17
|
+
committeesPerSlot: number
|
|
18
|
+
): Promise<number>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Free an entry. Returns false if `id` is unknown. A signature set that still references it falls back to its
|
|
22
|
+
* participant indices.
|
|
23
|
+
*/
|
|
24
|
+
export declare function releaseCommitteePubkeys(id: number): boolean;
|
|
25
|
+
|
|
26
|
+
/** Number of cached entries. */
|
|
27
|
+
export declare function committeePubkeysCount(): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import bindings from "./bindings.js";
|
|
2
|
+
|
|
3
|
+
const native = bindings.committeePubkeys;
|
|
4
|
+
|
|
5
|
+
export const COMMITTEE_PUBKEYS_MAX_ENTRIES = native.MAX_ENTRIES;
|
|
6
|
+
|
|
7
|
+
export const computeCommitteePubkeys = native.compute;
|
|
8
|
+
export const releaseCommitteePubkeys = native.release;
|
|
9
|
+
export const committeePubkeysCount = native.size;
|
package/src/pubkeys.d.ts
CHANGED
|
@@ -48,7 +48,10 @@ export interface PubkeyCache {
|
|
|
48
48
|
* recorded in the file is discarded above this limit.
|
|
49
49
|
*/
|
|
50
50
|
load(filepath: string, maxCapacity: number): void;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Testing-only reset from the control environment while no workers are using the cache.
|
|
53
|
+
* Also drops the committee pubkeys aggregated from the cleared keys.
|
|
54
|
+
*/
|
|
52
55
|
reset(): void;
|
|
53
56
|
/** Save from the control environment. */
|
|
54
57
|
save(filepath: string): void;
|