mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Fix bug with bitfield tree hash caching
This commit is contained in:
@@ -287,14 +287,12 @@ mod tests {
|
|||||||
let mut hasher = cached_tree_hash::CachedTreeHasher::new(&original).unwrap();
|
let mut hasher = cached_tree_hash::CachedTreeHasher::new(&original).unwrap();
|
||||||
|
|
||||||
assert_eq!(hasher.tree_hash_root().unwrap(), original.tree_hash_root());
|
assert_eq!(hasher.tree_hash_root().unwrap(), original.tree_hash_root());
|
||||||
/*
|
|
||||||
|
|
||||||
let modified = BooleanBitfield::from_bytes(&vec![2; 1][..]);
|
let modified = BooleanBitfield::from_bytes(&vec![2; 1][..]);
|
||||||
|
|
||||||
hasher.update(&modified).unwrap();
|
hasher.update(&modified).unwrap();
|
||||||
|
|
||||||
assert_eq!(hasher.tree_hash_root().unwrap(), modified.tree_hash_root());
|
assert_eq!(hasher.tree_hash_root().unwrap(), modified.tree_hash_root());
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -125,7 +125,8 @@ macro_rules! cached_tree_hash_bytes_as_list {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tree_hash_cache_schema(&self, depth: usize) -> cached_tree_hash::BTreeSchema {
|
fn tree_hash_cache_schema(&self, depth: usize) -> cached_tree_hash::BTreeSchema {
|
||||||
cached_tree_hash::impls::vec::produce_schema(&ssz::ssz_encode(self), depth)
|
let bytes = self.to_bytes();
|
||||||
|
cached_tree_hash::impls::vec::produce_schema(&bytes, depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_tree_hash_cache(
|
fn update_tree_hash_cache(
|
||||||
@@ -145,7 +146,7 @@ macro_rules! cached_tree_hash_bytes_as_list {
|
|||||||
cache.mix_in_length(new_overlay.chunk_range(), bytes.len())?;
|
cache.mix_in_length(new_overlay.chunk_range(), bytes.len())?;
|
||||||
|
|
||||||
// Skip an extra node to clear the length node.
|
// Skip an extra node to clear the length node.
|
||||||
cache.chunk_index = new_overlay.next_node() + 1;
|
cache.chunk_index += 1;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ pub fn subtree_derive(input: TokenStream) -> TokenStream {
|
|||||||
fn update_tree_hash_cache(&self, cache: &mut cached_tree_hash::TreeHashCache) -> Result<(), cached_tree_hash::Error> {
|
fn update_tree_hash_cache(&self, cache: &mut cached_tree_hash::TreeHashCache) -> Result<(), cached_tree_hash::Error> {
|
||||||
let overlay = cached_tree_hash::BTreeOverlay::new(self, cache.chunk_index, 0);
|
let overlay = cached_tree_hash::BTreeOverlay::new(self, cache.chunk_index, 0);
|
||||||
|
|
||||||
|
|
||||||
// Skip the chunk index to the first leaf node of this struct.
|
// Skip the chunk index to the first leaf node of this struct.
|
||||||
cache.chunk_index = overlay.first_leaf_node();
|
cache.chunk_index = overlay.first_leaf_node();
|
||||||
// Skip the overlay index to the first leaf node of this struct.
|
// Skip the overlay index to the first leaf node of this struct.
|
||||||
|
|||||||
Reference in New Issue
Block a user