Skip to content

JS cannot read sync progress, and a read during a sync waits until the sync ends #37

Backlog

Description

@danielgorgonha

A page can read the chain tip and the scanned height, both from the wallet summary, and no progress value. While sync() runs it cannot read the summary at all. The server's tip stays readable through get_latest_block, which takes no lock (bindgen/wallet.rs:604-610). I ran the lock behaviour at the head of #27 (9ad0a58) and read the same code on main (317d790).

How I ran it. A native harness calls the inner Rust Wallet methods that the wasm bindings wrap, over native tonic, against a public mainnet lightwalletd, at #27's head (it pins zcash_client_backend 0.25.0; main requires 0.24.0-rc.1). The key is a throwaway view key that holds no funds. The harness reads the tip through a new client on a clone of the same Channel, because the client field is pub(crate). The bindings and the browser transport were not exercised. The program and its output are in https://github.com/deegalabs/WebZjs/tree/409ce5a294db0a196a24e446f7687621bc9f3677/repro/birthday-lock-stall. Notes 1, 2 and 4 and the Ironwood paragraph are read from the code.

  1. WalletSummary exposes chain_tip_height and fully_scanned_height. scan_progress is commented out (bindgen/wallet.rs:668-675 on main, :681-690 at Feat/nu7 portable keys #27).
  2. suggest_scan_ranges exists on the inner Wallet (wallet.rs:265) and has no #[wasm_bindgen] binding. sync() takes no progress callback.
  3. get_wallet_summary takes the read lock (wallet.rs:296-302). Wallet::sync holds the write lock until sync::run returns (wallet.rs:279-294). So the summary call waits for the end of the sync. A page cannot read the scanned height, and so cannot draw progress from the heights, while it runs. In 3 of 3 runs, with a 50,000-block sync running, get_wallet_summary returned 2 to 3 ms after sync() returned, having waited 30,081 to 35,736 ms. The tip read, an upper bound, answered in at most 18 to 58 ms.
  4. Bounded sync steps, instance ids, close and worker poisoning #18 releases the lock between batches (sync_step), so a read can run between steps. It leaves scan_progress commented out (bindgen/wallet.rs:914), and so does Resumable, checkpointed full resync driven by sync steps #19. Neither adds a progress value.

One thing to fix before a progress value is exposed. The store pinned in #27 computes it from Sapling and Orchard outputs only, with no Ironwood term (wallet_read.rs:354-375). Since NU6.3 a transaction cannot add value to the Orchard pool (ZIP 2006), so a payment to an Orchard receiver lands in the Ironwood pool, and the value would leave that pool out. main pins the same progress code.

Fix to consider. Publish progress from the sync loop to the page without taking the wallet lock, for example a callback or a value updated after each batch. An open pull request on the upstream repository, ChainSafe/WebZjs#169, describes the lock problem in note 3 and adds a sync_progress() read.

🤖 Generated with Claude Code

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions