From 40c78297e897bd38b389b7870f9d18f368035996 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Fri, 3 Apr 2009 21:35:27 -0700
Subject: [PATCH] hashtree.py: another micro-optimization, expand on a comment

---
 src/allmydata/hashtree.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/allmydata/hashtree.py b/src/allmydata/hashtree.py
index ed073b06..9ecd2f06 100644
--- a/src/allmydata/hashtree.py
+++ b/src/allmydata/hashtree.py
@@ -417,8 +417,6 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list):
             # first we provisionally add all hashes to the tree, comparing
             # any duplicates
             for i,h in new_hashes.iteritems():
-                level = depth_of(i)
-
                 if self[i]:
                     if self[i] != h:
                         raise BadHashError("new hash %s does not match "
@@ -427,6 +425,7 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list):
                                               base32.b2a(self[i]),
                                               self._name_hash(i)))
                 else:
+                    level = depth_of(i)
                     hashes_to_check[level].add(i)
                     self[i] = h
                     remove_upon_failure.add(i)
@@ -440,7 +439,9 @@ class IncompleteHashTree(CompleteBinaryTreeMixin, list):
                         # really *check* the root; you either accept it
                         # because the caller told you what it is by including
                         # it in hashes, or you accept it because you
-                        # calculated it from its two children.
+                        # calculated it from its two children. You probably
+                        # want to set the root (from a trusted source) before
+                        # adding any children from an untrusted source.
                         continue
                     siblingnum = self.sibling(i)
                     if self[siblingnum] is None:
-- 
2.45.2