Skip to content

Commit 68e2c7a

Browse files
committed
merge fixes for thread issue
2 parents abb55b2 + fa1d590 commit 68e2c7a

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ path = "examples/simple-sync.rs"
2020
name = "message-board-sync"
2121
path = "examples/message-board-sync.rs"
2222

23-
2423
[profile.release]
2524
# Tell `rustc` to optimize for small code size.
2625
opt-level = 3
@@ -41,8 +40,7 @@ wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"]
4140
native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"]
4241
sqlite-db = ["dep:zcash_client_sqlite"]
4342
console_error_panic_hook = ["dep:console_error_panic_hook"]
44-
no-bundler = ["wasm-bindgen-rayon?/no-bundler"]
45-
43+
no-bundler = ["wasm-bindgen-rayon?/no-bundler", "wasm_thread/no-bundler"]
4644
sync2 = []
4745

4846
[dependencies]
@@ -95,7 +93,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
9593
tracing = "0.1.40"
9694
rayon = { version = "1.8", features = ["web_spin_lock"] }
9795
subtle = "2.6.1"
98-
wasm_thread = { git = "https://github.com/WilsonGramer/wasm_thread.git", rev = "eb41bcc0d98ce0620a313687c0344341391b9d78", default-features = false, features = ["keep_worker_alive"] }
96+
wasm_thread = { git = "https://github.com/ec2/wasm_thread", rev = "eb41bcc0d98ce0620a313687c0344341391b9d78", default-features = false, features = ["keep_worker_alive", "es_modules"] }
9997

10098
wasm_sync = "0.1.2"
10199
http = { version = "1.1.0", default-features = false }
@@ -119,7 +117,6 @@ wasm-bindgen-rayon = { git = "https://github.com/9SMTM6/wasm-bindgen-rayon", rev
119117
shardtree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" }
120118
incrementalmerkletree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" }
121119

122-
123120
#[patch.'https://github.com/chainsafe/librustzcash']
124121
#zcash_address = { path = "../librustzcash/components/zcash_address" }
125122
#zcash_client_backend = { path = "../librustzcash/zcash_client_backend" }

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
default:
22
just --list
33

4-
build:
5-
wasm-pack build --target web --scope webzjs --release --out-dir ./packages/webz-core --no-default-features --features="wasm-parallel,sync2" -Z build-std="panic_abort,std"
4+
build *features:
5+
wasm-pack build --no-opt -t web --scope webzjs --release --out-dir ./packages/webz-core --no-default-features --features="wasm wasm-parallel sync2 {{features}}" -Z build-std="panic_abort,std"
66

77
# All Wasm Tests
88
test-web *features:

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
{
22
"scripts": {
33
"preinstall": "npx only-allow pnpm",
4+
<<<<<<< HEAD
45
"start:dev": "parcel --no-autoinstall packages/demo-wallet",
56
"build": "parcel build --no-cache --no-autoinstall packages/demo-wallet"
7+
=======
8+
"start:dev": "pnpm --stream -r run start:dev",
9+
"build": "parcel build --no-autoinstall --no-cache packages/demo-wallet"
10+
>>>>>>> fa1d590219078a46ae59c0e85e0207362217b311
611
},
712
"dependencies": {
8-
"@webzjs/webz-core": "workspace:^",
9-
"@webzjs/demo-wallet": "workspace:^"
10-
},
13+
"@webzjs/webz-core": "workspace:^",
14+
"@webzjs/demo-wallet": "workspace:^"
15+
},
1116
"devDependencies": {
1217
"@parcel/core": "^2.12.0",
1318
"parcel": "^2.12.0",
1419
"process": "^0.11.10"
15-
}
20+
},
21+
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
1622
}

src/bindgen/wallet.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,26 @@ impl WebWallet {
136136

137137
/// Synchronize the wallet with the blockchain up to the tip using zcash_client_backend's algo
138138
pub async fn sync2(&self) -> Result<(), Error> {
139-
tracing::info!("Sync2 called");
140-
let db = self.inner.clone();
141-
142-
let shim_url = thread::get_wasm_bindgen_shim_script_path();
139+
assert!(!thread::is_web_worker_thread());
143140

144-
tracing::info!("shim script path: {}", shim_url);
145-
tracing::info!(
146-
"worker script: {}",
147-
thread::get_worker_script(Some(shim_url.clone()))
148-
);
141+
let db = self.inner.clone();
149142

150-
let main_handler = thread::Builder::new()
143+
let sync_handler = thread::Builder::new()
144+
.name("sync2".to_string())
151145
.spawn_async(|| async {
152-
tracing::info!("Sync2 thread spawned");
146+
assert!(thread::is_web_worker_thread());
147+
tracing::debug!(
148+
"Current num threads (wasm_thread) {}",
149+
rayon::current_num_threads()
150+
);
151+
153152
let db = db;
154-
db.sync2().await;
153+
db.sync2().await.unwrap_throw();
155154
})
156-
.unwrap()
155+
.unwrap_throw()
157156
.join_async();
158-
main_handler
159-
.await
160-
.map_err(|_| Error::SyncError("awaiting on main handler failed".to_string()))
157+
sync_handler.await.unwrap();
158+
Ok(())
161159
}
162160

163161
pub async fn get_wallet_summary(&self) -> Result<Option<WalletSummary>, Error> {

tests/simple-sync-and-send.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn initialize() {
2424
async fn test_get_and_scan_range() {
2525
initialize();
2626
#[cfg(feature = "wasm-parallel")]
27-
let _ = JsFuture::from(wasm_bindgen_rayon::init_thread_pool(10)).await;
27+
let _ = JsFuture::from(wasm_bindgen_rayon::init_thread_pool(3)).await;
2828
assert!(!thread::is_web_worker_thread());
2929
let w = WebWallet::new("test", "http://localhost:1234/testnet", 1).unwrap();
3030

0 commit comments

Comments
 (0)