From 963eae9ff8b10e69719cae523f5990d101e4aff1 Mon Sep 17 00:00:00 2001 From: jeff washington Date: Thu, 6 Apr 2023 17:34:37 -0500 Subject: [PATCH] disk index: bucket_index_ix doesn't % by capacity --- bucket_map/src/bucket.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bucket_map/src/bucket.rs b/bucket_map/src/bucket.rs index d5ab4595789af2..37c6cb84429b98 100644 --- a/bucket_map/src/bucket.rs +++ b/bucket_map/src/bucket.rs @@ -183,7 +183,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { key: &Pubkey, random: u64, ) -> Result<(Option>, u64), BucketMapError> { - let ix = Self::bucket_index_ix(index, key, random); + let ix = Self::bucket_index_ix(key, random) % index.capacity(); let mut first_free = None; let mut m = Measure::start("bucket_find_index_entry_mut"); let capacity = index.capacity(); @@ -222,7 +222,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { key: &Pubkey, random: u64, ) -> Option<(IndexEntryPlaceInBucket, u64)> { - let ix = Self::bucket_index_ix(index, key, random); + let ix = Self::bucket_index_ix(key, random) % index.capacity(); for i in ix..ix + index.max_search() { let ii = i % index.capacity(); if index.is_free(ii) { @@ -243,7 +243,7 @@ impl<'b, T: Clone + Copy + 'static> Bucket { is_resizing: bool, ) -> Result { let mut m = Measure::start("bucket_create_key"); - let ix = Self::bucket_index_ix(index, key, random); + let ix = Self::bucket_index_ix(key, random) % index.capacity(); for i in ix..ix + index.max_search() { let ii = i % index.capacity(); if !index.is_free(ii) { @@ -568,15 +568,14 @@ impl<'b, T: Clone + Copy + 'static> Bucket { items.data = Some((data_index, new_bucket)); } - fn bucket_index_ix(index: &BucketStorage>, key: &Pubkey, random: u64) -> u64 { + fn bucket_index_ix(key: &Pubkey, random: u64) -> u64 { let mut s = DefaultHasher::new(); key.hash(&mut s); //the locally generated random will make it hard for an attacker //to deterministically cause all the pubkeys to land in the same //location in any bucket on all validators random.hash(&mut s); - let ix = s.finish(); - ix % index.capacity() + s.finish() //debug!( "INDEX_IX: {:?} uid:{} loc: {} cap:{}", key, uid, location, index.capacity() ); }