Skip to content

Commit

Permalink
comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Pyattaev committed Mar 5, 2025
1 parent 95fc74a commit d8d544e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gossip/src/crds_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ use {
solana_sanitize::{Sanitize, SanitizeError},
solana_signature::Signature,
solana_signer::Signer,
std::borrow::{Borrow, Cow},
std::{
borrow::{Borrow, Cow},
io::Cursor,
mem::MaybeUninit,
},
};

/// CrdsValue that is replicated across the cluster
Expand Down Expand Up @@ -228,13 +232,17 @@ impl<'de> Deserialize<'de> for CrdsValue {
data: CrdsData,
}
let CrdsValue { signature, data } = CrdsValue::deserialize(deserializer)?;
let mut buffer = [0u8; PACKET_DATA_SIZE];
// To compute the hash of the received CrdsData we need to re-serialize it
// PACKET_DATA_SIZE is always enough since we have just received the value in a packet
let mut buffer: MaybeUninit<[u8; PACKET_DATA_SIZE]> = MaybeUninit::uninit();
// SAFETY: we are only using this buffer to store serialize results
let buf_ref = unsafe { buffer.assume_init_mut() };
let position = {
let mut cursor = std::io::Cursor::new(buffer.as_mut());
let mut cursor = Cursor::new(buf_ref.as_mut());
bincode::serialize_into(&mut cursor, &data).map_err(serde::de::Error::custom)?;
cursor.position() as usize
};
let hash = solana_sha256_hasher::hashv(&[signature.as_ref(), &buffer[0..position]]);
let hash = solana_sha256_hasher::hashv(&[signature.as_ref(), &buf_ref[0..position]]);
Ok(Self {
signature,
data,
Expand Down

0 comments on commit d8d544e

Please sign in to comment.