Uses AccountHash in CalculateHashIntermediate (#33822)
This commit is contained in:
parent
b0dcaf29e3
commit
2f024f0cc1
|
@ -2419,7 +2419,7 @@ impl<'a> AppendVecScan for ScanState<'a> {
|
|||
}
|
||||
}
|
||||
let source_item = CalculateHashIntermediate {
|
||||
hash: loaded_hash.0,
|
||||
hash: loaded_hash,
|
||||
lamports: balance,
|
||||
pubkey: *pubkey,
|
||||
};
|
||||
|
@ -10400,22 +10400,22 @@ pub mod tests {
|
|||
|
||||
let mut raw_expected = vec![
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: 1,
|
||||
pubkey: pubkey0,
|
||||
},
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: 128,
|
||||
pubkey: pubkey127,
|
||||
},
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: 129,
|
||||
pubkey: pubkey128,
|
||||
},
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: 256,
|
||||
pubkey: pubkey255,
|
||||
},
|
||||
|
@ -10438,7 +10438,7 @@ pub mod tests {
|
|||
));
|
||||
let hash = AccountsDb::hash_account(&raw_accounts[i], &raw_expected[i].pubkey);
|
||||
assert_eq!(hash, expected_hashes[i]);
|
||||
raw_expected[i].hash = hash.0;
|
||||
raw_expected[i].hash = hash;
|
||||
}
|
||||
|
||||
let to_store = raw_accounts
|
||||
|
@ -10925,7 +10925,7 @@ pub mod tests {
|
|||
let (storages, raw_expected) = sample_storages_and_accounts(&db);
|
||||
let expected_hash =
|
||||
AccountsHasher::compute_merkle_root_loop(raw_expected.clone(), MERKLE_FANOUT, |item| {
|
||||
&item.hash
|
||||
&item.hash.0
|
||||
});
|
||||
let sum = raw_expected.iter().map(|item| item.lamports).sum();
|
||||
let result = db
|
||||
|
@ -10974,7 +10974,7 @@ pub mod tests {
|
|||
assert_eq!(loaded_account.pubkey(), &self.pubkey);
|
||||
assert_eq!(self.slot_expected, self.current_slot);
|
||||
self.accum.push(vec![CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: self.value_to_use_for_lamports,
|
||||
pubkey: self.pubkey,
|
||||
}]);
|
||||
|
@ -11035,7 +11035,7 @@ pub mod tests {
|
|||
assert_scan(
|
||||
result2,
|
||||
vec![vec![vec![CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: expected,
|
||||
pubkey,
|
||||
}]]],
|
||||
|
@ -11263,7 +11263,7 @@ pub mod tests {
|
|||
assert_eq!(self.accum.len(), 1);
|
||||
}
|
||||
self.accum.push(vec![CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: loaded_account.lamports(),
|
||||
pubkey: Pubkey::default(),
|
||||
}]);
|
||||
|
|
|
@ -316,9 +316,9 @@ impl HashStats {
|
|||
/// Note this can be saved/loaded during hash calculation to a memory mapped file whose contents are
|
||||
/// [CalculateHashIntermediate]
|
||||
#[repr(C)]
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, Copy, Pod, Zeroable)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Pod, Zeroable)]
|
||||
pub struct CalculateHashIntermediate {
|
||||
pub hash: Hash,
|
||||
pub hash: AccountHash,
|
||||
pub lamports: u64,
|
||||
pub pubkey: Pubkey,
|
||||
}
|
||||
|
@ -326,7 +326,9 @@ pub struct CalculateHashIntermediate {
|
|||
// In order to safely guarantee CalculateHashIntermediate is Pod, it cannot have any padding
|
||||
const _: () = assert!(
|
||||
std::mem::size_of::<CalculateHashIntermediate>()
|
||||
== std::mem::size_of::<Hash>() + std::mem::size_of::<u64>() + std::mem::size_of::<Pubkey>(),
|
||||
== std::mem::size_of::<AccountHash>()
|
||||
+ std::mem::size_of::<u64>()
|
||||
+ std::mem::size_of::<Pubkey>(),
|
||||
"CalculateHashIntermediate cannot have any padding"
|
||||
);
|
||||
|
||||
|
@ -1168,7 +1170,7 @@ impl<'a> AccountsHasher<'a> {
|
|||
overall_sum = Self::checked_cast_for_capitalization(
|
||||
item.lamports as u128 + overall_sum as u128,
|
||||
);
|
||||
hashes.write(&item.hash);
|
||||
hashes.write(&item.hash.0);
|
||||
}
|
||||
} else {
|
||||
// if lamports == 0, check if they should be included
|
||||
|
@ -1406,7 +1408,7 @@ mod tests {
|
|||
(0..*count).map(move |_| {
|
||||
let binner = PubkeyBinCalculator24::new(bins);
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::default(),
|
||||
hash: AccountHash(Hash::default()),
|
||||
lamports: 0,
|
||||
pubkey: binner.lowest_pubkey_from_bin(bin, bins),
|
||||
}
|
||||
|
@ -1558,7 +1560,7 @@ mod tests {
|
|||
let mut account_maps = Vec::new();
|
||||
|
||||
let pubkey = Pubkey::from([11u8; 32]);
|
||||
let hash = Hash::new(&[1u8; 32]);
|
||||
let hash = AccountHash(Hash::new(&[1u8; 32]));
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
lamports: 88,
|
||||
|
@ -1568,7 +1570,7 @@ mod tests {
|
|||
|
||||
// 2nd key - zero lamports, so will be removed
|
||||
let pubkey = Pubkey::from([12u8; 32]);
|
||||
let hash = Hash::new(&[2u8; 32]);
|
||||
let hash = AccountHash(Hash::new(&[2u8; 32]));
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
lamports: 0,
|
||||
|
@ -1585,7 +1587,7 @@ mod tests {
|
|||
|
||||
// 3rd key - with pubkey value before 1st key so it will be sorted first
|
||||
let pubkey = Pubkey::from([10u8; 32]);
|
||||
let hash = Hash::new(&[2u8; 32]);
|
||||
let hash = AccountHash(Hash::new(&[2u8; 32]));
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
lamports: 20,
|
||||
|
@ -1600,7 +1602,7 @@ mod tests {
|
|||
|
||||
// 3rd key - with later slot
|
||||
let pubkey = Pubkey::from([10u8; 32]);
|
||||
let hash = Hash::new(&[99u8; 32]);
|
||||
let hash = AccountHash(Hash::new(&[99u8; 32]));
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
lamports: 30,
|
||||
|
@ -1626,7 +1628,8 @@ mod tests {
|
|||
fn test_accountsdb_de_dup_accounts_zero_chunks() {
|
||||
let vec = vec![vec![CalculateHashIntermediate {
|
||||
lamports: 1,
|
||||
..CalculateHashIntermediate::default()
|
||||
hash: AccountHash(Hash::default()),
|
||||
pubkey: Pubkey::default(),
|
||||
}]];
|
||||
let temp_vec = vec.to_vec();
|
||||
let slice = convert_to_slice(&temp_vec);
|
||||
|
@ -1692,7 +1695,7 @@ mod tests {
|
|||
let key_b = Pubkey::from([2u8; 32]);
|
||||
let key_c = Pubkey::from([3u8; 32]);
|
||||
const COUNT: usize = 6;
|
||||
let hashes = (0..COUNT).map(|i| Hash::new(&[i as u8; 32]));
|
||||
let hashes = (0..COUNT).map(|i| AccountHash(Hash::new(&[i as u8; 32])));
|
||||
// create this vector
|
||||
// abbbcc
|
||||
let keys = [key_a, key_b, key_b, key_b, key_c, key_c];
|
||||
|
@ -1856,7 +1859,7 @@ mod tests {
|
|||
fn test_accountsdb_compare_two_hash_entries() {
|
||||
solana_logger::setup();
|
||||
let pubkey = Pubkey::new_unique();
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
lamports: 1,
|
||||
|
@ -1864,7 +1867,7 @@ mod tests {
|
|||
};
|
||||
|
||||
// slot same, version <
|
||||
let hash2 = Hash::new_unique();
|
||||
let hash2 = AccountHash(Hash::new_unique());
|
||||
let val2 = CalculateHashIntermediate {
|
||||
hash: hash2,
|
||||
lamports: 4,
|
||||
|
@ -1876,7 +1879,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// slot same, vers =
|
||||
let hash3 = Hash::new_unique();
|
||||
let hash3 = AccountHash(Hash::new_unique());
|
||||
let val3 = CalculateHashIntermediate {
|
||||
hash: hash3,
|
||||
lamports: 2,
|
||||
|
@ -1888,7 +1891,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// slot same, vers >
|
||||
let hash4 = Hash::new_unique();
|
||||
let hash4 = AccountHash(Hash::new_unique());
|
||||
let val4 = CalculateHashIntermediate {
|
||||
hash: hash4,
|
||||
lamports: 6,
|
||||
|
@ -1900,7 +1903,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// slot >, version <
|
||||
let hash5 = Hash::new_unique();
|
||||
let hash5 = AccountHash(Hash::new_unique());
|
||||
let val5 = CalculateHashIntermediate {
|
||||
hash: hash5,
|
||||
lamports: 8,
|
||||
|
@ -1925,7 +1928,7 @@ mod tests {
|
|||
solana_logger::setup();
|
||||
|
||||
let pubkey = Pubkey::new_unique();
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let mut account_maps = Vec::new();
|
||||
let val = CalculateHashIntermediate {
|
||||
hash,
|
||||
|
@ -1939,7 +1942,7 @@ mod tests {
|
|||
let (hashfile, lamports) = test_de_dup_accounts_in_parallel(&slice);
|
||||
assert_eq!(
|
||||
(get_vec(hashfile), lamports),
|
||||
(vec![val.hash], val.lamports)
|
||||
(vec![val.hash.0], val.lamports)
|
||||
);
|
||||
|
||||
// zero original lamports, higher version
|
||||
|
@ -1962,7 +1965,7 @@ mod tests {
|
|||
for reverse in [false, true] {
|
||||
let key = Pubkey::new_from_array([1; 32]); // key is BEFORE key2
|
||||
let key2 = Pubkey::new_from_array([2; 32]);
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let mut account_maps = Vec::new();
|
||||
let mut account_maps2 = Vec::new();
|
||||
let val = CalculateHashIntermediate {
|
||||
|
@ -1993,7 +1996,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
(get_vec(hashfile), lamports),
|
||||
(
|
||||
vec![val.hash, if reverse { val2.hash } else { val3.hash }],
|
||||
vec![val.hash.0, if reverse { val2.hash.0 } else { val3.hash.0 }],
|
||||
val.lamports
|
||||
+ if reverse {
|
||||
val2.lamports
|
||||
|
@ -2012,7 +2015,7 @@ mod tests {
|
|||
for reverse in [false, true] {
|
||||
let key = Pubkey::new_from_array([3; 32]); // key is AFTER key2
|
||||
let key2 = Pubkey::new_from_array([2; 32]);
|
||||
let hash = Hash::new_unique();
|
||||
let hash = AccountHash(Hash::new_unique());
|
||||
let mut account_maps = Vec::new();
|
||||
let mut account_maps2 = Vec::new();
|
||||
let val2 = CalculateHashIntermediate {
|
||||
|
@ -2043,7 +2046,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
(get_vec(hashfile), lamports),
|
||||
(
|
||||
vec![if reverse { val2.hash } else { val3.hash }, val.hash],
|
||||
vec![if reverse { val2.hash.0 } else { val3.hash.0 }, val.hash.0],
|
||||
val.lamports
|
||||
+ if reverse {
|
||||
val2.lamports
|
||||
|
@ -2399,12 +2402,12 @@ mod tests {
|
|||
let offset = 2;
|
||||
let input = vec![
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::new(&[1u8; 32]),
|
||||
hash: AccountHash(Hash::new(&[1u8; 32])),
|
||||
lamports: u64::MAX - offset,
|
||||
pubkey: Pubkey::new_unique(),
|
||||
},
|
||||
CalculateHashIntermediate {
|
||||
hash: Hash::new(&[2u8; 32]),
|
||||
hash: AccountHash(Hash::new(&[2u8; 32])),
|
||||
lamports: offset + 1,
|
||||
pubkey: Pubkey::new_unique(),
|
||||
},
|
||||
|
@ -2433,12 +2436,12 @@ mod tests {
|
|||
let offset = 2;
|
||||
let input = vec![
|
||||
vec![CalculateHashIntermediate {
|
||||
hash: Hash::new(&[1u8; 32]),
|
||||
hash: AccountHash(Hash::new(&[1u8; 32])),
|
||||
lamports: u64::MAX - offset,
|
||||
pubkey: Pubkey::new_unique(),
|
||||
}],
|
||||
vec![CalculateHashIntermediate {
|
||||
hash: Hash::new(&[2u8; 32]),
|
||||
hash: AccountHash(Hash::new(&[2u8; 32])),
|
||||
lamports: offset + 1,
|
||||
pubkey: Pubkey::new_unique(),
|
||||
}],
|
||||
|
|
|
@ -362,7 +362,7 @@ impl CacheHashData {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {super::*, rand::Rng};
|
||||
use {super::*, crate::accounts_hash::AccountHash, rand::Rng};
|
||||
|
||||
impl CacheHashData {
|
||||
/// load from 'file_name' into 'accumulator'
|
||||
|
@ -503,7 +503,7 @@ mod tests {
|
|||
}
|
||||
|
||||
CalculateHashIntermediate {
|
||||
hash: solana_sdk::hash::Hash::new_unique(),
|
||||
hash: AccountHash(solana_sdk::hash::Hash::new_unique()),
|
||||
lamports: ct as u64,
|
||||
pubkey: pk,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue