simplifies update_stakes_cache implementation (#32534)

This commit is contained in:
behzad nouri 2023-07-19 18:13:30 +00:00 committed by GitHub
parent 3b8bcb4f7e
commit a8b0c92873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 13 deletions

View File

@ -89,6 +89,7 @@ use {
}, },
byteorder::{ByteOrder, LittleEndian}, byteorder::{ByteOrder, LittleEndian},
dashmap::{DashMap, DashSet}, dashmap::{DashMap, DashSet},
itertools::izip,
log::*, log::*,
percentage::Percentage, percentage::Percentage,
rayon::{ rayon::{
@ -7756,21 +7757,21 @@ impl Bank {
execution_results: &[TransactionExecutionResult], execution_results: &[TransactionExecutionResult],
loaded_txs: &[TransactionLoadResult], loaded_txs: &[TransactionLoadResult],
) { ) {
for (i, ((load_result, _load_nonce), tx)) in loaded_txs.iter().zip(txs).enumerate() { debug_assert_eq!(txs.len(), execution_results.len());
if let (Ok(loaded_transaction), true) = ( debug_assert_eq!(txs.len(), loaded_txs.len());
load_result, izip!(txs, execution_results, loaded_txs)
execution_results[i].was_executed_successfully(), .filter(|(_, execution_result, _)| execution_result.was_executed_successfully())
) { .flat_map(|(tx, _, (load_result, _))| {
load_result.iter().flat_map(|loaded_transaction| {
let num_account_keys = tx.message().account_keys().len();
loaded_transaction.accounts.iter().take(num_account_keys)
})
})
.for_each(|(pubkey, account)| {
// note that this could get timed to: self.rc.accounts.accounts_db.stats.stakes_cache_check_and_store_us, // note that this could get timed to: self.rc.accounts.accounts_db.stats.stakes_cache_check_and_store_us,
// but this code path is captured separately in ExecuteTimingType::UpdateStakesCacheUs // but this code path is captured separately in ExecuteTimingType::UpdateStakesCacheUs
let message = tx.message(); self.stakes_cache.check_and_store(pubkey, account);
for (_i, (pubkey, account)) in });
(0..message.account_keys().len()).zip(loaded_transaction.accounts.iter())
{
self.stakes_cache.check_and_store(pubkey, account);
}
}
}
} }
pub fn staked_nodes(&self) -> Arc<HashMap<Pubkey, u64>> { pub fn staked_nodes(&self) -> Arc<HashMap<Pubkey, u64>> {