From 6f1b70300de936f49d3a6d6df36f46be04f3b85a Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Fri, 29 Apr 2016 10:05:06 -0600 Subject: [PATCH] Small nit fixes --- src/zcash/IncrementalMerkleTree.cpp | 11 +++-------- src/zcash/IncrementalMerkleTree.hpp | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/zcash/IncrementalMerkleTree.cpp b/src/zcash/IncrementalMerkleTree.cpp index c47862d1f..426abe1de 100644 --- a/src/zcash/IncrementalMerkleTree.cpp +++ b/src/zcash/IncrementalMerkleTree.cpp @@ -53,12 +53,7 @@ void IncrementalMerkleTree::wfcheck() const { } // The last parent cannot be null. - bool wasnull = false; - BOOST_FOREACH(const boost::optional& parent, parents) { - wasnull = !parent; - } - - if (wasnull) { + if (!(parents.empty()) && !(parents.back())) { throw std::ios_base::failure("tree has non-canonical representation of parent"); } @@ -89,7 +84,7 @@ void IncrementalMerkleTree::append(Hash obj) { // Combine the leaves and propagate it up the tree boost::optional combined = Hash::combine(*left, *right); - // Set the left leaf to the object and make the right object none + // Set the "left" leaf to the object and make the "right" leaf none left = obj; right = boost::none; @@ -261,7 +256,7 @@ MerklePath IncrementalMerkleTree::path(std::deque filler_hash } template -std::deque IncrementalWitness::uncle_train() const { +std::deque IncrementalWitness::partial_path() const { std::deque uncles(filled.begin(), filled.end()); if (cursor) { diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index f170ffffa..ff31cc50b 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -68,6 +68,8 @@ public: private: boost::optional left; boost::optional right; + + // Collapsed "left" subtrees ordered toward the root of the tree. std::vector> parents; MerklePath path(std::deque filler_hashes = std::deque()) const; Hash root(size_t depth, std::deque filler_hashes = std::deque()) const; @@ -82,11 +84,11 @@ friend class IncrementalMerkleTree; public: MerklePath path() const { - return tree.path(uncle_train()); + return tree.path(partial_path()); } Hash root() const { - return tree.root(Depth, uncle_train()); + return tree.root(Depth, partial_path()); } void append(Hash obj); @@ -107,7 +109,7 @@ private: std::vector filled; boost::optional> cursor; size_t cursor_depth; - std::deque uncle_train() const; + std::deque partial_path() const; IncrementalWitness(IncrementalMerkleTree tree) : tree(tree) {} };