mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-09 04:21:22 +00:00
84e6d71950
## Proposed Changes Remove the remaining Altair `FIXME`s from consensus land. 1. Implement tree hash caching for the participation lists. This required some light type manipulation, including removing the `TreeHash` bound from `CachedTreeHash` which was purely descriptive. 2. Plumb the proposer index through Altair attestation processing, to avoid calculating it for _every_ attestation (potentially 128ms on large networks). This duplicates some work from #2431, but with the aim of getting it in sooner, particularly for the Altair devnets. 3. Removes two FIXMEs related to `superstruct` and cloning, which are unlikely to be particularly detrimental and will be tracked here instead: https://github.com/sigp/superstruct/issues/5
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
mod cache;
|
|
mod cache_arena;
|
|
mod impls;
|
|
#[cfg(test)]
|
|
mod test;
|
|
use smallvec::SmallVec;
|
|
|
|
type SmallVec8<T> = SmallVec<[T; 8]>;
|
|
pub type CacheArena = cache_arena::CacheArena<Hash256>;
|
|
|
|
pub use crate::cache::TreeHashCache;
|
|
pub use crate::impls::int_log;
|
|
use ethereum_types::H256 as Hash256;
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
pub enum Error {
|
|
/// Attempting to provide more than 2^depth leaves to a Merkle tree is disallowed.
|
|
TooManyLeaves,
|
|
/// Shrinking a Merkle tree cache by providing it with less leaves than it currently has is
|
|
/// disallowed (for simplicity).
|
|
CannotShrink,
|
|
/// Cache is inconsistent with the list of dirty indices provided.
|
|
CacheInconsistent,
|
|
CacheArenaError(cache_arena::Error),
|
|
/// Unable to find left index in Merkle tree.
|
|
MissingLeftIdx(usize),
|
|
}
|
|
|
|
impl From<cache_arena::Error> for Error {
|
|
fn from(e: cache_arena::Error) -> Error {
|
|
Error::CacheArenaError(e)
|
|
}
|
|
}
|
|
|
|
/// Trait for types which can make use of a cache to accelerate calculation of their tree hash root.
|
|
pub trait CachedTreeHash<Cache> {
|
|
/// Create a new cache appropriate for use with values of this type.
|
|
fn new_tree_hash_cache(&self, arena: &mut CacheArena) -> Cache;
|
|
|
|
/// Update the cache and use it to compute the tree hash root for `self`.
|
|
fn recalculate_tree_hash_root(
|
|
&self,
|
|
arena: &mut CacheArena,
|
|
cache: &mut Cache,
|
|
) -> Result<Hash256, Error>;
|
|
}
|