Merge pull request #88 from zcash/shardtree-insert_tree-checkpoints

shardtree: Pass checkpoints alongside tree to `ShardTree::insert_tree`
This commit is contained in:
ebfull 2023-07-25 09:27:20 -06:00 committed by GitHub
commit 2a667f5009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -487,12 +487,13 @@ mod tests {
let mut left = ShardTree::new(MemoryShardStore::empty(), max_checkpoints);
if let Some(BatchInsertionResult {
subtree,
checkpoints,
mut remainder,
..
}) = LocatedPrunableTree::from_iter(start..end, 0.into(), leaves.clone().into_iter())
{
assert_eq!(remainder.next(), None);
left.insert_tree(subtree).unwrap();
left.insert_tree(subtree, checkpoints).unwrap();
}
// Construct a tree using `ShardTree::batch_insert`.

View File

@ -584,6 +584,7 @@ impl<
pub fn insert_tree(
&mut self,
tree: LocatedPrunableTree<H>,
checkpoints: BTreeMap<C, Position>,
) -> Result<Vec<IncompleteAt>, ShardTreeError<S::Error>> {
let mut all_incomplete = vec![];
for subtree in tree.decompose_to_level(Self::subtree_level()).into_iter() {
@ -613,6 +614,14 @@ impl<
.map_err(ShardTreeError::Storage)?;
all_incomplete.append(&mut incomplete);
}
for (id, position) in checkpoints.into_iter() {
self.store
.add_checkpoint(id, Checkpoint::at_position(position))
.map_err(ShardTreeError::Storage)?;
}
self.prune_excess_checkpoints()?;
Ok(all_incomplete)
}