Repository navigation
Conversation
Rust-Checks has failed on main since the NU6.3 toolchain bump: rustfmt differs in nine files, and clippy on nightly-2025-06-15 rejects ten uninlined format arguments in webzjs-keys and one map iteration in webzjs-requests under -D warnings. Apply rustfmt and clippy's own suggestions; no behaviour changes.
Leaving the wallet open on Account Summary crashed after roughly 75
minutes with:
panicked at sharded-slab-0.1.7/src/shard.rs:295:9:
Thread count overflowed the configured max count.
Thread index = 128, max threads = 128.
followed by `RuntimeError: unreachable`, after which the wallet hung.
`WebWallet::sync` spawned a fresh web worker for every call, and the
periodic rescan calls it every 35 seconds. The tracing registry stores
spans in a sharded slab that allows 128 thread slots on wasm32; a thread
takes a slot the first time it creates a span (block scanning does) and
gives it back only from its thread-local destructor. Those destructors
never run here: wasm_thread is built with `keep_worker_alive`, so
finished workers are not closed at all, and closing a worker skips Rust
thread-local drops anyway. So every sync consumed one slot for good, and
sync number 129 panicked. The idle workers also kept their stacks and
thread-local storage, so memory grew per sync as well.
Run all syncs on a single long-lived worker, created on first use and
fed through a channel. Requests run one at a time, which the JS caller
already enforces with its sync-in-progress guard.
A trap inside the worker (a Rust panic compiled to wasm) is not recovered
from: the trapped call never resolves and later syncs wait behind it until
the page is reloaded. That was already the case with a worker per call, which
held the wallet lock forever after a trap.
The shared sync worker uses tokio::sync::{mpsc, oneshot}, which only compiled
because another dependency happened to enable the feature.
A Full Resync from an early birthday (for example 2,600,000) crashed the sync worker with `RuntimeError: unreachable` after a few 10,000-block batches, and the wallet UI hung afterwards. MemBlockCache::delete in zcash_client_memory was a lazy `async fn`, and zcash_client_backend::sync::run only awaits the returned futures once the whole sync has finished, so every downloaded compact block stayed in the cache for the entire sync. The browser caps wasm memory at 1 GiB and the allocation failure traps without a panic message. Point zcash_client_memory at a revision that removes the blocks when `delete` is called, and that also prunes the nullifier map below the fully scanned height as zcash_client_sqlite does, so a historic sync no longer keeps every on-chain nullifier in memory for the life of the wallet. Measured natively, syncing 800k blocks (2.6M to tip, batch 10,000): peak heap 2,039 MiB before, 524 MiB with the eager delete, 383 MiB with the pruning as well.
Since NU6.3, payments to shielded addresses and the shielded change of shielding transactions are delivered through the Ironwood pool, and this is where a wallet's shielded funds live from then on. zcash_client_memory did not track that pool, so every such transaction failed at creation with ProposalNotSupported, and Ironwood funds were invisible. Move the zcash_client_memory pin to the fork revision that tracks the Ironwood pool (its own commitment tree, notes, nullifiers, balances and serialization), and make the two wallet-side changes that depend on it: - pczt_prove proves the Ironwood bundle as well as the Orchard one. The two bundles share the circuit and proving key; without the second proof, extraction rejects every post-NU6.3 payment to a shielded address. - The wallet summary reports the Ironwood balance, and the web wallet counts it as shielded funds in the balance hook and the snap balance cache. Verified on mainnet: a payment from legacy Orchard notes to the wallet's own unified address, which the backend routes through Ironwood, built, signed in the snap, proved and broadcast, and the resulting Ironwood note was scanned. Both pins move together with this commit: zcash_client_memory to the fork revision that exposes spend records and change flags for history queries, and every librustzcash crate to sqhell/librustzcash, which is the previous pin (0a2c6d1) plus the upstream fix that records Ironwood outputs when a transaction is extracted from a PCZT. Without the latter, a payment to a shielded address signed through the snap left no sent record at all, and the history later showed only its change as a receipt.
23ceba7 to
8d808e8
Compare
8d808e8 to
1d33ffc
Compare
…uning The pinned revision is the head of the zcash_client_memory PR stack: the Ironwood pool on top of the nullifier-map pruning tests, then strict decode, loud encode, the dirty flag, the rewind nullifier fix and block pruning that the resync and persistence work was tested against.
`sync::run_step` lives on the fork's snap/0a2c6d1-ironwood-step-sync branch, on top of the Ironwood PCZT extraction fix already pinned. The pinned revision includes the follow-up that keeps Verify ranges out of the step budget, so a step always scans a full batch.
Wallet::sync used to take the wallet write lock once and run zcash_client_backend::sync::run over every batch, so a historic resync held the lock for the whole scan and could not be persisted or stopped part way. Build the sync out of sync::run_step instead: - Wallet::sync_step(first) refreshes the chain tip, fetches and scans at most one batch, releases the write lock and reports whether more work remains. The first step refreshes the subtree roots; later steps skip that round trip. - Wallet::sync is now a loop over sync_step, so existing callers keep working but the lock is released between batches. - Every Wallet carries an instance_id (a process-local counter plus a random suffix) and a closed flag shared by its clones. close() makes sync, sync_step, db_to_bytes, account creation, proposal, signing and the pczt_* and send paths fail with the new Error::InstanceClosed, so a sync loop driving an instance the page has replaced stops at the next batch boundary instead of writing into a stale wallet. - Error::SyncWorkerUnavailable is added for the bindings to report a sync worker that has trapped. BATCH_SIZE drops from 10000 to 2500 so a single step takes minutes, not up to an hour, on a historic resync. The trade-off is more round trips to lightwalletd in exchange for smaller memory peaks and shorter lock holds.
…soning
The shared sync worker ran only Wallet::sync, with no way to tell one
wallet instance from another, stop an instance, or recover once the
worker trapped.
- SyncRequest carries a SyncKind (Full or Step { first }) and replies
with the "more work remains" flag; the worker dispatches to
Wallet::sync or Wallet::sync_step accordingly. A closed instance is
reported back as Error::InstanceClosed rather than a flattened string.
- WebWallet gains sync_step(first): Promise<boolean>, the instance_id
getter, close() and is_closed(). sync(): Promise<void> is unchanged
for existing callers.
- A trap inside the worker is a wasm RuntimeError the library cannot
observe. The new free function report_sync_worker_trap() lets the
page's window error handler poison the worker: every in-flight call
is released and every later sync / sync_step rejects with
Error::SyncWorkerUnavailable at once instead of queueing behind the
dead worker. The sync doc comment explains the handshake.
- Requests from a closed instance are refused before they are queued.
Each sync step pays for a chain tip refresh, a UTXO refresh and a tree state fetch before scanning. At 2500 blocks per batch that overhead was paid four times as often as before the step-wise sync, for no gain in peak memory worth the cost. Back to the batch size the one-shot sync used.
1d33ffc to
53a47ed
Compare
|
One case #18 does not cover is a stall inside one batch. I reproduced it natively at #18's head (53a47ed) and at the head of #27 (9ad0a58). How I ran it. A native harness calls the inner Rust
A deadline sized to one batch, inside the client or around 🤖 Generated with Claude Code |
What
Wallet::sync_step(first)refreshes the chain tip, scans at most one batch, releases the write lock and reports whether more work remains;Wallet::syncis a loop over it. Built onzcash_client_backend::sync::run_stepfrom the pinned fork (sqhell/librustzcashbranchsnap/0a2c6d1-ironwood-step-sync: the pinned 0a2c6d1 plus the extraction fix plusrun_step).Wallethas aninstance_idand aclose()switch; a closed instance fails sync, persistence, proposal and signing withError::InstanceClosed, so a loop driving a replaced instance stops at the next batch boundary.WebWalletgainssync_step,instance_id,close,is_closed; the shared sync worker dispatches full syncs and steps.report_sync_worker_trap()lets the page's error handler poison a trapped worker so later calls reject withSyncWorkerUnavailableinstead of queueing forever.Why
Wallet::synctook the write lock once and ran the whole scan, so a historic resync could not be persisted or stopped part way, and hours of scanning lived only in memory. The fork'srun_stepkeeps the verification of the chain-tip view out of the step budget, so every step scans a full batch; an earlier draft charged the 10-blockVerifylookahead to the budget and crawled at 10 blocks per step.Stack
Position 14 of 15 in the WebZjs release order, to be merged in this order into
main. Builds on #15 (feat/ironwood-pool), #6 (fix/reuse-sync-worker). GitHub shows the whole stack againstmainuntil those merge; the commits of this PR alone are here: sqhell/WebZjs@feat/ironwood-pool...feat/resumable-sync (that view also includes the merge offix/reuse-sync-worker).chore/rust-checksfix/reuse-sync-workerfix/grpc-web-trailers-onlyfix/resync-dialogfeat/send-againfix/pczt-parse-errorfix/sign-change-paired-spendsfix/historic-sync-oomfeat/history-resync-hintfix/wallet-store-epochsfeat/ironwood-poolfix/history-from-spendsfeat/wallet-statsfeat/resumable-sync(this PR)feat/resync-resumeRust pins reference
sqhell/zcash_client_memoryandsqhell/librustzcashby revision so CI builds exactly what was tested; once the zcash_client_memory stack (red-dev-inc/zcash_client_memory #16 to #21) merges, the memory pin goes back tored-dev-inc/zcash_client_memoryfeat/snap-nu63. The integration branchtest/all-fixeson the fork merges all fourteen and is the build that was tested end to end.Tests