Skip to content

webzjs-wallet: fix a read-lock deadlock in get_transaction_history; add sync_progress() and an optional memo in pczt_create - #169

Open
Kubudak90 wants to merge 3 commits into
ChainSafe:mainfrom
Kubudak90:feat/sync-progress-memo
Open

Kubudak90 wants to merge 3 commits into
ChainSafe:mainfrom
Kubudak90:feat/sync-progress-memo

Conversation

@Kubudak90

Copy link
Copy Markdown

Summary

Three self-contained commits against main (a50df94), each one usable on its own:

  1. fix: nested read lock in get_transaction_history. It took db.read() and, while holding it, called get_wallet_summary(), which takes db.read() again. tokio's RwLock is write-preferring, so if sync asks for the write lock between the two reads, the second read queues behind the writer, the writer waits for the first guard, and every later wallet call hangs. The fix reuses the guard that is already held (5 lines).
  2. feat: WebWallet.sync_progress(). Wallet::sync holds the database write lock for the whole pass, so get_wallet_summary cannot answer until the pass ends and a UI has no way to show progress. A BlockCache wrapper (src/progress.rs) counts blocks as zcash_client_backend::sync::run moves them through insert (downloaded), the scanner's first walk (visited) and the next batch's insert (scanned/committed). sync_progress() reads only atomics, so it answers while sync holds the lock. Adds async-trait to webzjs-wallet's dependencies (already in Cargo.lock through zcash_client_memory).
  3. feat: optional text memo in pczt_create. pczt_create(account_id, to_address, value, memo?): UTF-8, at most 512 bytes (ZIP 302, Error::MemoTooLong otherwise). A memo to an address that cannot receive one (transparent, TEX, or a UA with only a transparent receiver) fails with Error::UnsupportedMemoRecipient, as ZIP 321 requires. An empty string is the same as no memo, and three-argument callers keep the old behaviour. The request is now built before the chain-tip check and the inline sync, so an invalid memo or recipient is rejected at once. A step towards [feature] Support payment URIs #121 (payment URIs can ask for a memo).

Happy to split this into three PRs if you prefer.

Testing

  • cargo check (native) and cargo check --no-default-features --features="wasm-parallel,no-bundler" --target=wasm32-unknown-unknown (the just check and just check-wasm recipes) pass at each of the three commits, with the repository's pinned toolchain (nightly-2025-01-07) and no new warnings.
  • These changes come from Celari, an open-source browser wallet built on WebZjs. There they run in production on top of further patches (below), with real mainnet sends, memos and shielding. On this branch, by themselves, they were only compile-checked as above.

Context: NU6.3 (Ironwood) and NU7

main still builds against ChainSafe/librustzcash-nu61 (NU6.1), so it does not follow mainnet's consensus rules after Ironwood (block 3,428,143) and NU7 (block 3,543,405); #168 may be one symptom of that. Celari has a port of WebZjs to the librustzcash crates of 2026-10 from crates.io (NU6.2, NU6.3 Ironwood, NU7): Ironwood balances, spends and change, v6 transactions, the NU7 activation-boundary rules, and native tests against real mainnet blocks. It is in Celari's patches/webzjs/ (0003, 0004) together with a port of zcash_client_memory (engine/zcash_client_memory, with its origin in UPSTREAM.md). It is large and moves WebZjs off the fork, so I did not include it here. If you want it upstream (#122), tell me how you would like to receive it (one PR, a series, or zcash_client_memory into your librustzcash fork first) and I'll prepare it.

🤖 Generated with Claude Code

Kubudak90 and others added 3 commits November 25, 2026 15:43
get_transaction_history took `db.read()` and, while holding it, called
`get_wallet_summary()`, which takes `db.read()` again. tokio's RwLock is
write-preferring: if `sync` asks for the write lock between the two reads,
the second read queues behind the writer, the writer waits for the first
read guard, and every later wallet call hangs.

Reuse the guard that is already held.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011GduadamEoKaPUqWNNM5M3
Wallet::sync holds the database write lock for the whole pass, so
get_wallet_summary cannot answer until the pass ends and a UI has no way
to show progress. A BlockCache wrapper (src/progress.rs) counts blocks as
zcash_client_backend::sync::run moves them through `insert` (downloaded),
the scanner's first walk (visited) and the next batch's insert (scanned,
i.e. committed). `sync_progress()` only reads atomics, so it answers
immediately while `sync` holds the lock.

Adds async-trait to webzjs-wallet's dependencies (already in Cargo.lock
through zcash_client_memory).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011GduadamEoKaPUqWNNM5M3
WebWallet.pczt_create(account_id, to_address, value, memo?) takes an
optional UTF-8 text memo for the recipient. It is encoded as ZIP 302
MemoBytes (at most 512 bytes; longer text fails with Error::MemoTooLong)
and the payment is built with zip321::Payment::new, which returns None for
a memo to an address that cannot receive one (transparent P2PKH/P2SH, TEX,
or a unified address with only a transparent receiver); that fails with
Error::UnsupportedMemoRecipient, as ZIP 321 requires. An empty string is
the same as no memo, and callers that pass three arguments keep the old
behaviour (Payment::without_memo).

The request is now built before the chain-tip check and the inline sync in
pczt_create, so an invalid memo or recipient is rejected at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011GduadamEoKaPUqWNNM5M3

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