Skip to content

Commit 5b83fbd

Browse files
committed
remove getset from sync state
1 parent b85184d commit 5b83fbd

File tree

4 files changed

+90
-103
lines changed

4 files changed

+90
-103
lines changed

zingo-sync/src/primitives.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use zcash_primitives::{
2424
TxId,
2525
},
2626
};
27+
2728
use zingo_status::confirmation_status::ConfirmationStatus;
2829

2930
use crate::{
@@ -38,19 +39,18 @@ pub type Locator = (BlockHeight, TxId);
3839
/// Initial sync state.
3940
///
4041
/// All fields will be reset when a new sync session starts.
41-
#[derive(Debug, Clone, CopyGetters, Setters)]
42-
#[getset(get_copy = "pub", set = "pub")]
42+
#[derive(Debug, Clone)]
4343
pub struct InitialSyncState {
4444
/// One block above the fully scanned wallet height at start of sync session.
45-
sync_start_height: BlockHeight,
45+
pub(crate) sync_start_height: BlockHeight,
4646
/// The tree sizes of the fully scanned height and chain tip at start of sync session.
47-
sync_tree_boundaries: TreeBoundaries,
47+
pub(crate) sync_tree_boundaries: TreeBoundaries,
4848
/// Total number of blocks to scan.
49-
total_blocks_to_scan: u32,
49+
pub(crate) total_blocks_to_scan: u32,
5050
/// Total number of sapling outputs to scan.
51-
total_sapling_outputs_to_scan: u32,
51+
pub(crate) total_sapling_outputs_to_scan: u32,
5252
/// Total number of orchard outputs to scan.
53-
total_orchard_outputs_to_scan: u32,
53+
pub(crate) total_orchard_outputs_to_scan: u32,
5454
}
5555

5656
impl InitialSyncState {
@@ -78,26 +78,25 @@ impl Default for InitialSyncState {
7878
}
7979

8080
/// Encapsulates the current state of sync
81-
#[derive(Debug, Clone, Getters, MutGetters, CopyGetters, Setters)]
82-
#[getset(get = "pub", get_mut = "pub")]
81+
#[derive(Debug, Clone)]
8382
pub struct SyncState {
8483
/// A vec of block ranges with scan priorities from wallet birthday to chain tip.
8584
/// In block height order with no overlaps or gaps.
86-
scan_ranges: Vec<ScanRange>,
85+
pub(crate) scan_ranges: Vec<ScanRange>,
8786
/// The block ranges that contain all sapling outputs of complete sapling shards.
8887
///
8988
/// There is an edge case where a range may include two (or more) shards. However, this only occurs when the lower
9089
/// shards are already scanned so will cause no issues when punching in the higher scan priorites.
91-
sapling_shard_ranges: Vec<Range<BlockHeight>>,
90+
pub(crate) sapling_shard_ranges: Vec<Range<BlockHeight>>,
9291
/// The block ranges that contain all orchard outputs of complete orchard shards.
9392
///
9493
/// There is an edge case where a range may include two (or more) shards. However, this only occurs when the lower
9594
/// shards are already scanned so will cause no issues when punching in the higher scan priorites.
96-
orchard_shard_ranges: Vec<Range<BlockHeight>>,
95+
pub(crate) orchard_shard_ranges: Vec<Range<BlockHeight>>,
9796
/// Locators for relevant transactions to the wallet.
98-
locators: BTreeSet<Locator>,
97+
pub(crate) locators: BTreeSet<Locator>,
9998
/// Initial sync state.
100-
initial_sync_state: InitialSyncState,
99+
pub(crate) initial_sync_state: InitialSyncState,
101100
}
102101

103102
impl SyncState {
@@ -112,9 +111,13 @@ impl SyncState {
112111
}
113112
}
114113

114+
pub fn scan_ranges(&self) -> &[ScanRange] {
115+
&self.scan_ranges
116+
}
117+
115118
/// Returns true if all scan ranges are scanned.
116119
pub(crate) fn scan_complete(&self) -> bool {
117-
self.scan_ranges()
120+
self.scan_ranges
118121
.iter()
119122
.all(|scan_range| scan_range.priority() == ScanPriority::Scanned)
120123
}
@@ -124,13 +127,13 @@ impl SyncState {
124127
/// Will panic if called before scan ranges are updated for the first time.
125128
pub fn fully_scanned_height(&self) -> BlockHeight {
126129
if let Some(scan_range) = self
127-
.scan_ranges()
130+
.scan_ranges
128131
.iter()
129132
.find(|scan_range| scan_range.priority() != ScanPriority::Scanned)
130133
{
131134
scan_range.block_range().start - 1
132135
} else {
133-
self.scan_ranges()
136+
self.scan_ranges
134137
.last()
135138
.expect("scan ranges always non-empty")
136139
.block_range()
@@ -145,7 +148,7 @@ impl SyncState {
145148
/// Will panic if called before scan ranges are updated for the first time.
146149
pub fn highest_scanned_height(&self) -> BlockHeight {
147150
if let Some(last_scanned_range) = self
148-
.scan_ranges()
151+
.scan_ranges
149152
.iter()
150153
.filter(|scan_range| scan_range.priority() == ScanPriority::Scanned)
151154
.last()
@@ -162,14 +165,14 @@ impl SyncState {
162165
///
163166
/// If the wallet birthday is below the sapling activation height, returns the sapling activation height instead.
164167
pub fn wallet_birthday(&self) -> Option<BlockHeight> {
165-
self.scan_ranges()
168+
self.scan_ranges
166169
.first()
167170
.map(|range| range.block_range().start)
168171
}
169172

170173
/// Returns the last known chain height to the wallet or `None` if `self.scan_ranges` is empty.
171174
pub fn wallet_height(&self) -> Option<BlockHeight> {
172-
self.scan_ranges()
175+
self.scan_ranges
173176
.last()
174177
.map(|range| range.block_range().end - 1)
175178
}

zingo-sync/src/sync.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,34 +220,29 @@ where
220220
acc + (block_range.end - block_range.start)
221221
});
222222
let scanned_blocks = sync_state
223-
.initial_sync_state()
224-
.total_blocks_to_scan()
223+
.initial_sync_state
224+
.total_blocks_to_scan
225225
.saturating_sub(unscanned_blocks);
226-
let percentage_blocks_scanned = (scanned_blocks as f32
227-
/ sync_state.initial_sync_state().total_blocks_to_scan() as f32)
228-
* 100.0;
226+
let percentage_blocks_scanned =
227+
(scanned_blocks as f32 / sync_state.initial_sync_state.total_blocks_to_scan as f32) * 100.0;
229228

230229
let (unscanned_sapling_outputs, unscanned_orchard_outputs) =
231230
state::calculate_unscanned_outputs(&*wallet_guard);
232231
let scanned_sapling_outputs = sync_state
233-
.initial_sync_state()
234-
.total_sapling_outputs_to_scan()
232+
.initial_sync_state
233+
.total_sapling_outputs_to_scan
235234
.saturating_sub(unscanned_sapling_outputs);
236235
let scanned_orchard_outputs = sync_state
237-
.initial_sync_state()
238-
.total_orchard_outputs_to_scan()
236+
.initial_sync_state
237+
.total_orchard_outputs_to_scan
239238
.saturating_sub(unscanned_orchard_outputs);
240239
let percentage_outputs_scanned = ((scanned_sapling_outputs + scanned_orchard_outputs) as f32
241-
/ (sync_state
242-
.initial_sync_state()
243-
.total_sapling_outputs_to_scan()
244-
+ sync_state
245-
.initial_sync_state()
246-
.total_orchard_outputs_to_scan()) as f32)
240+
/ (sync_state.initial_sync_state.total_sapling_outputs_to_scan
241+
+ sync_state.initial_sync_state.total_orchard_outputs_to_scan) as f32)
247242
* 100.0;
248243

249244
SyncStatus {
250-
scan_ranges: sync_state.scan_ranges().clone(),
245+
scan_ranges: sync_state.scan_ranges.clone(),
251246
scanned_blocks,
252247
unscanned_blocks,
253248
percentage_blocks_scanned,
@@ -553,7 +548,7 @@ where
553548
let sync_state = wallet.get_sync_state().unwrap();
554549
let fully_scanned_height = sync_state.fully_scanned_height();
555550
let highest_scanned_height = sync_state.highest_scanned_height();
556-
let sync_start_height = sync_state.initial_sync_state().sync_start_height();
551+
let sync_start_height = sync_state.initial_sync_state.sync_start_height;
557552

558553
let scanned_block_range_boundaries = sync_state
559554
.scan_ranges()
@@ -596,7 +591,7 @@ where
596591
wallet
597592
.get_sync_state_mut()
598593
.unwrap()
599-
.locators_mut()
594+
.locators
600595
.retain(|(height, _)| *height > fully_scanned_height);
601596

602597
Ok(())

0 commit comments

Comments
 (0)