@@ -35,19 +35,13 @@ use {
3535 crds_value:: { CrdsValue , CrdsValueLabel } ,
3636 } ,
3737 assert_matches:: debug_assert_matches,
38- bincode:: serialize,
3938 indexmap:: {
4039 map:: { rayon:: ParValues , Entry , IndexMap } ,
4140 set:: IndexSet ,
4241 } ,
4342 lru:: LruCache ,
4443 rayon:: { prelude:: * , ThreadPool } ,
45- solana_sdk:: {
46- clock:: Slot ,
47- hash:: { hash, Hash } ,
48- pubkey:: Pubkey ,
49- signature:: Signature ,
50- } ,
44+ solana_sdk:: { clock:: Slot , hash:: Hash , pubkey:: Pubkey , signature:: Signature } ,
5145 std:: {
5246 cmp:: Ordering ,
5347 collections:: { hash_map, BTreeMap , HashMap , VecDeque } ,
@@ -131,8 +125,6 @@ pub struct VersionedCrdsValue {
131125 pub value : CrdsValue ,
132126 /// local time when updated
133127 pub ( crate ) local_timestamp : u64 ,
134- /// value hash
135- pub ( crate ) value_hash : Hash ,
136128 /// None -> value upserted by GossipRoute::{LocalMessage,PullRequest}
137129 /// Some(0) -> value upserted by GossipRoute::PullResponse
138130 /// Some(k) if k > 0 -> value upserted by GossipRoute::PushMessage w/ k - 1 push duplicates
@@ -156,7 +148,6 @@ impl Cursor {
156148
157149impl VersionedCrdsValue {
158150 fn new ( value : CrdsValue , cursor : Cursor , local_timestamp : u64 , route : GossipRoute ) -> Self {
159- let value_hash = hash ( & serialize ( & value) . unwrap ( ) ) ;
160151 let num_push_recv = match route {
161152 GossipRoute :: LocalMessage => None ,
162153 GossipRoute :: PullRequest => None ,
@@ -168,7 +159,6 @@ impl VersionedCrdsValue {
168159 ordinal : cursor. ordinal ( ) ,
169160 value,
170161 local_timestamp,
171- value_hash,
172162 num_push_recv,
173163 }
174164 }
@@ -223,10 +213,7 @@ fn overrides(value: &CrdsValue, other: &VersionedCrdsValue) -> bool {
223213 // Ties should be broken in a deterministic way across the cluster.
224214 // For backward compatibility this is done by comparing hash of
225215 // serialized values.
226- Ordering :: Equal => {
227- let value_hash = hash ( & serialize ( & value) . unwrap ( ) ) ;
228- other. value_hash < value_hash
229- }
216+ Ordering :: Equal => other. value . hash ( ) < value. hash ( ) ,
230217 }
231218}
232219
@@ -310,7 +297,7 @@ impl Crds {
310297 // does not need to be updated.
311298 debug_assert_eq ! ( entry. get( ) . value. pubkey( ) , pubkey) ;
312299 self . cursor . consume ( value. ordinal ) ;
313- self . purged . push_back ( ( entry. get ( ) . value_hash , now) ) ;
300+ self . purged . push_back ( ( * entry. get ( ) . value . hash ( ) , now) ) ;
314301 entry. insert ( value) ;
315302 Ok ( ( ) )
316303 }
@@ -323,8 +310,8 @@ impl Crds {
323310 ) ;
324311 // Identify if the message is outdated (as opposed to
325312 // duplicate) by comparing value hashes.
326- if entry. get ( ) . value_hash != value. value_hash {
327- self . purged . push_back ( ( value. value_hash , now) ) ;
313+ if entry. get ( ) . value . hash ( ) != value. value . hash ( ) {
314+ self . purged . push_back ( ( * value. value . hash ( ) , now) ) ;
328315 Err ( CrdsError :: InsertFailed )
329316 } else if matches ! ( route, GossipRoute :: PushMessage ( _) ) {
330317 let entry = entry. get_mut ( ) ;
@@ -560,7 +547,7 @@ impl Crds {
560547 let Some ( ( index, _ /*label*/ , value) ) = self . table . swap_remove_full ( key) else {
561548 return ;
562549 } ;
563- self . purged . push_back ( ( value. value_hash , now) ) ;
550+ self . purged . push_back ( ( * value. value . hash ( ) , now) ) ;
564551 self . shards . remove ( index, & value) ;
565552 match value. value . data ( ) {
566553 CrdsData :: ContactInfo ( _) => {
@@ -837,7 +824,7 @@ mod tests {
837824 & Pubkey :: default ( ) ,
838825 0 ,
839826 ) ) ) ;
840- let value_hash = hash ( & serialize ( & original) . unwrap ( ) ) ;
827+ let value_hash = * original. hash ( ) ;
841828 assert_matches ! ( crds. insert( original, 0 , GossipRoute :: LocalMessage ) , Ok ( ( ) ) ) ;
842829 let val = CrdsValue :: new_unsigned ( CrdsData :: ContactInfo ( ContactInfo :: new_localhost (
843830 & Pubkey :: default ( ) ,
@@ -857,7 +844,7 @@ mod tests {
857844 & Pubkey :: default ( ) ,
858845 0 ,
859846 ) ) ) ;
860- let val1_hash = hash ( & serialize ( & val1) . unwrap ( ) ) ;
847+ let val1_hash = * val1. hash ( ) ;
861848 assert_eq ! (
862849 crds. insert( val1. clone( ) , 0 , GossipRoute :: LocalMessage ) ,
863850 Ok ( ( ) )
@@ -912,7 +899,7 @@ mod tests {
912899 let other = NodeInstance :: new ( & mut rng, pubkey, now - 1 ) ;
913900 let other = other. with_wallclock ( now + 1 ) ;
914901 let other = make_crds_value ( other) ;
915- let value_hash = hash ( & serialize ( & other) . unwrap ( ) ) ;
902+ let value_hash = * other. hash ( ) ;
916903 assert_eq ! (
917904 crds. insert( other, now, GossipRoute :: LocalMessage ) ,
918905 Err ( CrdsError :: InsertFailed )
@@ -924,7 +911,7 @@ mod tests {
924911 for _ in 0 ..100 {
925912 let other = NodeInstance :: new ( & mut rng, pubkey, now) ;
926913 let other = make_crds_value ( other) ;
927- let value_hash = hash ( & serialize ( & other) . unwrap ( ) ) ;
914+ let value_hash = * other. hash ( ) ;
928915 match crds. insert ( other, now, GossipRoute :: LocalMessage ) {
929916 Ok ( ( ) ) => num_overrides += 1 ,
930917 Err ( CrdsError :: InsertFailed ) => {
@@ -1433,7 +1420,7 @@ mod tests {
14331420 let purged: HashSet < _ > = crds. purged . iter ( ) . map ( |( hash, _) | hash) . copied ( ) . collect ( ) ;
14341421 values
14351422 . into_iter ( )
1436- . filter ( |v| purged. contains ( & v . value_hash ) )
1423+ . filter ( |v| purged. contains ( v . value . hash ( ) ) )
14371424 . collect ( )
14381425 } ;
14391426 assert_eq ! ( purged. len( ) + crds. table. len( ) , num_values) ;
@@ -1515,10 +1502,10 @@ mod tests {
15151502
15161503 assert_eq ! ( v1. value. label( ) , v2. value. label( ) ) ;
15171504 assert_eq ! ( v1. value. wallclock( ) , v2. value. wallclock( ) ) ;
1518- assert_ne ! ( v1. value_hash , v2. value_hash ) ;
1505+ assert_ne ! ( v1. value . hash ( ) , v2. value . hash ( ) ) ;
15191506 assert ! ( v1 != v2) ;
15201507 assert ! ( !( v1 == v2) ) ;
1521- if v1. value_hash > v2. value_hash {
1508+ if v1. value . hash ( ) > v2. value . hash ( ) {
15221509 assert ! ( overrides( & v1. value, & v2) ) ;
15231510 assert ! ( !overrides( & v2. value, & v1) ) ;
15241511 } else {
0 commit comments