Skip to content

Commit 57b3578

Browse files
committed
feat: use bun-ffi-z github url
1 parent a0fe350 commit 57b3578

File tree

9 files changed

+182
-173
lines changed

9 files changed

+182
-173
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,21 @@ jobs:
6161
echo "$HOME/.bun/bin" >> $GITHUB_PATH
6262
bun --version
6363
64-
# # TODOs
65-
# - name: Bun - Install Dependencies
66-
# run: bun install
67-
# working-directory: ./test/bun
64+
- name: Bun - Install Dependencies
65+
run: bun install
66+
working-directory: ./bun
6867

69-
# - name: Bun - Lint Code
70-
# run: bun lint
71-
# working-directory: ./test/bun
68+
- name: Bun - Lint Code
69+
run: bun lint
70+
working-directory: ./bun
7271

73-
# - name: Bun - Unit Tests
74-
# run: bun test:unit
75-
# working-directory: ./test/bun
72+
- name: Bun - Unit Tests
73+
run: bun test:unit
74+
working-directory: ./bun
7675

77-
# - name: Benchmark
78-
# run: bun benchmark
79-
# working-directory: ./test/bun
80-
# env:
81-
# # To write to PRs and commits
82-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
- name: Benchmark
77+
run: bun benchmark
78+
working-directory: ./bun
79+
env:
80+
# To write to PRs and commits
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bun/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"module": "src/index.ts",
44
"type": "module",
55
"dependencies": {
6-
"@chainsafe/bun-ffi-z": "../../bun-ffi-z"
6+
"@chainsafe/bun-ffi-z": "https://github.com/twoeths/bun-ffi-z.git#te/fix_open_library"
77
},
88
"devDependencies": {
99
"@types/bun": "latest",

bun/src/binding.ts

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,138 @@
1-
import {type ConvertFns} from "bun:ffi";
2-
import {openLibrary} from "@chainsafe/bun-ffi-z";
1+
import type { ConvertFns } from "bun:ffi";
32
import path from "node:path";
3+
import { openLibrary } from "@chainsafe/bun-ffi-z";
44

55
const fns = {
6-
createPubkeyIndexMap: {
7-
args: [],
8-
returns: "ptr",
9-
},
10-
destroyPubkeyIndexMap: {
11-
args: ["ptr"],
12-
returns: "void",
13-
},
14-
getNotFoundIndex: {
15-
args: [],
16-
returns: "u32",
17-
},
18-
getErrorIndex: {
19-
args: [],
20-
returns: "u32",
21-
},
22-
pubkeyIndexMapSet: {
23-
args: ["ptr", "ptr", "u32", "u32"],
24-
returns: "u32",
25-
},
26-
pubkeyIndexMapGet: {
27-
args: ["ptr", "ptr", "u32"],
28-
returns: "u32",
29-
},
30-
pubkeyIndexMapClear: {
31-
args: ["ptr"],
32-
returns: "void",
33-
},
34-
pubkeyIndexMapClone: {
35-
args: ["ptr"],
36-
returns: "ptr",
37-
},
38-
pubkeyIndexMapHas: {
39-
args: ["ptr", "ptr", "u32"],
40-
returns: "bool",
41-
},
42-
pubkeyIndexMapDelete: {
43-
args: ["ptr", "ptr", "u32"],
44-
returns: "bool",
45-
},
46-
pubkeyIndexMapSize: {
47-
args: ["ptr"],
48-
returns: "u32",
49-
},
50-
// binding for shuffe
51-
shuffleList: {
52-
args: ["ptr", "u32", "ptr", "u32", "u8"],
53-
returns: "u32",
54-
},
55-
unshuffleList: {
56-
args: ["ptr", "u32", "ptr", "u32", "u8"],
57-
returns: "u32",
58-
},
59-
asyncShuffleList: {
60-
args: ["ptr", "u32", "ptr", "u32", "u8"],
61-
returns: "u32",
62-
},
63-
asyncUnshuffleList: {
64-
args: ["ptr", "u32", "ptr", "u32", "u8"],
65-
returns: "u32",
66-
},
67-
pollAsyncResult: {
68-
args: ["u32"],
69-
returns: "u32",
70-
},
71-
releaseAsyncResult: {
72-
args: ["u32"],
73-
returns: "void",
74-
},
75-
computeProposerIndexElectra: {
76-
args: ["ptr", "u32", "ptr", "u32", "ptr", "u32", "u64", "u32", "u32"],
77-
returns: "u32",
78-
},
79-
computeProposerIndex: {
80-
args: ["ptr", "u32", "ptr", "u32", "ptr", "u32", "u8", "u64", "u32", "u32"],
81-
returns: "u32",
82-
},
83-
computeSyncCommitteeIndicesElectra: {
84-
args: [
85-
"ptr",
86-
"u32",
87-
"ptr",
88-
"u32",
89-
"ptr",
90-
"u32",
91-
"u64",
92-
"u32",
93-
"u32",
94-
"ptr",
95-
"u32",
96-
],
97-
returns: "u32",
98-
},
99-
computeSyncCommitteeIndices: {
100-
arts: [
101-
"ptr",
102-
"u32",
103-
"ptr",
104-
"u32",
105-
"ptr",
106-
"u32",
107-
"u8",
108-
"u64",
109-
"u32",
110-
"u32",
111-
"ptr",
112-
"u32",
113-
],
114-
returns: "u32",
115-
},
6+
createPubkeyIndexMap: {
7+
args: [],
8+
returns: "ptr",
9+
},
10+
destroyPubkeyIndexMap: {
11+
args: ["ptr"],
12+
returns: "void",
13+
},
14+
getNotFoundIndex: {
15+
args: [],
16+
returns: "u32",
17+
},
18+
getErrorIndex: {
19+
args: [],
20+
returns: "u32",
21+
},
22+
pubkeyIndexMapSet: {
23+
args: ["ptr", "ptr", "u32", "u32"],
24+
returns: "u32",
25+
},
26+
pubkeyIndexMapGet: {
27+
args: ["ptr", "ptr", "u32"],
28+
returns: "u32",
29+
},
30+
pubkeyIndexMapClear: {
31+
args: ["ptr"],
32+
returns: "void",
33+
},
34+
pubkeyIndexMapClone: {
35+
args: ["ptr"],
36+
returns: "ptr",
37+
},
38+
pubkeyIndexMapHas: {
39+
args: ["ptr", "ptr", "u32"],
40+
returns: "bool",
41+
},
42+
pubkeyIndexMapDelete: {
43+
args: ["ptr", "ptr", "u32"],
44+
returns: "bool",
45+
},
46+
pubkeyIndexMapSize: {
47+
args: ["ptr"],
48+
returns: "u32",
49+
},
50+
// binding for shuffe
51+
shuffleList: {
52+
args: ["ptr", "u32", "ptr", "u32", "u8"],
53+
returns: "u32",
54+
},
55+
unshuffleList: {
56+
args: ["ptr", "u32", "ptr", "u32", "u8"],
57+
returns: "u32",
58+
},
59+
asyncShuffleList: {
60+
args: ["ptr", "u32", "ptr", "u32", "u8"],
61+
returns: "u32",
62+
},
63+
asyncUnshuffleList: {
64+
args: ["ptr", "u32", "ptr", "u32", "u8"],
65+
returns: "u32",
66+
},
67+
pollAsyncResult: {
68+
args: ["u32"],
69+
returns: "u32",
70+
},
71+
releaseAsyncResult: {
72+
args: ["u32"],
73+
returns: "void",
74+
},
75+
computeProposerIndexElectra: {
76+
args: ["ptr", "u32", "ptr", "u32", "ptr", "u32", "u64", "u32", "u32"],
77+
returns: "u32",
78+
},
79+
computeProposerIndex: {
80+
args: ["ptr", "u32", "ptr", "u32", "ptr", "u32", "u8", "u64", "u32", "u32"],
81+
returns: "u32",
82+
},
83+
computeSyncCommitteeIndicesElectra: {
84+
args: [
85+
"ptr",
86+
"u32",
87+
"ptr",
88+
"u32",
89+
"ptr",
90+
"u32",
91+
"u64",
92+
"u32",
93+
"u32",
94+
"ptr",
95+
"u32",
96+
],
97+
returns: "u32",
98+
},
99+
computeSyncCommitteeIndices: {
100+
arts: [
101+
"ptr",
102+
"u32",
103+
"ptr",
104+
"u32",
105+
"ptr",
106+
"u32",
107+
"u8",
108+
"u64",
109+
"u32",
110+
"u32",
111+
"ptr",
112+
"u32",
113+
],
114+
returns: "u32",
115+
},
116116
};
117117

118-
let binding : ConvertFns<typeof fns> | null = null;
118+
let binding: ConvertFns<typeof fns> | null = null;
119119

120120
// Load the compiled Zig shared library
121121
const libPromise = await openLibrary(path.resolve("../bun"), fns);
122122

123123
export async function initBinding(): Promise<void> {
124-
const lib = await libPromise;
125-
binding = lib.symbols;
124+
const lib = await libPromise;
125+
binding = lib.symbols;
126126
}
127127

128128
export function getBinding(): ConvertFns<typeof fns> {
129-
if (binding == null) {
130-
throw new Error("Binding not initialized. Call init() first.");
131-
}
132-
return binding;
129+
if (binding == null) {
130+
throw new Error("Binding not initialized. Call init() first.");
131+
}
132+
return binding;
133133
}
134134

135135
export async function closeBinding(): Promise<void> {
136-
const lib = await libPromise;
136+
const lib = await libPromise;
137137
lib.close();
138138
}

bun/src/committeeIndices.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function computeProposerIndex(
2020
rounds: number,
2121
): number {
2222
validateShufflingParams(activeIndices, seed, rounds);
23-
const binding = getBinding();
23+
const binding = getBinding();
2424

2525
const result = binding.computeProposerIndex(
2626
seed,
@@ -49,7 +49,7 @@ export function computeProposerIndexElectra(
4949
rounds: number,
5050
): number {
5151
validateShufflingParams(activeIndices, seed, rounds);
52-
const binding = getBinding();
52+
const binding = getBinding();
5353

5454
const result = binding.computeProposerIndexElectra(
5555
seed,
@@ -79,7 +79,7 @@ export function computeSyncCommitteeIndices(
7979
rounds: number,
8080
): Uint32Array {
8181
validateShufflingParams(activeIndices, seed, rounds);
82-
const binding = getBinding();
82+
const binding = getBinding();
8383

8484
const out = new Uint32Array(syncCommitteeSize);
8585
const result = binding.computeSyncCommitteeIndices(
@@ -114,7 +114,7 @@ export function computeSyncCommitteeIndicesElectra(
114114
rounds: number,
115115
): Uint32Array {
116116
validateShufflingParams(activeIndices, seed, rounds);
117-
const binding = getBinding();
117+
const binding = getBinding();
118118

119119
const out = new Uint32Array(syncCommitteeSize);
120120
const result = binding.computeSyncCommitteeIndicesElectra(

0 commit comments

Comments
 (0)