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::ser::{Serialize, Serializer};
use ssz::{Decode, Encode};
use std::convert::TryInto;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use tree_hash::TreeHash;
@@ -84,6 +85,12 @@ impl<Pub, Sig> PartialEq for GenericSignatureBytes<Pub, Sig> {
}
}
impl<Pub, Sig> Hash for GenericSignatureBytes<Pub, Sig> {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.bytes.hash(hasher);
}
}
/// Serializes the `GenericSignature` in compressed form, storing the bytes in the newly created `Self`.
impl<Pub, Sig> From<GenericSignature<Pub, Sig>> for GenericSignatureBytes<Pub, Sig>
where