Skip to content

build: opt-in no-threads flavour of the wallet (no SharedArrayBuffer, no COOP/COEP) - #34

Draft
danielgorgonha wants to merge 6 commits into
red-dev-inc:feat/nu7-portable-keysfrom
deegalabs:feat/no-threads-wallet
Draft

danielgorgonha wants to merge 6 commits into
red-dev-inc:feat/nu7-portable-keysfrom
deegalabs:feat/no-threads-wallet

Conversation

@danielgorgonha

Copy link
Copy Markdown

Changes

  • New opt-in cargo feature no-threads on webzjs-wallet: a build with no wasm_thread, no wasm-bindgen-rayon, no thread pool, no shared memory and no atomics, so a page served without COOP/COEP can load the wallet. The rayon crate stays in the graph with no features, because zcash_client_backend and zcash_client_memory depend on it; no pool is created. no-threads and wasm-parallel are mutually exclusive (compile_error!).
  • sync and create_proposed_transactions now have two versions. With wasm-parallel they are unchanged. Without it they await their work in the caller's context instead of spawning a wasm_thread worker, so the caller should host the WebWallet in its own Worker. Behaviour change: a build with wasm and no wasm-parallel used to spawn wasm_thread workers and now takes the caller-context path. just build-wallet always passes wasm-parallel. Also in this flavour, a panic during sync aborts the module (no worker to contain it).
  • multicore is opt-in per crate instead of forced by the workspace (default-features = false on zcash_primitives and zcash_client_memory, multicore dropped from the zcash_proofs line, a multicore feature on webzjs-common and webzjs-keys, on by default, and webzjs-requests asking for it directly). The default build enables the same third-party features as before (checked with cargo tree on the earlier base c045717). Only the default marker features of zcash_primitives and zcash_client_memory leave the graph, with the same members.
  • just build-wallet-single builds the no-threads package (packages/webzjs-wallet-single). just check-no-threads (scripts/check-no-threads.sh) checks the graph and, given a .wasm, that it has no shared memory and no atomic instruction. A CI job runs the graph check and a type-check of the flavour.

Tests

just check-no-threads
cd crates/webzjs-wallet && RUSTFLAGS="" cargo check --lib --target wasm32-unknown-unknown --no-default-features --features "wasm no-threads"
just build-wallet-single && scripts/check-no-threads.sh packages/webzjs-wallet-single/webzjs_wallet_bg.wasm

What we ran, and on which base:

  • On this branch (9ad0a58): the graph check passes, and the flavour type-checks for wasm32 with the repo's .cargo/config.toml flags. The RUSTFLAGS="" line above is the CI step's and was not run locally.
  • On the earlier base c045717 (2026-11-09, before the review fixes): the graph check fails without the change (no no-threads feature; on the threaded graph it lists wasm_thread, wasm-bindgen-rayon and 17 thread-pool features) and passes with it. We built both flavours. The threaded package had the same exports, imports, memory and .d.ts as the base, and the same JS glue after closure renumbering, but not the same bytes. The single package had no shared memory and no atomics. The threaded package was not rebuilt after the review fixes or the rebase.
  • Also on c045717 before the review fixes: headless Chromium, a local gRPC-web proxy, the wallet in a module Worker, the page served without COOP/COEP (crossOriginIsolated false). sync() on a new account with a birthday 100 blocks below the tip logged "Scanning ChainTip(...)" and did not return in 12 minutes, with no error or panic and the page still responsive. The cause is in zcash_client_backend: scan_cached_blocks hangs on wasm32 without atomics (rayon::spawn_fifo with no thread pool) zcash/librustzcash#3270. With the inline change proposed there patched in locally, sync() returned (one run, an account with no notes, built without wasm-opt; the scan then occupies the Worker). Not rerun on 9ad0a58.

Not checked: spending in the no-threads build; a sync with an account that has notes; the CI job itself (not run); clippy on the pinned nightly; the snap and its keys .wasm; a build on stable rustc.

Issues

🤖 Generated with Claude Code

…pace

