Moves impl of bank_hash_info_at() into hash_internal_state() (#29913)
This commit is contained in:
parent
fbb90603a9
commit
867d2581a6
|
@ -4,7 +4,7 @@ use {
|
||||||
account_rent_state::{check_rent_state_with_account, RentState},
|
account_rent_state::{check_rent_state_with_account, RentState},
|
||||||
accounts_db::{
|
accounts_db::{
|
||||||
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig,
|
AccountShrinkThreshold, AccountsAddRootTiming, AccountsDb, AccountsDbConfig,
|
||||||
BankHashInfo, IncludeSlotInHash, LoadHint, LoadedAccount, ScanStorageResult,
|
IncludeSlotInHash, LoadHint, LoadedAccount, ScanStorageResult,
|
||||||
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING,
|
ACCOUNTS_DB_CONFIG_FOR_BENCHMARKS, ACCOUNTS_DB_CONFIG_FOR_TESTING,
|
||||||
},
|
},
|
||||||
accounts_index::{
|
accounts_index::{
|
||||||
|
@ -1067,17 +1067,6 @@ impl Accounts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bank_hash_info_at(&self, slot: Slot) -> BankHashInfo {
|
|
||||||
let accounts_delta_hash = self.accounts_db.calculate_accounts_delta_hash(slot);
|
|
||||||
let bank_hashes = self.accounts_db.bank_hashes.read().unwrap();
|
|
||||||
let mut bank_hash_info = bank_hashes
|
|
||||||
.get(&slot)
|
|
||||||
.expect("No bank hash was found for this bank, that should not be possible")
|
|
||||||
.clone();
|
|
||||||
bank_hash_info.accounts_delta_hash = accounts_delta_hash;
|
|
||||||
bank_hash_info
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This function will prevent multiple threads from modifying the same account state at the
|
/// This function will prevent multiple threads from modifying the same account state at the
|
||||||
/// same time
|
/// same time
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
|
|
@ -6595,14 +6595,19 @@ impl Bank {
|
||||||
/// Hash the `accounts` HashMap. This represents a validator's interpretation
|
/// Hash the `accounts` HashMap. This represents a validator's interpretation
|
||||||
/// of the delta of the ledger since the last vote and up to now
|
/// of the delta of the ledger since the last vote and up to now
|
||||||
fn hash_internal_state(&self) -> Hash {
|
fn hash_internal_state(&self) -> Hash {
|
||||||
// If there are no accounts, return the hash of the previous state and the latest blockhash
|
let slot = self.slot();
|
||||||
let bank_hash_info = self.rc.accounts.bank_hash_info_at(self.slot());
|
let accounts_delta_hash = self
|
||||||
|
.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.calculate_accounts_delta_hash(slot);
|
||||||
|
|
||||||
let mut signature_count_buf = [0u8; 8];
|
let mut signature_count_buf = [0u8; 8];
|
||||||
LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count());
|
LittleEndian::write_u64(&mut signature_count_buf[..], self.signature_count());
|
||||||
|
|
||||||
let mut hash = hashv(&[
|
let mut hash = hashv(&[
|
||||||
self.parent_hash.as_ref(),
|
self.parent_hash.as_ref(),
|
||||||
bank_hash_info.accounts_delta_hash.0.as_ref(),
|
accounts_delta_hash.0.as_ref(),
|
||||||
&signature_count_buf,
|
&signature_count_buf,
|
||||||
self.last_blockhash().as_ref(),
|
self.last_blockhash().as_ref(),
|
||||||
]);
|
]);
|
||||||
|
@ -6617,24 +6622,23 @@ impl Bank {
|
||||||
.hard_forks
|
.hard_forks
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get_hash_data(self.slot(), self.parent_slot());
|
.get_hash_data(slot, self.parent_slot());
|
||||||
if let Some(buf) = buf {
|
if let Some(buf) = buf {
|
||||||
let hard_forked_hash = extend_and_hash(&hash, &buf);
|
let hard_forked_hash = extend_and_hash(&hash, &buf);
|
||||||
warn!(
|
warn!("hard fork at slot {slot} by hashing {buf:?}: {hash} => {hard_forked_hash}");
|
||||||
"hard fork at slot {} by hashing {:?}: {} => {}",
|
|
||||||
self.slot(),
|
|
||||||
buf,
|
|
||||||
hash,
|
|
||||||
hard_forked_hash
|
|
||||||
);
|
|
||||||
hash = hard_forked_hash;
|
hash = hard_forked_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bank_hash_stats = self
|
||||||
|
.rc
|
||||||
|
.accounts
|
||||||
|
.accounts_db
|
||||||
|
.get_bank_hash_info(slot)
|
||||||
|
.expect("No bank hash was found for this bank, that should not be possible")
|
||||||
|
.stats;
|
||||||
info!(
|
info!(
|
||||||
"bank frozen: {} hash: {} accounts_delta: {} signature_count: {} last_blockhash: {} capitalization: {}{}",
|
"bank frozen: {slot} hash: {hash} accounts_delta: {} signature_count: {} last_blockhash: {} capitalization: {}{}, stats: {bank_hash_stats:?}",
|
||||||
self.slot(),
|
accounts_delta_hash.0,
|
||||||
hash,
|
|
||||||
bank_hash_info.accounts_delta_hash.0,
|
|
||||||
self.signature_count(),
|
self.signature_count(),
|
||||||
self.last_blockhash(),
|
self.last_blockhash(),
|
||||||
self.capitalization(),
|
self.capitalization(),
|
||||||
|
@ -6644,12 +6648,6 @@ impl Bank {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
info!(
|
|
||||||
"accounts hash slot: {} stats: {:?}",
|
|
||||||
self.slot(),
|
|
||||||
bank_hash_info.stats,
|
|
||||||
);
|
|
||||||
hash
|
hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue