Skip to content

Commit

Permalink
correctly rename boundaries to bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Feb 14, 2025
1 parent f08a976 commit 07f5bcc
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 91 deletions.
54 changes: 16 additions & 38 deletions zingo-sync/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! Module for primitive structs associated with the sync engine
//! Module for primitive wallet structs generated by the sync engine from block chain data or to track the wallet's
//! sync status.
//! The structs will be (or be transposed into) the fundamental wallet components for the wallet interfacing with this
//! sync engine.
use std::{
collections::{BTreeMap, BTreeSet},
fmt::Debug,
ops::Range,
};

use getset::{CopyGetters, Getters, MutGetters, Setters};

use incrementalmerkletree::Position;
use zcash_client_backend::{
data_api::scanning::{ScanPriority, ScanRange},
Expand Down Expand Up @@ -44,7 +45,7 @@ pub struct InitialSyncState {
/// One block above the fully scanned wallet height at start of sync session.
pub(crate) sync_start_height: BlockHeight,
/// The tree sizes of the fully scanned height and chain tip at start of sync session.
pub(crate) sync_tree_boundaries: TreeBoundaries,
pub(crate) sync_tree_bounds: TreeBounds,
/// Total number of blocks to scan.
pub(crate) total_blocks_to_scan: u32,
/// Total number of sapling outputs to scan.
Expand All @@ -58,7 +59,7 @@ impl InitialSyncState {
pub fn new() -> Self {
InitialSyncState {
sync_start_height: 0.into(),
sync_tree_boundaries: TreeBoundaries {
sync_tree_bounds: TreeBounds {
sapling_initial_tree_size: 0,
sapling_final_tree_size: 0,
orchard_initial_tree_size: 0,
Expand Down Expand Up @@ -185,7 +186,7 @@ impl Default for SyncState {
}

#[derive(Debug, Clone, Copy)]
pub struct TreeBoundaries {
pub struct TreeBounds {
pub sapling_initial_tree_size: u32,
pub sapling_final_tree_size: u32,
pub orchard_initial_tree_size: u32,
Expand Down Expand Up @@ -292,7 +293,7 @@ pub struct WalletBlock {
pub(crate) prev_hash: BlockHash,
pub(crate) time: u32,
pub(crate) txids: Vec<TxId>,
pub(crate) tree_boundaries: TreeBoundaries,
pub(crate) tree_bounds: TreeBounds,
}

impl WalletBlock {
Expand All @@ -316,8 +317,8 @@ impl WalletBlock {
&self.txids
}

pub fn tree_boundaries(&self) -> TreeBoundaries {
self.tree_boundaries
pub fn tree_bounds(&self) -> TreeBounds {
self.tree_bounds
}
}

Expand Down Expand Up @@ -786,41 +787,18 @@ pub trait OutgoingNoteInterface: Sized {
}

/// Note sent from this capability to a recipient
#[derive(Debug, Clone, Getters, CopyGetters, Setters)]
#[derive(Debug, Clone)]
pub struct OutgoingNote<N> {
/// Output ID
#[getset(get_copy = "pub")]
output_id: OutputId,
pub(crate) output_id: OutputId,
/// Identifier for key used to decrypt output
#[getset(get_copy = "pub")]
key_id: KeyId,
pub(crate) key_id: KeyId,
/// Decrypted note with recipient and value
#[getset(get = "pub")]
note: N,
pub(crate) note: N,
/// Memo
#[getset(get = "pub")]
memo: Memo,
pub(crate) memo: Memo,
/// Recipient's full unified address from encoded memo
#[getset(get = "pub", set = "pub")]
recipient_unified_address: Option<UnifiedAddress>,
}

impl<N> OutgoingNote<N> {
pub fn from_parts(
output_id: OutputId,
key_id: KeyId,
note: N,
memo: Memo,
recipient_ua: Option<UnifiedAddress>,
) -> Self {
Self {
output_id,
key_id,
note,
memo,
recipient_unified_address: recipient_ua,
}
}
pub(crate) recipient_unified_address: Option<UnifiedAddress>,
}

pub type OutgoingSaplingNote = OutgoingNote<sapling_crypto::Note>;
Expand Down
10 changes: 5 additions & 5 deletions zingo-sync/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ impl InitialScanData {
let (sapling_initial_tree_size, orchard_initial_tree_size) =
if let Some(prev) = &start_seam_block {
(
prev.tree_boundaries().sapling_final_tree_size,
prev.tree_boundaries().orchard_final_tree_size,
prev.tree_bounds().sapling_final_tree_size,
prev.tree_bounds().orchard_final_tree_size,
)
} else {
let tree_boundaries = compact_blocks::calculate_block_tree_boundaries(
let tree_bounds = compact_blocks::calculate_block_tree_bounds(
consensus_parameters,
fetch_request_sender,
first_block,
)
.await;

(
tree_boundaries.sapling_initial_tree_size,
tree_boundaries.orchard_initial_tree_size,
tree_bounds.sapling_initial_tree_size,
tree_bounds.orchard_initial_tree_size,
)
};

Expand Down
14 changes: 7 additions & 7 deletions zingo-sync/src/scan/compact_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use zcash_primitives::{
use crate::{
client::{self, FetchRequest},
keys::{KeyId, ScanningKeyOps, ScanningKeys},
primitives::{NullifierMap, OutputId, TreeBoundaries, WalletBlock},
primitives::{NullifierMap, OutputId, TreeBounds, WalletBlock},
witness::WitnessData,
MAX_BATCH_OUTPUTS,
};
Expand Down Expand Up @@ -143,7 +143,7 @@ where
.iter()
.map(|transaction| transaction.txid())
.collect(),
tree_boundaries: TreeBoundaries {
tree_bounds: TreeBounds {
sapling_initial_tree_size,
sapling_final_tree_size,
orchard_initial_tree_size,
Expand Down Expand Up @@ -248,12 +248,12 @@ fn check_continuity(
fn check_tree_size(compact_block: &CompactBlock, wallet_block: &WalletBlock) -> Result<(), ()> {
if let Some(chain_metadata) = &compact_block.chain_metadata {
if chain_metadata.sapling_commitment_tree_size
!= wallet_block.tree_boundaries().sapling_final_tree_size
!= wallet_block.tree_bounds().sapling_final_tree_size
{
panic!("sapling tree size is incorrect!")
}
if chain_metadata.orchard_commitment_tree_size
!= wallet_block.tree_boundaries().orchard_final_tree_size
!= wallet_block.tree_bounds().orchard_final_tree_size
{
panic!("orchard tree size is incorrect!")
}
Expand Down Expand Up @@ -418,11 +418,11 @@ fn collect_nullifiers(
Ok(())
}

pub(super) async fn calculate_block_tree_boundaries<P>(
pub(super) async fn calculate_block_tree_bounds<P>(
consensus_parameters: &P,
fetch_request_sender: mpsc::UnboundedSender<FetchRequest>,
compact_block: &CompactBlock,
) -> TreeBoundaries
) -> TreeBounds
where
P: consensus::Parameters + Sync + Send + 'static,
{
Expand Down Expand Up @@ -476,7 +476,7 @@ where
.try_into()
.expect("Sapling output count cannot exceed a u32");

TreeBoundaries {
TreeBounds {
sapling_initial_tree_size: sapling_final_tree_size - sapling_output_count,
sapling_final_tree_size,
orchard_initial_tree_size: orchard_final_tree_size - orchard_output_count,
Expand Down
20 changes: 10 additions & 10 deletions zingo-sync/src/scan/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
MAX_BATCH_OUTPUTS,
};

use super::{compact_blocks::calculate_block_tree_boundaries, error::ScanError, scan, ScanResults};
use super::{compact_blocks::calculate_block_tree_bounds, error::ScanError, scan, ScanResults};

const MAX_WORKER_POOLSIZE: usize = 2;

Expand Down Expand Up @@ -344,7 +344,7 @@ where
}

if first_batch {
let tree_boundaries = calculate_block_tree_boundaries(
let tree_bounds = calculate_block_tree_bounds(
&consensus_parameters,
fetch_request_sender.clone(),
&compact_block,
Expand All @@ -361,12 +361,12 @@ where
.iter()
.map(|transaction| transaction.txid())
.collect(),
tree_boundaries,
tree_bounds,
});
first_batch = false;
}
if compact_block.height() == scan_task.scan_range.block_range().end - 1 {
let tree_boundaries = calculate_block_tree_boundaries(
let tree_bounds = calculate_block_tree_bounds(
&consensus_parameters,
fetch_request_sender.clone(),
&compact_block,
Expand All @@ -383,7 +383,7 @@ where
.iter()
.map(|transaction| transaction.txid())
.collect(),
tree_boundaries,
tree_bounds,
});
}

Expand Down Expand Up @@ -643,7 +643,7 @@ impl ScanTask {
lower_task_locators.split_off(&(block_height, TxId::from_bytes([0; 32])));

let lower_task_last_block = if let Some(block) = lower_compact_blocks.last() {
let tree_boundaries = calculate_block_tree_boundaries(
let tree_bounds = calculate_block_tree_bounds(
consensus_parameters,
fetch_request_sender.clone(),
block,
Expand All @@ -660,14 +660,14 @@ impl ScanTask {
.iter()
.map(|transaction| transaction.txid())
.collect(),
tree_boundaries,
tree_bounds,
})
} else {
None
};
let upper_task_first_block = if let Some(block) = upper_compact_blocks.first() {
let tree_boundaries =
calculate_block_tree_boundaries(consensus_parameters, fetch_request_sender, block)
let tree_bounds =
calculate_block_tree_bounds(consensus_parameters, fetch_request_sender, block)
.await;

Some(WalletBlock {
Expand All @@ -680,7 +680,7 @@ impl ScanTask {
.iter()
.map(|transaction| transaction.txid())
.collect(),
tree_boundaries,
tree_bounds,
})
} else {
None
Expand Down
14 changes: 7 additions & 7 deletions zingo-sync/src/scan/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ where
&output.value_commitment(),
&output.out_ciphertext(),
) {
outgoing_notes.push(OutgoingNote::from_parts(
OutputId::new(txid, output_index as u16),
key_ids[key_index],
outgoing_notes.push(OutgoingNote {
output_id: OutputId::new(txid, output_index as u16),
key_id: key_ids[key_index],
note,
Memo::from_bytes(memo_bytes.as_ref()).unwrap(),
None,
));
memo: Memo::from_bytes(memo_bytes.as_ref()).unwrap(),
recipient_unified_address: None,
});
}
}

Expand Down Expand Up @@ -478,7 +478,7 @@ fn add_recipient_unified_address<P, Nz>(
.iter_mut()
.filter(|note| ua_receivers.contains(&note.encoded_recipient(parameters)))
.for_each(|note| {
note.set_recipient_unified_address(Some(ua.clone()));
note.recipient_unified_address = Some(ua.clone());
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions zingo-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ where
let highest_scanned_height = sync_state.highest_scanned_height();
let sync_start_height = sync_state.initial_sync_state.sync_start_height;

let scanned_block_range_boundaries = sync_state
let scanned_block_range_bounds = sync_state
.scan_ranges()
.iter()
.filter(|scan_range| {
Expand All @@ -572,7 +572,7 @@ where
wallet.get_wallet_blocks_mut().unwrap().retain(|height, _| {
*height >= sync_start_height - 1
|| *height >= highest_scanned_height - MAX_VERIFICATION_WINDOW
|| scanned_block_range_boundaries.contains(height)
|| scanned_block_range_bounds.contains(height)
|| wallet_transaction_heights.contains(height)
});
wallet
Expand Down
Loading

0 comments on commit 07f5bcc

Please sign in to comment.