mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 18:21:45 +00:00
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:
@@ -1,7 +1,6 @@
|
||||
use crate::sync::RequestId;
|
||||
use lighthouse_network::rpc::methods::BlocksByRangeRequest;
|
||||
use lighthouse_network::PeerId;
|
||||
use ssz::Encode;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::Sub;
|
||||
@@ -390,7 +389,7 @@ impl Attempt {
|
||||
#[allow(clippy::ptr_arg)]
|
||||
fn new<T: EthSpec>(peer_id: PeerId, blocks: &Vec<SignedBeaconBlock<T>>) -> Self {
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
blocks.as_ssz_bytes().hash(&mut hasher);
|
||||
blocks.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
Attempt { peer_id, hash }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user