Repository navigation
Description
pczt_send checks that the wallet is synced before broadcasting, but the value it compares with the server's tip is chain_height(), not the scanned height:
WebZjs/crates/webzjs-wallet/src/wallet.rs
Line 772 in 317d790
| let fully_scanned = db_read.chain_height()?; |
(wallet.rs:897 at 9ad0a58, the head of #27.) WalletRead::chain_height is "the height of the chain as known to the wallet as of the most recent call to update_chain_tip", and sync::run calls update_chain_tip at the start, before scanning. So once a sync has started, chain_height() is the tip whether or not the blocks below it were scanned, and the "blocks behind" check passes.
The same value decides whether to sync first in pczt_shield (
WebZjs/crates/webzjs-wallet/src/wallet.rs
Line 479 in 317d790
| let wallet_height = self.db.read().await.chain_height()?; |
pczt_create (WebZjs/crates/webzjs-wallet/src/wallet.rs
Line 612 in 317d790
| let wallet_height = self.db.read().await.chain_height()?; |
pczt_sweep. The web wallet relies on these checks (usePCZT.ts: "Rust's pczt_shield/pczt_send handle sync validation internally ... so no JS-layer pre-check required"). #18 changes how sync runs but keeps this check as it is.
When this matters: any sync() that stops partway. Two cases, run natively against the crates #27 pins (zcash_client_backend 0.25.0, zcash_client_memory b4c8f0d) with a fake lightwalletd, birthday 3,500,000, tip 3,524,999:
GetBlockRangefails partway through the second range (sync()returns an error):chain_height3,524,999,fully_scanned_height3,509,999.- The server ends the first range early with an OK status (
sync()returnsOk):chain_height3,524,999,fully_scanned_height3,500,499.
In both, a check against chain_height() sees 0 blocks behind, while the fully scanned height is 15,000 and 24,500 blocks below the tip (in the second case 9,500 blocks are unscanned, in a gap below blocks that were scanned). On main the pins differ (zcash_client_backend 0.24.0-rc.1 at librustzcash 0a2c6d1), but chain_height and update_chain_tip read the same there; I ran only the #27 pins. I did not run WebZjs itself; that the check passes is read from the code plus the values above. What I expect it to cause, also not tested: the sync these functions promise is skipped, so a transaction is built from a partly scanned wallet.
Suggestion: compare against the fully scanned height instead, for example db.block_fully_scanned()?.map(|m| m.block_height()), or fully_scanned_height() from get_wallet_summary, in all four places. Until then, a caller can check fully_scanned_height < chain_tip_height from get_wallet_summary() itself. Happy to send a small PR if you agree with the approach.
🤖 Generated with Claude Code
Activity
danielgorgonha commentedon Nov 24, 2026
The program behind the two cases above: https://github.com/deegalabs/WebZjs/tree/a8ca70f8260975094b3a2006706a74da12b4d831/repro/chain-height-check
Native, no browser, no network. It runs
sync::runagainst a fake lightwalletd (an in-process tower service), with the crates and heights from the issue and empty blocks. Each case runs a second sync against an honest server after the first.git clone https://github.com/deegalabs/WebZjs && cd WebZjs && git checkout a8ca70f8260975094b3a2006706a74da12b4d831 && cd repro/chain-height-checkcargo run --release --locked -- B: the firstGetBlockRangeends after 500 of 10,000 blocks with an OK status. Undersync #1:run() -> Ok(()), thenchain_height Some(BlockHeight(3524999)) block_fully_scanned Some(BlockHeight(3500499)).cargo run --release --locked -- E: the secondGetBlockRangesends 300 blocks, then grpc-status 11. Undersync #1:run() -> Err(...)ending inout of range, thenchain_height Some(BlockHeight(3524999)) block_fully_scanned Some(BlockHeight(3509999)).So the wallet is 24,500 (B) and 15,000 (E) blocks behind, and a check against
chain_height(), like the one inpczt_send,pczt_shieldandpczt_create, sees 0. In both casessync #2fills the gap.🤖 Generated with Claude Code