mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 22:08:30 +00:00
Merge branch '368' into ef-tests
This commit is contained in:
@@ -60,29 +60,36 @@ impl CachedTreeHash for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl CachedTreeHash for [u8; 4] {
|
||||
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
||||
Ok(TreeHashCache::from_bytes(
|
||||
merkleize(self.to_vec()),
|
||||
false,
|
||||
None,
|
||||
)?)
|
||||
}
|
||||
macro_rules! impl_for_u8_array {
|
||||
($len: expr) => {
|
||||
impl CachedTreeHash for [u8; $len] {
|
||||
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
||||
Ok(TreeHashCache::from_bytes(
|
||||
merkleize(self.to_vec()),
|
||||
false,
|
||||
None,
|
||||
)?)
|
||||
}
|
||||
|
||||
fn tree_hash_cache_schema(&self, depth: usize) -> BTreeSchema {
|
||||
BTreeSchema::from_lengths(depth, vec![1])
|
||||
}
|
||||
fn tree_hash_cache_schema(&self, depth: usize) -> BTreeSchema {
|
||||
BTreeSchema::from_lengths(depth, vec![1])
|
||||
}
|
||||
|
||||
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
|
||||
let leaf = merkleize(self.to_vec());
|
||||
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
|
||||
fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> {
|
||||
let leaf = merkleize(self.to_vec());
|
||||
cache.maybe_update_chunk(cache.chunk_index, &leaf)?;
|
||||
|
||||
cache.chunk_index += 1;
|
||||
cache.chunk_index += 1;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_for_u8_array!(4);
|
||||
impl_for_u8_array!(32);
|
||||
|
||||
impl CachedTreeHash for H256 {
|
||||
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
||||
Ok(TreeHashCache::from_bytes(
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use super::*;
|
||||
// use cached_tree_hash::CachedTreeHash;
|
||||
// use ssz::{Decode, Encode};
|
||||
// use tree_hash::TreeHash;
|
||||
|
||||
impl<T, N: Unsigned> tree_hash::TreeHash for FixedLenVec<T, N>
|
||||
where
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Decode for bool {
|
||||
_ => {
|
||||
return Err(DecodeError::BytesInvalid(
|
||||
format!("Out-of-range for boolean: {}", bytes[0]).to_string(),
|
||||
))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,6 +156,7 @@ macro_rules! impl_decodable_for_u8_array {
|
||||
}
|
||||
|
||||
impl_decodable_for_u8_array!(4);
|
||||
impl_decodable_for_u8_array!(32);
|
||||
|
||||
impl<T: Decode> Decode for Vec<T> {
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
|
||||
@@ -132,6 +132,7 @@ macro_rules! impl_encodable_for_u8_array {
|
||||
}
|
||||
|
||||
impl_encodable_for_u8_array!(4);
|
||||
impl_encodable_for_u8_array!(32);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -41,12 +41,6 @@ fn get_serializable_field_types<'a>(struct_data: &'a syn::DataStruct) -> Vec<&'a
|
||||
None
|
||||
} else {
|
||||
Some(&f.ty)
|
||||
/*
|
||||
Some(match &f.ident {
|
||||
Some(ref ident) => ident,
|
||||
_ => panic!("ssz_derive only supports named struct fields."),
|
||||
})
|
||||
*/
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -51,24 +51,31 @@ impl TreeHash for bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeHash for [u8; 4] {
|
||||
fn tree_hash_type() -> TreeHashType {
|
||||
TreeHashType::Vector
|
||||
}
|
||||
macro_rules! impl_for_u8_array {
|
||||
($len: expr) => {
|
||||
impl TreeHash for [u8; $len] {
|
||||
fn tree_hash_type() -> TreeHashType {
|
||||
TreeHashType::Vector
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
unreachable!("bytesN should never be packed.")
|
||||
}
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
unreachable!("bytesN should never be packed.")
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
unreachable!("bytesN should never be packed.")
|
||||
}
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
unreachable!("bytesN should never be packed.")
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
merkle_root(&self[..])
|
||||
}
|
||||
fn tree_hash_root(&self) -> Vec<u8> {
|
||||
merkle_root(&self[..])
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_for_u8_array!(4);
|
||||
impl_for_u8_array!(32);
|
||||
|
||||
impl TreeHash for H256 {
|
||||
fn tree_hash_type() -> TreeHashType {
|
||||
TreeHashType::Vector
|
||||
|
||||
Reference in New Issue
Block a user