From cd970bac4264d47f5ef14548961ffbda19394a8c Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 20 Aug 2024 23:02:28 +0000 Subject: [PATCH 1/4] added and edited comments --- zingolib/src/lightclient.rs | 6 ++++-- zingolib/src/wallet/disk.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zingolib/src/lightclient.rs b/zingolib/src/lightclient.rs index 6748995dd..5518ffdd4 100644 --- a/zingolib/src/lightclient.rs +++ b/zingolib/src/lightclient.rs @@ -217,7 +217,7 @@ pub struct UserBalances { pub incoming_dust: u64, } -/// The LightClient provides a unified interface to the separate concerns that the zingolib library manages. +/// The LightClient connects one LightWallet to one lightwalletd server via gRPC. /// 1. initialization of stored state /// * from seed /// * from keys @@ -226,6 +226,8 @@ pub struct UserBalances { /// 2. synchronization of the client with the state of the blockchain via a gRPC server /// * pub struct LightClient { + // / the LightClient connects to one server. + // pub(crate) server_uri: Arc>, pub(crate) config: ZingoConfig, /// TODO: Add Doc Comment Here! pub wallet: LightWallet, @@ -242,7 +244,7 @@ pub struct LightClient { save_buffer: ZingoSaveBuffer, } -/// This is the omnibus interface to the library, we are currently in the process of refining this typez broad definition! +/// all the wonderfully intertwined ways to conjure a LightClient pub mod instantiation { use log::debug; use std::{ diff --git a/zingolib/src/wallet/disk.rs b/zingolib/src/wallet/disk.rs index f99a45ab9..032379f0b 100644 --- a/zingolib/src/wallet/disk.rs +++ b/zingolib/src/wallet/disk.rs @@ -191,8 +191,16 @@ impl LightWallet { WalletZecPriceInfo::read(&mut reader)? }; + // this initialization combines two types of data let transaction_context = TransactionContext::new( + // Config data could be used differently based on the circumstances + // hardcoded? + // entered at init by user? + // stored on disk in a separate location and connected by a descendant library (such as zingo-mobile)? config, + // Saveable Arc data + // - Arcs allow access between threads. + // - This data is loaded from the wallet file and but needs multithreaded access during sync. Arc::new(wallet_capability), Arc::new(RwLock::new(transactions)), ); From 0543fafae86de35d8853fd2dd0e4dc2fdfd8c173 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 20 Aug 2024 23:11:46 +0000 Subject: [PATCH 2/4] delete unused duplicate Arc>>> --- zingolib/CHANGELOG.md | 6 ++++++ zingolib/src/blaze/syncdata.rs | 8 +------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zingolib/CHANGELOG.md b/zingolib/CHANGELOG.md index a499a625c..a2ea4dc08 100644 --- a/zingolib/CHANGELOG.md +++ b/zingolib/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- `lightclient.bsync_data.uri()` + +## [mobile-release-1.4.3-0-g9fa99407] + ### Deprecated - `lightclient::LightClient::do_list_transactions` diff --git a/zingolib/src/blaze/syncdata.rs b/zingolib/src/blaze/syncdata.rs index 4b55c8036..8d5e602e7 100644 --- a/zingolib/src/blaze/syncdata.rs +++ b/zingolib/src/blaze/syncdata.rs @@ -11,25 +11,19 @@ use crate::wallet::WalletOptions; pub struct BlazeSyncData { pub(crate) block_data: BlockManagementData, - uri: Arc>, pub(crate) wallet_options: WalletOptions, } impl BlazeSyncData { - pub fn new(config: &ZingoConfig) -> Self { + pub fn new() -> Self { let sync_status = Arc::new(RwLock::new(BatchSyncStatus::default())); Self { - uri: config.lightwalletd_uri.clone(), block_data: BlockManagementData::new(sync_status), wallet_options: WalletOptions::default(), } } - pub fn uri(&self) -> Uri { - self.uri.read().unwrap().clone() - } - pub async fn setup_nth_batch( &mut self, start_block: u64, From ff8592088bb208da05901e7c8559e0a5f5ec22e4 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 21 Aug 2024 00:10:30 +0000 Subject: [PATCH 3/4] simplified lightwalletd_uri lookup --- zingolib/src/blaze/block_management_reorg_detection.rs | 5 +++-- zingolib/src/blaze/trial_decryptions.rs | 4 ++-- zingolib/src/lightclient.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zingolib/src/blaze/block_management_reorg_detection.rs b/zingolib/src/blaze/block_management_reorg_detection.rs index 3b2a32138..51e3be3d9 100644 --- a/zingolib/src/blaze/block_management_reorg_detection.rs +++ b/zingolib/src/blaze/block_management_reorg_detection.rs @@ -505,7 +505,7 @@ impl BlockManagementData { /// currently of the opinion that this function should be factored into separate concerns. pub(crate) async fn get_note_witness( &self, - uri: Uri, + lightwalletd_uri: Uri, height: BlockHeight, transaction_num: usize, output_num: usize, @@ -521,7 +521,8 @@ impl BlockManagementData { let tree = if prev_height < activation_height { frontier::CommitmentTree::<::Node, 32>::empty() } else { - let tree_state = crate::grpc_connector::get_trees(uri, prev_height).await?; + let tree_state = + crate::grpc_connector::get_trees(lightwalletd_uri, prev_height).await?; let tree = hex::decode(D::get_tree(&tree_state)).unwrap(); self.unverified_treestates.write().await.push(tree_state); read_commitment_tree(&tree[..]).map_err(|e| format!("{}", e))? diff --git a/zingolib/src/blaze/trial_decryptions.rs b/zingolib/src/blaze/trial_decryptions.rs index cee4cc556..fa9cfeac2 100644 --- a/zingolib/src/blaze/trial_decryptions.rs +++ b/zingolib/src/blaze/trial_decryptions.rs @@ -301,6 +301,7 @@ impl TrialDecryptions { .collect::>(); let maybe_decrypted_outputs = zcash_note_encryption::batch::try_compact_note_decryption(&[ivk], &outputs); + for maybe_decrypted_output in maybe_decrypted_outputs.into_iter().enumerate() { let (output_num, witnessed) = if let (i, Some(((note, to), _ivk_num))) = maybe_decrypted_output { @@ -321,7 +322,6 @@ impl TrialDecryptions { //TODO: Wrong. We don't have fvk import, all our keys are spending let have_spending_key = true; - let uri = bsync_data.read().await.uri().clone(); // Get the witness for the note let witness = bsync_data @@ -329,7 +329,7 @@ impl TrialDecryptions { .await .block_data .get_note_witness::( - uri, + config.get_lightwalletd_uri(), height, transaction_num, i, diff --git a/zingolib/src/lightclient.rs b/zingolib/src/lightclient.rs index 5518ffdd4..cf050fbf3 100644 --- a/zingolib/src/lightclient.rs +++ b/zingolib/src/lightclient.rs @@ -277,7 +277,7 @@ pub mod instantiation { config: config.clone(), mempool_monitor: std::sync::RwLock::new(None), sync_lock: Mutex::new(()), - bsync_data: Arc::new(RwLock::new(BlazeSyncData::new(&config))), + bsync_data: Arc::new(RwLock::new(BlazeSyncData::new())), interrupt_sync: Arc::new(RwLock::new(false)), latest_proposal: Arc::new(RwLock::new(None)), save_buffer: ZingoSaveBuffer::new(buffer), From 06a63c8620b285fc245b91d6b419455e236a2bed Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 21 Aug 2024 01:28:40 +0000 Subject: [PATCH 4/4] cargo clippy --fix --tests --all-features --- zingolib/src/blaze/syncdata.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/zingolib/src/blaze/syncdata.rs b/zingolib/src/blaze/syncdata.rs index 8d5e602e7..1d2ef9992 100644 --- a/zingolib/src/blaze/syncdata.rs +++ b/zingolib/src/blaze/syncdata.rs @@ -1,11 +1,9 @@ use std::sync::Arc; -use http::Uri; use tokio::sync::RwLock; use zcash_client_backend::proto::service::TreeState; use super::{block_management_reorg_detection::BlockManagementData, sync_status::BatchSyncStatus}; -use crate::config::ZingoConfig; use crate::wallet::data::BlockData; use crate::wallet::WalletOptions;