Promotes accounts delta hash to its own type (#29768)

This commit is contained in:
Brooks 2023-01-20 14:23:56 -05:00 committed by GitHub
parent 6baab92ab5
commit db10073c36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 11 deletions

View File

@ -25,8 +25,8 @@ use {
accounts_background_service::{DroppedSlotsSender, SendDroppedBankCallback},
accounts_cache::{AccountsCache, CachedAccount, SlotCache},
accounts_hash::{
AccountsHash, AccountsHasher, CalcAccountsHashConfig, CalculateHashIntermediate,
HashStats, ZeroLamportAccounts,
AccountsDeltaHash, AccountsHash, AccountsHasher, CalcAccountsHashConfig,
CalculateHashIntermediate, HashStats, ZeroLamportAccounts,
},
accounts_index::{
AccountIndexGetResult, AccountSecondaryIndexes, AccountsIndex, AccountsIndexConfig,
@ -1076,7 +1076,7 @@ impl BankHashStats {
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, AbiExample)]
pub struct BankHashInfo {
pub accounts_delta_hash: Hash,
pub accounts_delta_hash: AccountsDeltaHash,
pub accounts_hash: AccountsHash,
pub stats: BankHashStats,
}
@ -7437,7 +7437,7 @@ impl AccountsDb {
(hashes, scan.as_us(), accumulate)
}
pub fn get_accounts_delta_hash(&self, slot: Slot) -> Hash {
pub fn get_accounts_delta_hash(&self, slot: Slot) -> AccountsDeltaHash {
let (mut hashes, scan_us, mut accumulate) = self.get_pubkey_hash_for_slot(slot);
let dirty_keys = hashes.iter().map(|(pubkey, _hash)| *pubkey).collect();
@ -7446,7 +7446,8 @@ impl AccountsDb {
hashes.retain(|(pubkey, _hash)| !self.is_filler_account(pubkey));
}
let ret = AccountsHasher::accumulate_account_hashes(hashes);
let accounts_delta_hash =
AccountsDeltaHash(AccountsHasher::accumulate_account_hashes(hashes));
accumulate.stop();
let mut uncleaned_time = Measure::start("uncleaned_index");
self.uncleaned_pubkeys.insert(slot, dirty_keys);
@ -7462,7 +7463,7 @@ impl AccountsDb {
.delta_hash_accumulate_time_total_us
.fetch_add(accumulate.as_us(), Ordering::Relaxed);
self.stats.delta_hash_num.fetch_add(1, Ordering::Relaxed);
ret
accounts_delta_hash
}
fn update_index<'a, T: ReadableAccount + Sync>(
@ -12178,9 +12179,8 @@ pub mod tests {
Err(MissingBankHash)
);
let some_bank_hash = Hash::new(&[0xca; HASH_BYTES]);
let bank_hash_info = BankHashInfo {
accounts_delta_hash: some_bank_hash,
accounts_delta_hash: AccountsDeltaHash(Hash::new(&[0xca; HASH_BYTES])),
accounts_hash: AccountsHash(Hash::new(&[0xca; HASH_BYTES])),
stats: BankHashStats::default(),
};

View File

@ -1120,6 +1120,10 @@ pub enum ZeroLamportAccounts {
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize, Deserialize, AbiExample)]
pub struct AccountsHash(pub Hash);
/// Hash of accounts written in a single slot
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Serialize, Deserialize, AbiExample)]
pub struct AccountsDeltaHash(pub Hash);
#[cfg(test)]
pub mod tests {
use {super::*, std::str::FromStr};

View File

@ -6630,7 +6630,7 @@ impl Bank {
let mut hash = hashv(&[
self.parent_hash.as_ref(),
bank_hash_info.accounts_delta_hash.as_ref(),
bank_hash_info.accounts_delta_hash.0.as_ref(),
&signature_count_buf,
self.last_blockhash().as_ref(),
]);
@ -6662,7 +6662,7 @@ impl Bank {
"bank frozen: {} hash: {} accounts_delta: {} signature_count: {} last_blockhash: {} capitalization: {}{}",
self.slot(),
hash,
bank_hash_info.accounts_delta_hash,
bank_hash_info.accounts_delta_hash.0,
self.signature_count(),
self.last_blockhash(),
self.capitalization(),

View File

@ -691,7 +691,7 @@ mod test_bank_serialize {
// This some what long test harness is required to freeze the ABI of
// Bank's serialization due to versioned nature
#[frozen_abi(digest = "464v92sAyLDZWCXjH6cuQfgrSNuB3PY8cmoVu2dciXvV")]
#[frozen_abi(digest = "DVS6Qqzxe2w86mdaEuVnsdZqXQVXaPab54uCJG2GypT6")]
#[derive(Serialize, AbiExample)]
pub struct BankAbiTestWrapperNewer {
#[serde(serialize_with = "wrapper_newer")]