mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 05:18:30 +00:00
@@ -121,7 +121,6 @@ pub enum Error {
|
||||
state: Slot,
|
||||
},
|
||||
TreeHashError(tree_hash::Error),
|
||||
CachedTreeHashError(cached_tree_hash::Error),
|
||||
InvalidValidatorPubkey(ssz::DecodeError),
|
||||
ValidatorRegistryShrunk,
|
||||
TreeHashCacheInconsistent,
|
||||
@@ -2560,12 +2559,6 @@ impl From<bls::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<cached_tree_hash::Error> for Error {
|
||||
fn from(e: cached_tree_hash::Error) -> Error {
|
||||
Error::CachedTreeHashError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<tree_hash::Error> for Error {
|
||||
fn from(e: tree_hash::Error) -> Error {
|
||||
Error::TreeHashError(e)
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::Unsigned;
|
||||
use crate::{BeaconState, EthSpec, Hash256};
|
||||
use cached_tree_hash::Error;
|
||||
use cached_tree_hash::{int_log, CacheArena, CachedTreeHash, TreeHashCache};
|
||||
use compare_fields_derive::CompareFields;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::VariableList;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::{mix_in_length, TreeHash, BYTES_PER_CHUNK};
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
/// `HistoricalSummary` matches the components of the phase0 `HistoricalBatch`
|
||||
@@ -44,46 +40,3 @@ impl HistoricalSummary {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type allowing the implementation of `CachedTreeHash`.
|
||||
#[derive(Debug)]
|
||||
pub struct HistoricalSummaryCache<'a, N: Unsigned> {
|
||||
pub inner: &'a VariableList<HistoricalSummary, N>,
|
||||
}
|
||||
|
||||
impl<'a, N: Unsigned> HistoricalSummaryCache<'a, N> {
|
||||
pub fn new(inner: &'a VariableList<HistoricalSummary, N>) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.inner.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: Unsigned> CachedTreeHash<TreeHashCache> for HistoricalSummaryCache<'a, N> {
|
||||
fn new_tree_hash_cache(&self, arena: &mut CacheArena) -> TreeHashCache {
|
||||
TreeHashCache::new(arena, int_log(N::to_usize()), self.len())
|
||||
}
|
||||
|
||||
fn recalculate_tree_hash_root(
|
||||
&self,
|
||||
arena: &mut CacheArena,
|
||||
cache: &mut TreeHashCache,
|
||||
) -> Result<Hash256, Error> {
|
||||
Ok(mix_in_length(
|
||||
&cache.recalculate_merkle_root(arena, leaf_iter(self.inner))?,
|
||||
self.len(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn leaf_iter(
|
||||
values: &[HistoricalSummary],
|
||||
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
|
||||
values
|
||||
.iter()
|
||||
.map(|value| value.tree_hash_root())
|
||||
.map(Hash256::to_fixed_bytes)
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ pub mod config_and_preset;
|
||||
pub mod execution_block_header;
|
||||
pub mod fork_context;
|
||||
pub mod participation_flags;
|
||||
pub mod participation_list;
|
||||
pub mod payload;
|
||||
pub mod preset;
|
||||
pub mod slot_epoch;
|
||||
@@ -200,7 +199,6 @@ pub use crate::light_client_update::{
|
||||
LightClientUpdateCapella, LightClientUpdateDeneb, LightClientUpdateElectra,
|
||||
};
|
||||
pub use crate::participation_flags::ParticipationFlags;
|
||||
pub use crate::participation_list::ParticipationList;
|
||||
pub use crate::payload::{
|
||||
AbstractExecPayload, BlindedPayload, BlindedPayloadBellatrix, BlindedPayloadCapella,
|
||||
BlindedPayloadDeneb, BlindedPayloadElectra, BlindedPayloadRef, BlockType, ExecPayload,
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#![allow(clippy::arithmetic_side_effects)]
|
||||
|
||||
use crate::{Hash256, ParticipationFlags, Unsigned, VariableList};
|
||||
use cached_tree_hash::{int_log, CacheArena, CachedTreeHash, Error, TreeHashCache};
|
||||
use tree_hash::{mix_in_length, BYTES_PER_CHUNK};
|
||||
|
||||
/// Wrapper type allowing the implementation of `CachedTreeHash`.
|
||||
#[derive(Debug)]
|
||||
pub struct ParticipationList<'a, N: Unsigned> {
|
||||
pub inner: &'a VariableList<ParticipationFlags, N>,
|
||||
}
|
||||
|
||||
impl<'a, N: Unsigned> ParticipationList<'a, N> {
|
||||
pub fn new(inner: &'a VariableList<ParticipationFlags, N>) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, N: Unsigned> CachedTreeHash<TreeHashCache> for ParticipationList<'a, N> {
|
||||
fn new_tree_hash_cache(&self, arena: &mut CacheArena) -> TreeHashCache {
|
||||
TreeHashCache::new(
|
||||
arena,
|
||||
int_log(N::to_usize() / BYTES_PER_CHUNK),
|
||||
leaf_count(self.inner.len()),
|
||||
)
|
||||
}
|
||||
|
||||
fn recalculate_tree_hash_root(
|
||||
&self,
|
||||
arena: &mut CacheArena,
|
||||
cache: &mut TreeHashCache,
|
||||
) -> Result<Hash256, Error> {
|
||||
Ok(mix_in_length(
|
||||
&cache.recalculate_merkle_root(arena, leaf_iter(self.inner))?,
|
||||
self.inner.len(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn leaf_count(len: usize) -> usize {
|
||||
(len + BYTES_PER_CHUNK - 1) / BYTES_PER_CHUNK
|
||||
}
|
||||
|
||||
pub fn leaf_iter(
|
||||
values: &[ParticipationFlags],
|
||||
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
|
||||
values.chunks(BYTES_PER_CHUNK).map(|xs| {
|
||||
// Zero-pad chunks on the right.
|
||||
let mut chunk = [0u8; BYTES_PER_CHUNK];
|
||||
for (byte, x) in chunk.iter_mut().zip(xs) {
|
||||
*byte = x.into_u8();
|
||||
}
|
||||
chunk
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user