Change read JS bindings
- Lingua principale
- TypeScript
- Stelle
- 1
- Fork
- 21
- Merge medio
- 12h 14m
- PR unite (30g)
- 41
Descrizione
A lot of WASM read bindings take `&mut self` unnecessarily, which forces serialization of concurrent reads. The read bindings in `crates/web-client/src` are declared `&mut self` even though the underlying rust-client methods only need `&self`: `get_account`, `get_accounts`, `get_account_vault`, `get_account_storage`, `get_account_code`, and `get_sync_height`. The corresponding methods on `Client` are all `&self`. The wrappers just reach for `get_mut_inner()` when a `get_inner()` would compile. On an async `#[wasm_bindgen]` fn, `&mut self` causes `wasm-bindgen` to take an exclusive borrow that is held across every await. Two concurrent reads collide on that borrow and panic with "recursive use of an object detected".
PR 0xMiden/miden-client#2057 worked around this at the JS level by serializing every async call through a chain but in that sense I believe the fix was not complete: The cost is that every read now waits for every write, even though reads don't actually need exclusive access. cc @WiktorStarczewski
We should flip the read bindings listed above from `&mut self`/`get_mut_inner()` to `&self`/`get_inner()` and check for any other similar occurrences across the codebase
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
The issue points to the `crates/web-client/src` directory. Look for the listed methods (`get_account`, `get_accounts`, etc.) in the Rust code, identified by their `#[wasm_bindgen]` attribute. Change their `&mut self` parameters to `&self` and update the internal calls from `get_mut_inner()` to `get_inner()`. Then, search the codebase for other `&mut self` bindings on read-only methods. Test by building the WASM and ensuring concurrent async calls no longer panic.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust, typescript, wasm
- Ambito
- api, backend
- Tipo di issue
- Refactoring
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 65/100