Skip to content

Commit

Permalink
do not cache hash
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Nov 6, 2024
1 parent d77d66d commit 5098388
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions types/src/state_store/state_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use aptos_crypto::{
};
use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher};
use bytes::Bytes;
use once_cell::sync::OnceCell;
#[cfg(any(test, feature = "fuzzing"))]
use proptest::{arbitrary::Arbitrary, prelude::*};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -164,7 +163,7 @@ impl StateValueMetadata {
#[derive(Clone, Debug, CryptoHasher)]
pub struct StateValue {
inner: StateValueInner,
hash: OnceCell<HashValue>,
// hash: OnceCell<HashValue>,
}

impl PartialEq for StateValue {
Expand Down Expand Up @@ -235,8 +234,9 @@ impl<'de> Deserialize<'de> for StateValue {
D: Deserializer<'de>,
{
let inner = PersistedStateValue::deserialize(deserializer)?.into_in_mem_form();
let hash = OnceCell::new();
Ok(Self { inner, hash })
// let hash = OnceCell::new();
// Ok(Self { inner, hash })
Ok( Self { inner } )
}
}

Expand All @@ -256,8 +256,9 @@ impl StateValue {

pub fn new_with_metadata(data: Bytes, metadata: StateValueMetadata) -> Self {
let inner = StateValueInner { data, metadata };
let hash = OnceCell::new();
Self { inner, hash }
// let hash = OnceCell::new();
// Self { inner, hash }
Self { inner }
}

pub fn size(&self) -> usize {
Expand Down Expand Up @@ -286,7 +287,7 @@ impl StateValue {

pub fn set_bytes(&mut self, data: Bytes) {
self.inner.data = data;
self.hash = OnceCell::new();
// self.hash = OnceCell::new();
}

pub fn metadata(&self) -> &StateValueMetadata {
Expand Down Expand Up @@ -325,9 +326,7 @@ impl CryptoHash for StateValue {
type Hasher = StateValueHasher;

fn hash(&self) -> HashValue {
*self
.hash
.get_or_init(|| CryptoHash::hash(&self.inner.to_persistable_form()))
CryptoHash::hash(&self.inner.to_persistable_form())
}
}

Expand Down

0 comments on commit 5098388

Please sign in to comment.