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

@@ -7,6 +7,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;
@@ -145,6 +146,13 @@ impl<PublicKey, T: TSignature<PublicKey>> TreeHash for GenericSignature<PublicKe
impl_tree_hash!(SIGNATURE_BYTES_LEN);
}
/// Hashes the `self.serialize()` bytes.
impl<PublicKey, T: TSignature<PublicKey>> Hash for GenericSignature<PublicKey, T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.serialize().hash(state);
}
}
impl<PublicKey, T: TSignature<PublicKey>> fmt::Display for GenericSignature<PublicKey, T> {
impl_display!();
}