Repository navigation
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
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three self-contained commits against
main(a50df94), each one usable on its own:get_transaction_history. It tookdb.read()and, while holding it, calledget_wallet_summary(), which takesdb.read()again. tokio'sRwLockis write-preferring, so ifsyncasks 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).WebWallet.sync_progress().Wallet::syncholds the database write lock for the whole pass, soget_wallet_summarycannot answer until the pass ends and a UI has no way to show progress. ABlockCachewrapper (src/progress.rs) counts blocks aszcash_client_backend::sync::runmoves them throughinsert(downloaded), the scanner's first walk (visited) and the next batch's insert (scanned/committed).sync_progress()reads only atomics, so it answers whilesyncholds the lock. Addsasync-traitto webzjs-wallet's dependencies (already inCargo.lockthroughzcash_client_memory).pczt_create.pczt_create(account_id, to_address, value, memo?): UTF-8, at most 512 bytes (ZIP 302,Error::MemoTooLongotherwise). A memo to an address that cannot receive one (transparent, TEX, or a UA with only a transparent receiver) fails withError::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) andcargo check --no-default-features --features="wasm-parallel,no-bundler" --target=wasm32-unknown-unknown(thejust checkandjust check-wasmrecipes) pass at each of the three commits, with the repository's pinned toolchain (nightly-2025-01-07) and no new warnings.Context: NU6.3 (Ironwood) and NU7
mainstill builds againstChainSafe/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'spatches/webzjs/(0003,0004) together with a port ofzcash_client_memory(engine/zcash_client_memory, with its origin inUPSTREAM.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, orzcash_client_memoryinto your librustzcash fork first) and I'll prepare it.🤖 Generated with Claude Code