shardtree: Derive correct shard root addrs in `ShardTree::insert_tree`

`LocatedTree::decompose_to_level` will return the tree as-is if it is
smaller than a shard, so we can't assume that the address of `subtree`
is a valid shard address.
This commit is contained in:
Jack Grigg 2023-07-24 18:07:35 +00:00
parent f23b5f314f
commit 1eda8b2e24
1 changed files with 5 additions and 1 deletions

View File

@ -587,7 +587,11 @@ impl<
) -> Result<Vec<IncompleteAt>, ShardTreeError<S::Error>> {
let mut all_incomplete = vec![];
for subtree in tree.decompose_to_level(Self::subtree_level()).into_iter() {
let root_addr = subtree.root_addr;
// `LocatedTree::decompose_to_level` will return the tree as-is if it is
// smaller than a shard, so we can't assume that the address of `subtree` is a
// valid shard address.
let root_addr = Self::subtree_addr(subtree.root_addr.position_range_start());
let contains_marked = subtree.root.contains_marked();
let (new_subtree, mut incomplete) = self
.store