Skip to content

Commit cc15183

Browse files
committed
Enable multicore on zcash deps
1 parent d621bc6 commit cc15183

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ license = "MIT OR Apache-2.0"
66
repository = "https://github.com/ChainSafe/WebZjs"
77
description = "A browser client-side library for implementing Zcash wallets"
88
edition = "2021"
9+
resolver = "2"
10+
911

1012
[lib]
1113
crate-type = ["cdylib", "rlib"]
@@ -20,17 +22,17 @@ codegen-units = 1
2022
wasm-opt = ["-O4", "-O4"]
2123

2224
[features]
23-
default = ["native"]
25+
default = ["native", "multicore"]
2426

2527
native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots"]
26-
wasm-parallel = ["wasm", "wasm-bindgen-rayon"]
27-
wasm = ["console_error_panic_hook", "dep:tracing-web"]
28+
multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_client_memory/multicore"]
2829

30+
# WASM specific features
31+
wasm = ["console_error_panic_hook", "dep:tracing-web", "zcash_client_backend/wasm-bindgen"]
32+
wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"]
2933
console_error_panic_hook = ["dep:console_error_panic_hook"]
30-
3134
no-bundler = ["wasm-bindgen-rayon?/no-bundler"]
3235

33-
3436
[dependencies]
3537
## Web dependencies
3638
wasm-bindgen = "0.2.84"
@@ -46,20 +48,19 @@ tonic-web-wasm-client = "0.6.0"
4648

4749
## Zcash dependencies
4850
zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
49-
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96", default-features = false, features = ["lightwalletd-tonic", "wasm-bindgen"] }
51+
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96", default-features = false, features = ["lightwalletd-tonic"] }
5052
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96", features = ["orchard"] }
5153
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96" }
5254
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96" }
5355
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "a77e8a0204dab421fdbf5822e585716339567b96", default-features = false, features = ["bundled-prover"] }
5456

57+
5558
## gRPC Web dependencies
5659
prost = { version = "0.12", default-features = false }
5760
tonic = { version = "0.12", default-features = false, features = [
5861
"prost",
5962
] }
6063

61-
62-
6364
getrandom = { version = "0.2", features = ["js"] }
6465
thiserror = "1.0.63"
6566
indexed_db_futures = "0.5.0"
@@ -72,7 +73,7 @@ nonempty = "0.7"
7273
hex = "0.4.3"
7374
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
7475
tracing = "0.1.40"
75-
76+
rayon = "1.8"
7677

7778
[dev-dependencies]
7879
wasm-bindgen-test = "0.3.42"

tests/tests.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use wasm_bindgen_futures::JsFuture;
21
use wasm_bindgen_test::*;
32

43
use webz_core::{bindgen::wallet::WebWallet, Wallet};
@@ -11,6 +10,8 @@ const SEED: &str = "visit armed kite pen cradle toward reward clay marble oil wr
1110
const HD_INDEX: u32 = 0;
1211
const BIRTHDAY: Option<u32> = Some(2577329);
1312

13+
const THREADS: usize = 5;
14+
1415
// Required to initialize the logger and panic hooks only once
1516
use std::{num::NonZeroU32, sync::Once};
1617
static INIT: Once = Once::new();
@@ -19,12 +20,21 @@ pub fn initialize() {
1920
webz_core::init::start();
2021
});
2122
}
23+
#[cfg(all(feature = "wasm-parallel"))]
24+
async fn init_threadpool(threads: usize) -> wasm_bindgen_futures::JsFuture {
25+
tracing::info!("Initializing thread pool with {} threads", threads);
26+
wasm_bindgen_futures::JsFuture::from(wasm_bindgen_rayon::init_thread_pool(threads))
27+
}
2228

2329
#[wasm_bindgen_test]
2430
async fn test_get_and_scan_range() {
2531
initialize();
32+
2633
#[cfg(all(feature = "wasm-parallel"))]
27-
let _ = JsFuture::from(wasm_bindgen_rayon::init_thread_pool(5)).await;
34+
let _ = init_threadpool(THREADS).await;
35+
36+
let num_parallel = rayon::current_num_threads();
37+
tracing::info!("WASM rayon has {} threads", num_parallel);
2838

2939
let mut w = WebWallet::new("test", "https://zcash-testnet.chainsafe.dev", 1).unwrap();
3040

@@ -55,6 +65,8 @@ async fn test_get_and_scan_range() {
5565
#[tokio::test]
5666
async fn test_get_and_scan_range_native() {
5767
initialize();
68+
let num_parallel = rayon::current_num_threads();
69+
tracing::info!("Native rayon has {} threads", num_parallel);
5870
let url = "https://testnet.zec.rocks:443";
5971
let c = tonic::transport::Channel::from_shared(url).unwrap();
6072

0 commit comments

Comments
 (0)