Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use our own sync loop #35

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
696 changes: 481 additions & 215 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ no-bundler = ["wasm-bindgen-rayon?/no-bundler", "wasm_thread/no-bundler"]

[dependencies]
## Web dependencies
wasm-bindgen = "0.2.93"
wasm-bindgen = "=0.2.93" ## There is something weird happening in 0.2.95 where the workerHelpers.worker.js file isnt being included
js-sys = "0.3.70"
wasm-bindgen-futures = "0.4.43"
web-sys = { version = "0.3.70", features = [
"console",
] }
wasm-bindgen-rayon = { version = "1.2.1", optional = true }
wasm-bindgen-rayon = { version = "1.2", optional = true }

# WASM specific dependencies
tracing-web = { version = "0.1.3", optional = true }
Expand All @@ -60,12 +60,13 @@ tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "syn

## Zcash dependencies

zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] }
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", features = ["orchard"] }
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f" }
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f" }
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "9673cc2859e8a2528d1efd3c74795363f87ddf8f", default-features = false, features = ["bundled-prover"] }
zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be", default-features = false, features = ["transparent-inputs", "sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] }
zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be", features = ["orchard", "transparent-inputs"] }
zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be" }
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be" }
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "5e5b30301891e2d4614951f3a99d23b980c8a9be", default-features = false, features = ["bundled-prover"] }


## gRPC Web dependencies
prost = { version = "0.12", default-features = false }
Expand Down Expand Up @@ -110,14 +111,6 @@ byte-unit = { version = "5.1.4", features = ["byte"] }

[patch.crates-io]
zip32 = { git = "https://github.com/zcash/zip32.git", branch = "diversifier_index_ord" }
# TODO: See: https://github.com/RReverser/wasm-bindgen-rayon/pull/12
wasm-bindgen-rayon = { git = "https://github.com/9SMTM6/wasm-bindgen-rayon", rev = "d1816e5bc2bf928ff5442355c04500a381d66a41" }
# TODO: Remove these once the PRs are merged
shardtree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" }
incrementalmerkletree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" }

# [patch.'https://github.com/WilsonGramer/wasm_thread']
# wasm_thread = { git = "https://github.com/ec2/wasm_thread", rev = "9e432077948d927d49373d1d039c23447d3648df" }

#[patch.'https://github.com/chainsafe/librustzcash']
#zcash_address = { path = "../librustzcash/components/zcash_address" }
Expand Down
20 changes: 5 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tonic_web_wasm_client::Client;
use crate::error::Error;
use crate::wallet::usk_from_seed_str;
use crate::Network;
use crate::{bindgen::proposal::Proposal, Wallet, PRUNING_DEPTH};
use crate::{bindgen::proposal::Proposal, BlockRange, Wallet, PRUNING_DEPTH};
use wasm_thread as thread;
use zcash_address::ZcashAddress;
use zcash_client_backend::data_api::{InputSource, WalletRead};
Expand Down Expand Up @@ -196,6 +196,10 @@ impl WebWallet {
.map(|id| *id)
}

pub async fn suggest_scan_ranges(&self) -> Result<Vec<BlockRange>, Error> {
self.inner.suggest_scan_ranges().await
}

///
/// Start a background sync task which will fetch and scan blocks from the connected lighwalletd server
///
Expand All @@ -204,11 +208,10 @@ impl WebWallet {
///
pub async fn sync(&self) -> Result<(), Error> {
assert!(!thread::is_web_worker_thread());

let db = self.inner.clone();

let sync_handler = thread::Builder::new()
.name("sync".to_string())
.name("sync3".to_string())
.spawn_async(|| async {
assert!(thread::is_web_worker_thread());
tracing::debug!(
Expand Down
1 change: 1 addition & 0 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn setup_tracing() {
// For WASM, we must set the directives here at compile time.
let filter_layer = EnvFilter::default()
.add_directive(LevelFilter::INFO.into())
.add_directive("webz_core=debug".parse().unwrap())
.add_directive("zcash_client_memory=info".parse().unwrap())
.add_directive("zcash_client_backend::scanning=debug".parse().unwrap())
.add_directive("zcash_client_backend::sync=debug".parse().unwrap());
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ pub const PRUNING_DEPTH: usize = 100;

#[cfg(feature = "wasm-parallel")]
pub use wasm_bindgen_rayon::init_thread_pool;

// dummy NO-OP init_thread pool to maintain the same API between features
#[cfg(not(feature = "wasm-parallel"))]
#[wasm_bindgen(js_name = initThreadPool)]
pub fn init_thread_pool(_threads: usize) {}

#[wasm_bindgen]
pub struct BlockRange(pub u32, pub u32);

pub mod sync;
Loading
Loading