nano-rspow-web 0.17.1 → 0.17.2
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 +92 -3
- package/nano_rspow_web.d.ts +3 -3
- package/nano_rspow_web.js +44 -12
- package/nano_rspow_web_bg.wasm +0 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ node when it differs. See Nano's
|
|
|
39
39
|
[Work Generation guide](https://docs.nano.org/integration-guides/work-generation/)
|
|
40
40
|
for current network requirements.
|
|
41
41
|
|
|
42
|
-
## Benchmarking
|
|
42
|
+
## Benchmarking Dashboards
|
|
43
43
|
|
|
44
44
|
<table>
|
|
45
45
|
<tr>
|
|
@@ -54,9 +54,79 @@ for current network requirements.
|
|
|
54
54
|
</tr>
|
|
55
55
|
</table>
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
Try the browser-only dashboard without building anything:
|
|
58
|
+
**[https://casualsecurityinc.github.io/nano-rspow/](https://casualsecurityinc.github.io/nano-rspow/)**
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
### Running them locally
|
|
61
|
+
|
|
62
|
+
Everything runs through `make` from the repository root. Run `make help` for the
|
|
63
|
+
full list.
|
|
64
|
+
|
|
65
|
+
**One-time setup, after cloning:**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
make web-prereqs
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
That installs the `wasm32-unknown-unknown` Rust target, builds the
|
|
72
|
+
`nano-rspow-node` native addon and installs the dashboard's npm dependencies,
|
|
73
|
+
skipping whatever is already satisfied. It is safe to re-run. It needs `cargo`,
|
|
74
|
+
`npm` and `python3` on your `PATH`, plus the `wasm-bindgen` CLI, which it does
|
|
75
|
+
*not* install for you — that compiles for several minutes, so the script prints
|
|
76
|
+
the command instead and exits. Both dashboards need `wasm-bindgen`; the native
|
|
77
|
+
addon is the only prerequisite that only the head-to-head dashboard needs, so
|
|
78
|
+
`./scripts/setup-web-toolchain.sh --skip-addon` is enough for the browser-only
|
|
79
|
+
one.
|
|
80
|
+
|
|
81
|
+
Verify the toolchain without changing anything with
|
|
82
|
+
`./scripts/setup-web-toolchain.sh --check`.
|
|
83
|
+
|
|
84
|
+
`cargo benchmark-web` also builds and opens the browser-only dashboard. It is a
|
|
85
|
+
thin wrapper around the same `build-demo.py`, kept because the root README has
|
|
86
|
+
long pointed at it; prefer `make web-demo`, which is the same thing plus the
|
|
87
|
+
prerequisite tooling.
|
|
88
|
+
|
|
89
|
+
**Browser-only dashboard** — measures this package's WebGPU and WASM CPU
|
|
90
|
+
backends, nothing else. No server, no addon:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
make web-demo # builds and opens nano-rspow-web/browser-demo/index.html
|
|
94
|
+
make web-demo-build # same build, no browser launch
|
|
95
|
+
make web-demo-check # is the built page present, complete and current?
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`index.html` is a single self-contained file — the WebAssembly, the
|
|
99
|
+
wasm-bindgen glue and the WGSL shader are all inlined, so it works when opened
|
|
100
|
+
straight from disk over `file://`. It is **generated and not committed**,
|
|
101
|
+
because a 550 KB committed artifact eventually gets opened after the crate has
|
|
102
|
+
moved on and silently benchmarks an old WebAssembly module. If the file is
|
|
103
|
+
missing or older than its sources, `make web-demo-check` says so and tells you
|
|
104
|
+
to rebuild.
|
|
105
|
+
|
|
106
|
+
**Head-to-head dashboard** — compares this package against `nano-pow` and
|
|
107
|
+
against the `nano-rspow-node` addon and the Rust CLI work peer. It needs the
|
|
108
|
+
native addon, which is why it is a separate command:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
make web-compare-run # builds, then serves on http://localhost:8080/
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Overrides: `make web-compare-run PORT=8081`, or `WORK_PEER_PORT`,
|
|
115
|
+
`WORK_PEER_BACKEND=auto|cpu|gpu`, and `NANO_WORK_URL` to point at a work peer
|
|
116
|
+
you are already running. `make web-compare` builds into `dist/` without serving.
|
|
117
|
+
`make web-all` builds both, `make web-clean` removes the generated output.
|
|
118
|
+
|
|
119
|
+
### What CI covers
|
|
120
|
+
|
|
121
|
+
CI builds and verifies the **browser-only** dashboard only, in the
|
|
122
|
+
`browser-demo` job of `.github/workflows/web-browser-tests.yml`. It runs the same
|
|
123
|
+
prerequisite script, the same `make web-demo-build`, and then
|
|
124
|
+
`scripts/check-browser-demo.sh` — the same check as `make web-demo-check` — so
|
|
125
|
+
CI and your machine cannot disagree about what a valid dashboard is.
|
|
126
|
+
|
|
127
|
+
The head-to-head dashboard is not built in CI because it requires the native
|
|
128
|
+
`nano-rspow-node` addon, which is a platform-specific native compile. It is a
|
|
129
|
+
local tool, and `make web-compare-run` is the supported way to run it.
|
|
60
130
|
|
|
61
131
|
|
|
62
132
|
|
|
@@ -78,6 +148,25 @@ Asynchronously generates Proof of Work for a 32-byte block hash at any hexadecim
|
|
|
78
148
|
### `generate_work_gpu(hash_hex: string, threshold_hex: string, cancel_token: WasmCancelToken): Promise<GenerateResult>`
|
|
79
149
|
Forces WebGPU PoW generation at any hexadecimal threshold. Rejects if WebGPU is unavailable or if the cancellation token is triggered.
|
|
80
150
|
|
|
151
|
+
### GPU resource lifetime and concurrency
|
|
152
|
+
|
|
153
|
+
One WebGPU generator is built per page and reused by every call. Building one
|
|
154
|
+
requests an instance, adapter, device and queue, compiles the WGSL shader,
|
|
155
|
+
creates the compute pipeline and allocates the double-buffered slots, so
|
|
156
|
+
rebuilding it per call charged that whole cost to the caller once per block.
|
|
157
|
+
`recommendLocalPow` builds the same generator, which also warms the cache for
|
|
158
|
+
the first `generate_work` call.
|
|
159
|
+
|
|
160
|
+
Two consequences for callers:
|
|
161
|
+
|
|
162
|
+
- **Generation is serialised.** The generator's ping-pong buffers are shared, so
|
|
163
|
+
overlapping calls would write the same slot and read back each other's
|
|
164
|
+
results, handing back work computed for a different block. Calls are
|
|
165
|
+
therefore queued and run one at a time, in the order they arrive. Concurrent
|
|
166
|
+
calls are safe but wait their turn; they are never rejected or interleaved.
|
|
167
|
+
- **A lost device is recovered automatically.** If the browser drops the
|
|
168
|
+
device, the cached generator is discarded and the next call builds a new one.
|
|
169
|
+
|
|
81
170
|
### `generate_work_cpu(hash_hex: string, threshold_hex: string): GenerateResult`
|
|
82
171
|
Synchronously generates PoW at any hexadecimal threshold, forcing single-threaded CPU WebAssembly.
|
|
83
172
|
|
package/nano_rspow_web.d.ts
CHANGED
|
@@ -81,9 +81,9 @@ export interface InitOutput {
|
|
|
81
81
|
readonly validate_work: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
82
82
|
readonly wasmcanceltoken_cancel: (a: number) => void;
|
|
83
83
|
readonly wasmcanceltoken_new: () => number;
|
|
84
|
-
readonly
|
|
85
|
-
readonly
|
|
86
|
-
readonly
|
|
84
|
+
readonly wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_eea6accdcfb85281___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
85
|
+
readonly wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
86
|
+
readonly wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue______true_: (a: number, b: number, c: any) => void;
|
|
87
87
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
88
88
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
89
89
|
readonly __wbindgen_exn_store: (a: number) => void;
|
package/nano_rspow_web.js
CHANGED
|
@@ -309,6 +309,16 @@ function __wbg_get_imports() {
|
|
|
309
309
|
const ret = result;
|
|
310
310
|
return ret;
|
|
311
311
|
},
|
|
312
|
+
__wbg_instanceof_GpuDeviceLostInfo_0e99a9595225a57d: function(arg0) {
|
|
313
|
+
let result;
|
|
314
|
+
try {
|
|
315
|
+
result = arg0 instanceof GPUDeviceLostInfo;
|
|
316
|
+
} catch (_) {
|
|
317
|
+
result = false;
|
|
318
|
+
}
|
|
319
|
+
const ret = result;
|
|
320
|
+
return ret;
|
|
321
|
+
},
|
|
312
322
|
__wbg_label_9a8583e3a20fafc7: function(arg0, arg1) {
|
|
313
323
|
const ret = arg1.label;
|
|
314
324
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -323,10 +333,21 @@ function __wbg_get_imports() {
|
|
|
323
333
|
__wbg_log_eb752234eec406d1: function(arg0) {
|
|
324
334
|
console.log(arg0);
|
|
325
335
|
},
|
|
336
|
+
__wbg_lost_b787a12a0e44349f: function(arg0) {
|
|
337
|
+
const ret = arg0.lost;
|
|
338
|
+
return ret;
|
|
339
|
+
},
|
|
326
340
|
__wbg_mapAsync_e3cfbd141919d03c: function(arg0, arg1, arg2, arg3) {
|
|
327
341
|
const ret = arg0.mapAsync(arg1 >>> 0, arg2, arg3);
|
|
328
342
|
return ret;
|
|
329
343
|
},
|
|
344
|
+
__wbg_message_c717665d7f0d1da0: function(arg0, arg1) {
|
|
345
|
+
const ret = arg1.message;
|
|
346
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
347
|
+
const len1 = WASM_VECTOR_LEN;
|
|
348
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
349
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
350
|
+
},
|
|
330
351
|
__wbg_navigator_3334c390f542c642: function(arg0) {
|
|
331
352
|
const ret = arg0.navigator;
|
|
332
353
|
return ret;
|
|
@@ -350,7 +371,7 @@ function __wbg_get_imports() {
|
|
|
350
371
|
const a = state0.a;
|
|
351
372
|
state0.a = 0;
|
|
352
373
|
try {
|
|
353
|
-
return
|
|
374
|
+
return wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined_______true_(a, state0.b, arg0, arg1);
|
|
354
375
|
} finally {
|
|
355
376
|
state0.a = a;
|
|
356
377
|
}
|
|
@@ -368,7 +389,7 @@ function __wbg_get_imports() {
|
|
|
368
389
|
const a = state0.a;
|
|
369
390
|
state0.a = 0;
|
|
370
391
|
try {
|
|
371
|
-
return
|
|
392
|
+
return wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined_______true_(a, state0.b, arg0, arg1);
|
|
372
393
|
} finally {
|
|
373
394
|
state0.a = a;
|
|
374
395
|
}
|
|
@@ -409,6 +430,10 @@ function __wbg_get_imports() {
|
|
|
409
430
|
const ret = arg0.queue;
|
|
410
431
|
return ret;
|
|
411
432
|
},
|
|
433
|
+
__wbg_reason_170684b0bb329a56: function(arg0) {
|
|
434
|
+
const ret = arg0.reason;
|
|
435
|
+
return (__wbindgen_enum_GpuDeviceLostReason.indexOf(ret) + 1 || 3) - 1;
|
|
436
|
+
},
|
|
412
437
|
__wbg_requestAdapter_0049683abd339828: function(arg0, arg1) {
|
|
413
438
|
const ret = arg0.requestAdapter(arg1);
|
|
414
439
|
return ret;
|
|
@@ -609,6 +634,10 @@ function __wbg_get_imports() {
|
|
|
609
634
|
__wbg_submit_b3bbead76cbf7627: function(arg0, arg1) {
|
|
610
635
|
arg0.submit(arg1);
|
|
611
636
|
},
|
|
637
|
+
__wbg_then_7b57a40e3ee05615: function(arg0, arg1) {
|
|
638
|
+
const ret = arg0.then(arg1);
|
|
639
|
+
return ret;
|
|
640
|
+
},
|
|
612
641
|
__wbg_then_837494e384b37459: function(arg0, arg1) {
|
|
613
642
|
const ret = arg0.then(arg1);
|
|
614
643
|
return ret;
|
|
@@ -628,13 +657,13 @@ function __wbg_get_imports() {
|
|
|
628
657
|
arg0.writeBuffer(arg1, arg2, getArrayU8FromWasm0(arg3, arg4), arg5, arg6);
|
|
629
658
|
}, arguments); },
|
|
630
659
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
631
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
632
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
660
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 111, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
661
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_eea6accdcfb85281___JsError___true_);
|
|
633
662
|
return ret;
|
|
634
663
|
},
|
|
635
664
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
636
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
637
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
665
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 77, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
666
|
+
const ret = makeMutClosure(arg0, arg1, wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue______true_);
|
|
638
667
|
return ret;
|
|
639
668
|
},
|
|
640
669
|
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
@@ -668,25 +697,28 @@ function __wbg_get_imports() {
|
|
|
668
697
|
};
|
|
669
698
|
}
|
|
670
699
|
|
|
671
|
-
function
|
|
672
|
-
wasm.
|
|
700
|
+
function wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue______true_(arg0, arg1, arg2) {
|
|
701
|
+
wasm.wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue______true_(arg0, arg1, arg2);
|
|
673
702
|
}
|
|
674
703
|
|
|
675
|
-
function
|
|
676
|
-
const ret = wasm.
|
|
704
|
+
function wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_eea6accdcfb85281___JsError___true_(arg0, arg1, arg2) {
|
|
705
|
+
const ret = wasm.wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___wasm_bindgen_eea6accdcfb85281___JsValue__core_ed718c3d60ebd546___result__Result_____wasm_bindgen_eea6accdcfb85281___JsError___true_(arg0, arg1, arg2);
|
|
677
706
|
if (ret[1]) {
|
|
678
707
|
throw takeFromExternrefTable0(ret[0]);
|
|
679
708
|
}
|
|
680
709
|
}
|
|
681
710
|
|
|
682
|
-
function
|
|
683
|
-
wasm.
|
|
711
|
+
function wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
|
|
712
|
+
wasm.wasm_bindgen_eea6accdcfb85281___convert__closures_____invoke___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined___js_sys_8383356d580dd162___Function_fn_wasm_bindgen_eea6accdcfb85281___JsValue_____wasm_bindgen_eea6accdcfb85281___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
|
|
684
713
|
}
|
|
685
714
|
|
|
686
715
|
|
|
687
716
|
const __wbindgen_enum_GpuBufferBindingType = ["uniform", "storage", "read-only-storage"];
|
|
688
717
|
|
|
689
718
|
|
|
719
|
+
const __wbindgen_enum_GpuDeviceLostReason = ["unknown", "destroyed"];
|
|
720
|
+
|
|
721
|
+
|
|
690
722
|
const __wbindgen_enum_GpuPowerPreference = ["low-power", "high-performance"];
|
|
691
723
|
|
|
692
724
|
|
package/nano_rspow_web_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nano-rspow-web",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "WebGPU-accelerated Nano (XNO) Proof of Work generation in the browser using WebAssembly",
|
|
6
6
|
"keywords": [
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "cargo build -p nano-rspow-web --target wasm32-unknown-unknown --release && wasm-bindgen --target web --out-dir . ../target/wasm32-unknown-unknown/release/nano_rspow_web.wasm",
|
|
37
|
-
"test": "node --test recommendation.test.js"
|
|
37
|
+
"test": "node --test recommendation.test.js",
|
|
38
|
+
"test:browser": "npm run build && node --test tests/browser/*.test.mjs"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@openrai/nano-pow-contract": "^0.1.0"
|