From ebbd2e3d2d271df884f9dc890a4f06a6261870ec Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 31 Mar 2023 16:24:15 -0600 Subject: [PATCH] Apply suggestions from code review. Co-authored-by: Daira Hopwood --- bridgetree/src/lib.rs | 6 +++++- incrementalmerkletree/src/frontier.rs | 11 ++++++----- incrementalmerkletree/src/lib.rs | 6 +----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bridgetree/src/lib.rs b/bridgetree/src/lib.rs index 40860fa..acb815d 100644 --- a/bridgetree/src/lib.rs +++ b/bridgetree/src/lib.rs @@ -535,7 +535,11 @@ impl BridgeTree { impl BridgeTree { /// Construct a new BridgeTree that will start recording changes from the state of /// the specified frontier. - pub fn from_frontier(max_checkpoints: usize, frontier: NonEmptyFrontier, checkpoint_id: C) -> Self { + pub fn from_frontier( + max_checkpoints: usize, + frontier: NonEmptyFrontier, + checkpoint_id: C, + ) -> Self { let mut bridge = Self { prior_bridges: vec![], current_bridge: Some(MerkleBridge::from_parts( diff --git a/incrementalmerkletree/src/frontier.rs b/incrementalmerkletree/src/frontier.rs index 30e6d04..5cb8c1f 100644 --- a/incrementalmerkletree/src/frontier.rs +++ b/incrementalmerkletree/src/frontier.rs @@ -15,7 +15,8 @@ pub enum FrontierError { PositionMismatch { expected_ommers: usize }, /// An error representing that the position and/or list of ommers provided to frontier /// construction would result in a frontier that exceeds the maximum statically allowed depth - /// of the tree. + /// of the tree. `depth` is the minimum tree depth that would be required in order for that + /// tree to contain the position in question. MaxDepthExceeded { depth: u8 }, } @@ -39,7 +40,7 @@ impl NonEmptyFrontier { } } - /// Constructs a new frontier from its constituent parts + /// Constructs a new frontier from its constituent parts. pub fn from_parts(position: Position, leaf: H, ommers: Vec) -> Result { let expected_ommers = position.past_ommer_count(); if ommers.len() == expected_ommers { @@ -58,7 +59,7 @@ impl NonEmptyFrontier { self.position } - /// Returns the leaf most recently appended to the frontier + /// Returns the leaf most recently appended to the frontier. pub fn leaf(&self) -> &H { &self.leaf } @@ -71,8 +72,8 @@ impl NonEmptyFrontier { } impl NonEmptyFrontier { - /// Append a new leaf to the frontier, and recompute recompute ommers by hashing together full - /// subtrees until an empty ommer slot is found. + /// Append a new leaf to the frontier, and recompute ommers by hashing together full subtrees + /// until an empty ommer slot is found. pub fn append(&mut self, leaf: H) { let prior_position = self.position; let prior_leaf = self.leaf.clone(); diff --git a/incrementalmerkletree/src/lib.rs b/incrementalmerkletree/src/lib.rs index 1352379..236b4e7 100644 --- a/incrementalmerkletree/src/lib.rs +++ b/incrementalmerkletree/src/lib.rs @@ -289,11 +289,7 @@ impl Address { pub fn sibling(&self) -> Address { Address { level: self.level, - index: if self.index & 0x1 == 0 { - self.index + 1 - } else { - self.index - 1 - }, + index: self.index ^ 1, } }