diff --git a/eth2/types/src/slot_epoch_macros.rs b/eth2/types/src/slot_epoch_macros.rs index 446838d0a..4a48bba9f 100644 --- a/eth2/types/src/slot_epoch_macros.rs +++ b/eth2/types/src/slot_epoch_macros.rs @@ -224,7 +224,7 @@ macro_rules! impl_ssz { } } - impl cached_tree_hash::CachedTreeHash<$type> for $type { + impl cached_tree_hash::CachedTreeHash for $type { fn new_tree_hash_cache( &self, depth: usize, diff --git a/eth2/types/src/tree_hash_vector.rs b/eth2/types/src/tree_hash_vector.rs index bfbb42e57..8a7d99a6c 100644 --- a/eth2/types/src/tree_hash_vector.rs +++ b/eth2/types/src/tree_hash_vector.rs @@ -55,9 +55,9 @@ where } } -impl CachedTreeHash> for TreeHashVector +impl CachedTreeHash for TreeHashVector where - T: CachedTreeHash + TreeHash, + T: CachedTreeHash + TreeHash, { fn new_tree_hash_cache( &self, diff --git a/eth2/utils/cached_tree_hash/src/btree_overlay.rs b/eth2/utils/cached_tree_hash/src/btree_overlay.rs index 46b1f31b8..7d08210fb 100644 --- a/eth2/utils/cached_tree_hash/src/btree_overlay.rs +++ b/eth2/utils/cached_tree_hash/src/btree_overlay.rs @@ -42,7 +42,7 @@ pub struct BTreeOverlay { impl BTreeOverlay { pub fn new(item: &T, initial_offset: usize, depth: usize) -> Self where - T: CachedTreeHash, + T: CachedTreeHash, { Self::from_schema(item.tree_hash_cache_schema(depth), initial_offset) } diff --git a/eth2/utils/cached_tree_hash/src/impls.rs b/eth2/utils/cached_tree_hash/src/impls.rs index 357f94d32..5105ad6a7 100644 --- a/eth2/utils/cached_tree_hash/src/impls.rs +++ b/eth2/utils/cached_tree_hash/src/impls.rs @@ -6,7 +6,7 @@ pub mod vec; macro_rules! impl_for_single_leaf_int { ($type: ident) => { - impl CachedTreeHash<$type> for $type { + impl CachedTreeHash for $type { fn new_tree_hash_cache(&self, _depth: usize) -> Result { Ok(TreeHashCache::from_bytes( merkleize(self.to_le_bytes().to_vec()), @@ -37,7 +37,7 @@ impl_for_single_leaf_int!(u32); impl_for_single_leaf_int!(u64); impl_for_single_leaf_int!(usize); -impl CachedTreeHash for bool { +impl CachedTreeHash for bool { fn new_tree_hash_cache(&self, _depth: usize) -> Result { Ok(TreeHashCache::from_bytes( merkleize((*self as u8).to_le_bytes().to_vec()), @@ -60,7 +60,7 @@ impl CachedTreeHash for bool { } } -impl CachedTreeHash<[u8; 4]> for [u8; 4] { +impl CachedTreeHash for [u8; 4] { fn new_tree_hash_cache(&self, _depth: usize) -> Result { Ok(TreeHashCache::from_bytes( merkleize(self.to_vec()), @@ -83,7 +83,7 @@ impl CachedTreeHash<[u8; 4]> for [u8; 4] { } } -impl CachedTreeHash for H256 { +impl CachedTreeHash for H256 { fn new_tree_hash_cache(&self, _depth: usize) -> Result { Ok(TreeHashCache::from_bytes( self.as_bytes().to_vec(), diff --git a/eth2/utils/cached_tree_hash/src/impls/vec.rs b/eth2/utils/cached_tree_hash/src/impls/vec.rs index 67a48ac0b..00a1ef9d9 100644 --- a/eth2/utils/cached_tree_hash/src/impls/vec.rs +++ b/eth2/utils/cached_tree_hash/src/impls/vec.rs @@ -2,9 +2,9 @@ use super::*; use crate::btree_overlay::LeafNode; use crate::merkleize::{merkleize, num_sanitized_leaves, sanitise_bytes}; -impl CachedTreeHash> for Vec +impl CachedTreeHash for Vec where - T: CachedTreeHash + TreeHash, + T: CachedTreeHash + TreeHash, { fn new_tree_hash_cache(&self, depth: usize) -> Result { let (mut cache, schema) = new_tree_hash_cache(self, depth)?; @@ -40,7 +40,7 @@ where } } -pub fn new_tree_hash_cache>( +pub fn new_tree_hash_cache( vec: &Vec, depth: usize, ) -> Result<(TreeHashCache, BTreeSchema), Error> { @@ -65,7 +65,7 @@ pub fn new_tree_hash_cache>( Ok((cache, schema)) } -pub fn produce_schema>(vec: &Vec, depth: usize) -> BTreeSchema { +pub fn produce_schema(vec: &Vec, depth: usize) -> BTreeSchema { let lengths = match T::tree_hash_type() { TreeHashType::Basic => { // Ceil division. @@ -89,7 +89,7 @@ pub fn produce_schema>(vec: &Vec, depth: usize) -> BTree BTreeSchema::from_lengths(depth, lengths) } -pub fn update_tree_hash_cache>( +pub fn update_tree_hash_cache( vec: &Vec, cache: &mut TreeHashCache, ) -> Result { @@ -273,7 +273,7 @@ fn splice_in_new_tree( cache: &mut TreeHashCache, ) -> Result<(), Error> where - T: CachedTreeHash, + T: CachedTreeHash, { let (bytes, mut bools, schemas) = TreeHashCache::new(item, depth)?.into_components(); @@ -296,7 +296,7 @@ where fn get_packed_leaves(vec: &Vec) -> Result, Error> where - T: CachedTreeHash, + T: CachedTreeHash, { let num_packed_bytes = (BYTES_PER_CHUNK / T::tree_hash_packing_factor()) * vec.len(); let num_leaves = num_sanitized_leaves(num_packed_bytes); diff --git a/eth2/utils/cached_tree_hash/src/lib.rs b/eth2/utils/cached_tree_hash/src/lib.rs index ee5f98275..b9bb8457b 100644 --- a/eth2/utils/cached_tree_hash/src/lib.rs +++ b/eth2/utils/cached_tree_hash/src/lib.rs @@ -1,5 +1,4 @@ use hashing::hash; -use merkleize::num_unsanitized_leaves; use std::ops::Range; use tree_hash::{TreeHash, TreeHashType, BYTES_PER_CHUNK, HASHSIZE}; @@ -14,7 +13,7 @@ pub use btree_overlay::{BTreeOverlay, BTreeSchema}; pub use errors::Error; pub use tree_hash_cache::TreeHashCache; -pub trait CachedTreeHash: TreeHash { +pub trait CachedTreeHash: TreeHash { fn tree_hash_cache_schema(&self, depth: usize) -> BTreeSchema; fn num_tree_hash_cache_chunks(&self) -> usize { @@ -34,7 +33,7 @@ pub struct CachedTreeHasher { impl CachedTreeHasher { pub fn new(item: &T) -> Result where - T: CachedTreeHash, + T: CachedTreeHash, { Ok(Self { cache: TreeHashCache::new(item, 0)?, @@ -43,7 +42,7 @@ impl CachedTreeHasher { pub fn update(&mut self, item: &T) -> Result<(), Error> where - T: CachedTreeHash, + T: CachedTreeHash, { self.cache.update(item) } @@ -57,7 +56,7 @@ impl CachedTreeHasher { #[macro_export] macro_rules! cached_tree_hash_ssz_encoding_as_vector { ($type: ident, $num_bytes: expr) => { - impl cached_tree_hash::CachedTreeHash<$type> for $type { + impl cached_tree_hash::CachedTreeHash for $type { fn new_tree_hash_cache( &self, depth: usize, @@ -94,7 +93,7 @@ macro_rules! cached_tree_hash_ssz_encoding_as_vector { #[macro_export] macro_rules! cached_tree_hash_bytes_as_list { ($type: ident) => { - impl cached_tree_hash::CachedTreeHash<$type> for $type { + impl cached_tree_hash::CachedTreeHash for $type { fn new_tree_hash_cache( &self, depth: usize, 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 089e38469..225ae9d5f 100644 --- a/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs +++ b/eth2/utils/cached_tree_hash/src/tree_hash_cache.rs @@ -33,14 +33,14 @@ impl Into> for TreeHashCache { impl TreeHashCache { pub fn new(item: &T, depth: usize) -> Result where - T: CachedTreeHash, + T: CachedTreeHash, { item.new_tree_hash_cache(depth) } pub fn update(&mut self, item: &T) -> Result<(), Error> where - T: CachedTreeHash, + T: CachedTreeHash, { if self.is_empty() { Err(Error::CacheNotInitialized) @@ -62,7 +62,7 @@ impl TreeHashCache { depth: usize, ) -> Result where - T: CachedTreeHash, + T: CachedTreeHash, { let overlay = BTreeOverlay::new(item, 0, depth); diff --git a/eth2/utils/cached_tree_hash/tests/tests.rs b/eth2/utils/cached_tree_hash/tests/tests.rs index 024277e16..4b7a4e830 100644 --- a/eth2/utils/cached_tree_hash/tests/tests.rs +++ b/eth2/utils/cached_tree_hash/tests/tests.rs @@ -34,7 +34,7 @@ pub struct NestedStruct { fn test_routine(original: T, modified: Vec) where - T: CachedTreeHash + std::fmt::Debug, + T: CachedTreeHash + std::fmt::Debug, { let mut hasher = CachedTreeHasher::new(&original).unwrap(); diff --git a/eth2/utils/tree_hash_derive/src/lib.rs b/eth2/utils/tree_hash_derive/src/lib.rs index 3ba846307..b111ae7c4 100644 --- a/eth2/utils/tree_hash_derive/src/lib.rs +++ b/eth2/utils/tree_hash_derive/src/lib.rs @@ -56,7 +56,7 @@ pub fn subtree_derive(input: TokenStream) -> TokenStream { let idents_c = idents_a.clone(); let output = quote! { - impl cached_tree_hash::CachedTreeHash<#name> for #name { + impl cached_tree_hash::CachedTreeHash for #name { fn new_tree_hash_cache(&self, depth: usize) -> Result { let tree = cached_tree_hash::TreeHashCache::from_leaves_and_subtrees( self, diff --git a/eth2/utils/tree_hash_derive/tests/tests.rs b/eth2/utils/tree_hash_derive/tests/tests.rs index 2166fd146..11eae4e02 100644 --- a/eth2/utils/tree_hash_derive/tests/tests.rs +++ b/eth2/utils/tree_hash_derive/tests/tests.rs @@ -10,10 +10,7 @@ pub struct Inner { pub d: u64, } -fn test_standard_and_cached(original: &T, modified: &T) -where - T: CachedTreeHash, -{ +fn test_standard_and_cached(original: &T, modified: &T) { // let mut cache = original.new_tree_hash_cache().unwrap(); let mut hasher = CachedTreeHasher::new(original).unwrap();