Skip to content

Commit

Permalink
Code simplifications
Browse files Browse the repository at this point in the history
Co-authored-by: Daira Hopwood <[email protected]>
  • Loading branch information
str4d and daira committed Jul 18, 2023
1 parent 9d39ac7 commit b741eab
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 188 deletions.
26 changes: 11 additions & 15 deletions zcash_client_backend/src/data_api/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ScanRange {

/// Returns whether or not the scan range is empty.
pub fn is_empty(&self) -> bool {
self.block_range.end == self.block_range.start
self.block_range.is_empty()
}

/// Returns the number of blocks in the scan range.
Expand Down Expand Up @@ -89,20 +89,16 @@ impl ScanRange {
/// end of the first range returned and the start of the second. Returns `None` if
/// `p <= self.block_range().start || p >= self.block_range().end`.
pub fn split_at(&self, p: BlockHeight) -> Option<(Self, Self)> {
if p > self.block_range.start && p < self.block_range.end {
Some((
ScanRange {
block_range: self.block_range.start..p,
priority: self.priority,
},
ScanRange {
block_range: p..self.block_range.end,
priority: self.priority,
},
))
} else {
None
}
(p > self.block_range.start && p < self.block_range.end).then_some((
ScanRange {
block_range: self.block_range.start..p,
priority: self.priority,
},
ScanRange {
block_range: p..self.block_range.end,
priority: self.priority,
},
))
}
}

Expand Down
18 changes: 9 additions & 9 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
});
let mut wallet_note_ids = vec![];
let mut sapling_commitments = vec![];
let mut end_height = None;
let mut last_scanned_height = None;
let mut note_positions = vec![];
for block in blocks.into_iter() {
if end_height.iter().any(|prev| block.height() != *prev + 1) {
if last_scanned_height.iter().any(|prev| block.height() != *prev + 1) {
return Err(SqliteClientError::NonSequentialBlocks);
}

Expand Down Expand Up @@ -453,14 +453,14 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
.map(|out| out.note_commitment_tree_position())
}));

end_height = Some(block.height());
last_scanned_height = Some(block.height());
sapling_commitments.extend(block.into_sapling_commitments().into_iter());
}

// We will have a start position and an end height in all cases where `blocks` is
// non-empty.
if let Some(((start_height, start_position), end_height)) =
start_positions.zip(end_height)
// We will have a start position and a last scanned height in all cases where
// `blocks` is non-empty.
if let Some(((start_height, start_position), last_scanned_height)) =
start_positions.zip(last_scanned_height)
{
// Update the Sapling note commitment tree with all newly read note commitments
let mut sapling_commitments = sapling_commitments.into_iter();
Expand All @@ -470,14 +470,14 @@ impl<P: consensus::Parameters> WalletWrite for WalletDb<rusqlite::Connection, P>
})?;

// Update now-expired transactions that didn't get mined.
wallet::update_expired_notes(wdb.conn.0, end_height)?;
wallet::update_expired_notes(wdb.conn.0, last_scanned_height)?;

wallet::scanning::scan_complete(
wdb.conn.0,
&wdb.params,
Range {
start: start_height,
end: end_height + 1,
end: last_scanned_height + 1,
},
&note_positions,
)?;
Expand Down
Loading

0 comments on commit b741eab

Please sign in to comment.