Lazy hashing for SignedBeaconBlock in sync (#2916)

## Proposed Changes

Allocate less memory in sync by hashing the `SignedBeaconBlock`s in a batch directly, rather than going via SSZ bytes.

Credit to @paulhauner for finding this source of temporary allocations.
This commit is contained in:
Michael Sproul
2022-01-14 07:20:54 +00:00
parent 1c667ad3ca
commit ceeab02e3a
22 changed files with 93 additions and 39 deletions

View File

@@ -9,6 +9,7 @@ use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use ssz::{Decode, Encode};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use tree_hash::TreeHash;
@@ -264,6 +265,18 @@ where
impl_tree_hash!(SIGNATURE_BYTES_LEN);
}
/// Hashes the `self.serialize()` bytes.
#[allow(clippy::derive_hash_xor_eq)]
impl<Pub, AggPub, Sig, AggSig> Hash for GenericAggregateSignature<Pub, AggPub, Sig, AggSig>
where
Sig: TSignature<Pub>,
AggSig: TAggregateSignature<Pub, AggPub, Sig>,
{
fn hash<H: Hasher>(&self, state: &mut H) {
self.serialize().hash(state);
}
}
impl<Pub, AggPub, Sig, AggSig> fmt::Display for GenericAggregateSignature<Pub, AggPub, Sig, AggSig>
where
Sig: TSignature<Pub>,