-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements a priority queue backed by the wallet database for scan range ordering. The scan queue is updated on each call to `put_blocks` or to `update_chain_tip`.
- Loading branch information
Showing
8 changed files
with
926 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::ops::Range; | ||
|
||
use zcash_primitives::consensus::BlockHeight; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||
pub enum ScanPriority { | ||
/// Block ranges that have already been scanned have lowest priority. | ||
Scanned, | ||
/// Block ranges to be scanned to advance the fully-scanned height. | ||
Historic, | ||
/// Block ranges adjacent to wallet open heights. | ||
OpenAdjacent, | ||
/// Blocks that must be scanned to complete note commitment tree shards adjacent to found notes. | ||
FoundNote, | ||
/// Blocks that must be scanned to complete the latest note commitment tree shard. | ||
ChainTip, | ||
/// A previously-scanned range that must be verified has highest priority. | ||
Verify, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct ScanRange { | ||
block_range: Range<BlockHeight>, | ||
priority: ScanPriority, | ||
} | ||
|
||
impl ScanRange { | ||
pub fn from_parts(block_range: Range<BlockHeight>, priority: ScanPriority) -> Self { | ||
ScanRange { | ||
block_range, | ||
priority, | ||
} | ||
} | ||
|
||
pub fn block_range(&self) -> &Range<BlockHeight> { | ||
&self.block_range | ||
} | ||
pub fn priority(&self) -> ScanPriority { | ||
self.priority | ||
} | ||
|
||
pub fn truncate_left(&self, block_height: BlockHeight) -> Option<Self> { | ||
if block_height >= self.block_range.end { | ||
None | ||
} else { | ||
Some(ScanRange { | ||
block_range: block_height..self.block_range.end, | ||
priority: self.priority, | ||
}) | ||
} | ||
} | ||
|
||
pub fn truncate_right(&self, block_height: BlockHeight) -> Option<Self> { | ||
if block_height <= self.block_range.start { | ||
None | ||
} else { | ||
Some(ScanRange { | ||
block_range: self.block_range.start..block_height, | ||
priority: self.priority, | ||
}) | ||
} | ||
} | ||
|
||
pub fn split_at(&self, p: BlockHeight) -> (Self, Self) { | ||
assert!(p > self.block_range.start && p < self.block_range.end); | ||
( | ||
ScanRange { | ||
block_range: self.block_range.start..p, | ||
priority: self.priority, | ||
}, | ||
ScanRange { | ||
block_range: p..self.block_range.end, | ||
priority: self.priority, | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.