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