From fbf8fad4f1f09174ddcc755eaee4b5fb530c1d92 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 29 Apr 2019 10:57:19 +1000 Subject: [PATCH] Add counter-resets to `reset_modifications` --- eth2/utils/cached_tree_hash/src/tree_hash_cache.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs b/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs index 225ae9d5ff..c6b3833c81 100644 --- a/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs +++ b/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs @@ -45,11 +45,6 @@ impl TreeHashCache { if self.is_empty() { Err(Error::CacheNotInitialized) } else { - // Reset the per-hash counters. - self.chunk_index = 0; - self.schema_index = 0; - - // Reset the "modified" flags for the cache. self.reset_modifications(); item.update_tree_hash_cache(self) @@ -156,6 +151,10 @@ impl TreeHashCache { } pub fn reset_modifications(&mut self) { + // Reset the per-hash counters. + self.chunk_index = 0; + self.schema_index = 0; + for chunk_modified in &mut self.chunk_modified { *chunk_modified = false; } @@ -243,6 +242,10 @@ impl TreeHashCache { self.cache.len() } + pub fn tree_hash_root(&self) -> Result<&[u8], Error> { + self.root() + } + pub fn root(&self) -> Result<&[u8], Error> { if self.is_empty() { Err(Error::CacheNotInitialized)