From 7331a8f4584b1d946dbed4da5f2f64d90417b1cb Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 21 Jul 2022 18:38:05 -0600 Subject: [PATCH] Rename fragments -> ommers --- src/bridgetree.rs | 55 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/bridgetree.rs b/src/bridgetree.rs index 76ebc23c..bdb82e07 100644 --- a/src/bridgetree.rs +++ b/src/bridgetree.rs @@ -252,21 +252,21 @@ pub struct MerkleBridge { /// The position of the final leaf in the frontier of the bridge that this bridge is the /// successor of, or None if this is the first bridge in a tree. prior_position: Option, - /// The set of addresses for which we are waiting to discover the fragments. The values of this + /// The set of addresses for which we are waiting to discover the ommers. The values of this /// set and the keys of the `need` map should always be disjoint. Also, this set should /// never contain an address for which the sibling value has been discovered; at that point, /// the address is replaced in this set with its parent and the address/sibling pair is stored - /// in `fragments`. + /// in `ommers`. /// /// Another way to consider the contents of this set is that the values that exist in - /// `fragments`, combined with the values in previous bridges' `fragments` and an original leaf + /// `ommers`, combined with the values in previous bridges' `ommers` and an original leaf /// node, already contain all the values needed to compute the value at the given address. /// Therefore, we are tracking that address as we do not yet have enough information to compute /// its sibling without filling the sibling subtree with empty nodes. tracking: BTreeSet
, - /// A map from addresses that were being tracked to the values of their fragments that have been + /// A map from addresses that were being tracked to the values of their ommers that have been /// discovered while scanning this bridge's range by adding leaves to the bridge's frontier. - fragments: BTreeMap, + ommers: BTreeMap, /// The leading edge of the bridge. frontier: NonEmptyFrontier, } @@ -278,7 +278,7 @@ impl MerkleBridge { Self { prior_position: None, tracking: BTreeSet::new(), - fragments: BTreeMap::new(), + ommers: BTreeMap::new(), frontier: NonEmptyFrontier::new(value), } } @@ -287,13 +287,13 @@ impl MerkleBridge { pub fn from_parts( prior_position: Option, tracking: BTreeSet
, - fragments: BTreeMap, + ommers: BTreeMap, frontier: NonEmptyFrontier, ) -> Self { Self { prior_position, tracking, - fragments, + ommers, frontier, } } @@ -311,15 +311,15 @@ impl MerkleBridge { } /// Returns the set of internal node addresses that we're searching - /// for the fragments for. + /// for the ommers for. pub fn tracking(&self) -> &BTreeSet
{ &self.tracking } /// Returns the set of internal node addresses that we're searching - /// for the fragments for. - pub fn fragments(&self) -> &BTreeMap { - &self.fragments + /// for the ommers for. + pub fn ommers(&self) -> &BTreeMap { + &self.ommers } /// Returns the non-empty frontier of this Merkle bridge. @@ -356,7 +356,7 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { let mut result = Self { prior_position: Some(self.frontier.position()), tracking: self.tracking.clone(), - fragments: BTreeMap::new(), + ommers: BTreeMap::new(), frontier: self.frontier.clone(), }; @@ -373,7 +373,7 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { } /// Advances this bridge's frontier by appending the specified node, - /// and updates any auth path fragments being tracked if necessary. + /// and updates any auth path ommers being tracked if necessary. pub fn append(&mut self, value: H) { self.frontier.append(value); @@ -390,7 +390,7 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { .is_complete_subtree(address.level()) { let digest = self.frontier.root(Some(address.level())); - self.fragments.insert(address.sibling(), digest); + self.ommers.insert(address.sibling(), digest); found.push(*address); } } @@ -401,7 +401,7 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { // The address of the next incomplete parent note for which // we need to find a sibling. let parent = address.next_incomplete_parent(); - assert!(!self.fragments.contains_key(&parent)); + assert!(!self.ommers.contains_key(&parent)); self.tracking.insert(parent); } } @@ -416,10 +416,10 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { let fused = Self { prior_position: self.prior_position, tracking: next.tracking.clone(), - fragments: self - .fragments + ommers: self + .ommers .iter() - .chain(next.fragments.iter()) + .chain(next.ommers.iter()) .map(|(k, v)| (*k, v.clone())) .collect(), frontier: next.frontier.clone(), @@ -460,17 +460,16 @@ impl<'a, H: Hashable + Ord + Clone + 'a> MerkleBridge { // the frontier's position is after the end of the requested // range, so the requested value should exist in a stored // fragment - self.fragments.get(&addr).cloned() + self.ommers.get(&addr).cloned() } }) } - fn retain(&mut self, witness_node_addrs: &BTreeSet
) { - // Prune away any fragments & tracking addresses we don't need + fn retain(&mut self, ommer_addrs: &BTreeSet
) { + // Prune away any ommers & tracking addresses we don't need self.tracking - .retain(|addr| witness_node_addrs.contains(&addr.sibling())); - self.fragments - .retain(|addr, _| witness_node_addrs.contains(addr)); + .retain(|addr| ommer_addrs.contains(&addr.sibling())); + self.ommers.retain(|addr, _| ommer_addrs.contains(addr)); } } @@ -1039,7 +1038,7 @@ impl Tree for BridgeTree> = None; let mut merged = 0; - let mut witness_node_addrs: BTreeSet
= BTreeSet::new(); + let mut ommer_addrs: BTreeSet
= BTreeSet::new(); for (i, next_bridge) in std::mem::take(&mut self.prior_bridges) .into_iter() .enumerate() @@ -1059,7 +1058,7 @@ impl Tree for BridgeTree Tree for BridgeTree