diff --git a/src/bindgen/wallet.rs b/src/bindgen/wallet.rs index 7166f89..73ed81a 100644 --- a/src/bindgen/wallet.rs +++ b/src/bindgen/wallet.rs @@ -126,32 +126,8 @@ impl WebWallet { self.inner.suggest_scan_ranges().await } - /// Synchronize the wallet with the blockchain up to the tip using zcash_client_backend's algo - 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()) - .spawn_async(|| async { - assert!(thread::is_web_worker_thread()); - tracing::debug!( - "Current num threads (wasm_thread) {}", - rayon::current_num_threads() - ); - - let db = db; - db.sync().await.unwrap_throw(); - }) - .unwrap_throw() - .join_async(); - sync_handler.await.unwrap(); - Ok(()) - } - /// Synchronize the wallet with the blockchain up to the tip using our newest and bestest - pub async fn sync3(&self) -> Result<(), Error> { + pub async fn sync(&self) -> Result<(), Error> { assert!(!thread::is_web_worker_thread()); tracing::debug!("SYNC 3 Main!!!!"); let db = self.inner.clone(); @@ -166,7 +142,7 @@ impl WebWallet { ); let db = db; - db.sync3().await.unwrap_throw(); + db.sync().await.unwrap_throw(); }) .unwrap_throw() .join_async(); diff --git a/src/lib.rs b/src/lib.rs index 5c30930..39cfa80 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,10 +19,6 @@ use wasm_bindgen::prelude::*; /// The maximum number of checkpoints to store in each shard-tree pub const PRUNING_DEPTH: usize = 100; - -use zcash_client_memory::MemoryWalletDb; -use zcash_primitives::consensus; - #[cfg(feature = "wasm-parallel")] pub use wasm_bindgen_rayon::init_thread_pool; @@ -34,5 +30,4 @@ pub fn init_thread_pool(_threads: usize) {} #[wasm_bindgen] pub struct BlockRange(pub u32, pub u32); - -pub mod sync3; +pub mod sync; diff --git a/src/sync3/mod.rs b/src/sync.rs similarity index 98% rename from src/sync3/mod.rs rename to src/sync.rs index c201508..520f958 100644 --- a/src/sync3/mod.rs +++ b/src/sync.rs @@ -92,9 +92,12 @@ where // any shielded scanning, to ensure that we discover any UTXOs between the old // fully-scanned height and the current chain tip. // #[cfg(feature = "transparent-inputs")] - let account_ids = db_data.read().await.get_account_ids().map_err(Error::Wallet)?; - for account_id in account_ids - { + let account_ids = db_data + .read() + .await + .get_account_ids() + .map_err(Error::Wallet)?; + for account_id in account_ids { let start_height = db_data .read() .await diff --git a/src/wallet.rs b/src/wallet.rs index c07b8e1..eac437f 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -9,7 +9,7 @@ use tonic::{ }; use crate::error::Error; -use crate::{sync3, BlockRange}; +use crate::BlockRange; use serde::{Serialize, Serializer}; use std::fmt::Debug; @@ -41,7 +41,6 @@ use zcash_primitives::transaction::fees::zip317::FeeRule; use zcash_primitives::transaction::TxId; use zcash_proofs::prover::LocalTxProver; -use zcash_client_backend::sync::run; const BATCH_SIZE: u32 = 10000; /// # A Zcash wallet @@ -224,33 +223,16 @@ where })?) } - pub async fn sync3(&self) -> Result<(), Error> { - let mut client = self.client.clone(); - // TODO: This should be held in the Wallet struct so we can download in parallel - let db_cache = MemBlockCache::new(); - - sync3::run( - &mut client, - &self.network.clone(), - &db_cache, - self.db.clone(), - BATCH_SIZE, - ) - .await - .map_err(Into::into) - } - pub async fn sync(&self) -> Result<(), Error> { let mut client = self.client.clone(); // TODO: This should be held in the Wallet struct so we can download in parallel let db_cache = MemBlockCache::new(); - let mut db = self.db.write().await; - run( + crate::sync::run( &mut client, &self.network.clone(), &db_cache, - &mut *db, + self.db.clone(), BATCH_SIZE, ) .await