zcash_primitives, zcash_proofs and zcash_client_memory pulled `multicore`
(rayon) through their default features or a hard-set feature, so no crate
could switch it off. Take them without it at the workspace level and add a
`multicore` feature to webzjs-common and webzjs-keys (default on).
webzjs-requests and `just build-keys` ask for it explicitly, so those builds
resolve the same third-party features as before.

Assisted-by: Claude Code
`no-threads` builds the wasm wallet without wasm_thread, the rayon pool and
wasm-bindgen-rayon, so it needs no SharedArrayBuffer. `sync` and
`create_proposed_transactions` then run in the caller's context instead of a
spawned worker. The `wasm-parallel` build keeps the same code path as before.

- `multicore` now forwards to webzjs-keys and webzjs-common, and no longer
  rides on the zcash_proofs dependency line.
- `wasm_thread` and `rayon` are optional and enabled by `wasm-parallel` only.
- `no-threads` and `wasm-parallel` together fail with `compile_error!`.

Assisted-by: Claude Code
`build-wallet-single` builds the `no-threads` flavour with RUSTFLAGS="" (so
the atomics flags in .cargo/config.toml are not applied), without -Z build-std
and without add-worker-module.sh. `scripts/check-no-threads.sh` fails if the
no-threads graph has wasm_thread, wasm-bindgen-rayon or any multicore/threads
feature, and, given a built .wasm, if it has shared memory or atomics. CI runs
the graph part.

Assisted-by: Claude Code
…eads build

The no-threads path used unwrap_throw, so a failure became a raw JS throw that
skips destructors and loses the error. Use `?` like the rest of the file, so
the caller gets the same Err as in the threaded build. Also say in the
WebWallet and sync docs that the no-threads build runs in the caller's context
and cannot report a panic as an Error.

Assisted-by: Claude Code
wasm-pack names both packages after the crate, and yarn refuses two
workspaces with the same name, which broke every yarn command once the single
build had run. Rename the generated package.json in `build-wallet-single`.

Assisted-by: Claude Code
… threads proposal

- CI job `no-threads` also runs `cargo check` of the wasm32 no-threads build.
- check-no-threads.sh uses `wasm-tools validate --features=-threads`, which
  also rejects atomic.fence and no longer loads the whole module as text; the
  failure message shows the overridden FEATURES.
- README: say that `wasm` without `wasm-parallel` now behaves like no-threads,
  and name the single package.

Assisted-by: Claude Code
@danielgorgonha

Copy link
Copy Markdown
Author

In the threaded build, sync() and create_proposed_transactions() start with assert!(!thread::is_web_worker_thread()) (bindgen/wallet.rs:294 and :437 on this branch, under wasm-parallel; the same asserts are at :275 and :376 on main). I ran sync() from a Worker on this branch's head (1a9c3ac).

How I ran it. Both builds come from this branch with the justfile commands, loaded in Chromium through Playwright, inside a dedicated Worker, with a local gRPC-web proxy to a public mainnet lightwalletd and a throwaway view key that holds no funds. The threaded build ran on a cross-origin-isolated page. Chromium was 151.0.7922.34 and playwright-core 1.65.1. The program and its output are in https://github.com/deegalabs/WebZjs/tree/2fdafadb0e32003f645c5ff9d717be20169f9bec/repro/worker-assert.

  1. In the threaded build, sync() called from the Worker panics at bindgen/wallet.rs:294:9 with assertion failed: !thread::is_web_worker_thread(). The Worker gets Uncaught RuntimeError: unreachable, and the call does not return an Error. I did not run create_proposed_transactions(), because it takes a Proposal, which needs a funded wallet. Its assert at :437 is read from the code.
  2. main builds with panic_abort (justfile:10), so the panic is a wasm trap. Reuse one web worker for every sync instead of spawning per call #6 shows a wallet that hung after a trap, from another cause.
  3. The assert is compiled only under wasm-parallel, so the no-threads flavour has none. In that build, in a Worker, sync() does not trap. It starts scanning. The log ends at a scan with no trap, and the run's 270 s deadline passed without a return, which is the longest the run waited. This matches scan_cached_blocks hangs on wasm32 without atomics (rayon::spawn_fifo with no thread pool) zcash/librustzcash#3270, as this PR's description says.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant