Skip to content

Commit

Permalink
manual backport of #28422 (#28532)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Oct 21, 2022
1 parent 8167e15 commit 5571aca
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 1,372 deletions.
48 changes: 2 additions & 46 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use {
bank::Rewrites,
cache_hash_data::CacheHashData,
contains::Contains,
expected_rent_collection::{ExpectedRentCollection, SlotInfoInEpoch},
pubkey_bins::PubkeyBinCalculator24,
read_only_accounts_cache::ReadOnlyAccountsCache,
rent_collector::RentCollector,
Expand Down Expand Up @@ -1793,26 +1792,22 @@ trait AppendVecScan: Send + Sync + Clone {
/// These would have been captured in a fn from within the scan function.
/// Some of these are constant across all pubkeys, some are constant across a slot.
/// Some could be unique per pubkey.
struct ScanState<'a, T: Fn(Slot) -> Option<Slot> + Sync + Send + Clone> {
struct ScanState<'a> {
/// slot we're currently scanning
current_slot: Slot,
/// accumulated results
accum: BinnedHashData,
/// max slot (inclusive) that we're calculating accounts hash on
max_slot_info: SlotInfoInEpoch,
bin_calculator: &'a PubkeyBinCalculator24,
bin_range: &'a Range<usize>,
config: &'a CalcAccountsHashConfig<'a>,
mismatch_found: Arc<AtomicU64>,
stats: &'a crate::accounts_hash::HashStats,
find_unskipped_slot: &'a T,
filler_account_suffix: Option<&'a Pubkey>,
range: usize,
sort_time: Arc<AtomicU64>,
pubkey_to_bin_index: usize,
}

impl<'a, T: Fn(Slot) -> Option<Slot> + Sync + Send + Clone> AppendVecScan for ScanState<'a, T> {
impl<'a> AppendVecScan for ScanState<'a> {
fn set_slot(&mut self, slot: Slot) {
self.current_slot = slot;
}
Expand Down Expand Up @@ -1841,20 +1836,6 @@ impl<'a, T: Fn(Slot) -> Option<Slot> + Sync + Send + Clone> AppendVecScan for Sc
};

let loaded_hash = loaded_account.loaded_hash();
let new_hash = ExpectedRentCollection::maybe_rehash_skipped_rewrite(
loaded_account,
&loaded_hash,
pubkey,
self.current_slot,
self.config.epoch_schedule,
self.config.rent_collector,
self.stats,
&self.max_slot_info,
self.find_unskipped_slot,
self.filler_account_suffix,
);
let loaded_hash = new_hash.unwrap_or(loaded_hash);

let source_item = CalculateHashIntermediate::new(loaded_hash, balance, *pubkey);

if self.config.check_hash
Expand Down Expand Up @@ -6255,8 +6236,6 @@ impl AccountsDb {
let total_lamports = Mutex::<u64>::new(0);
let stats = HashStats::default();

let max_slot_info = SlotInfoInEpoch::new(max_slot, config.epoch_schedule);

let get_hashes = || {
keys.par_chunks(chunks)
.map(|pubkeys| {
Expand Down Expand Up @@ -6289,23 +6268,7 @@ impl AccountsDb {
.get_loaded_account()
.and_then(
|loaded_account| {
let find_unskipped_slot = |slot: Slot| {
self.find_unskipped_slot(slot, config.ancestors)
};
let loaded_hash = loaded_account.loaded_hash();
let new_hash = ExpectedRentCollection::maybe_rehash_skipped_rewrite(
&loaded_account,
&loaded_hash,
pubkey,
*slot,
config.epoch_schedule,
config.rent_collector,
&stats,
&max_slot_info,
find_unskipped_slot,
self.filler_account_suffix.as_ref(),
);
let loaded_hash = new_hash.unwrap_or(loaded_hash);
let balance = loaded_account.lamports();
if config.check_hash && !self.is_filler_account(pubkey) { // this will not be supported anymore
let computed_hash =
Expand Down Expand Up @@ -6890,22 +6853,15 @@ impl AccountsDb {
let range = bin_range.end - bin_range.start;
let sort_time = Arc::new(AtomicU64::new(0));

let find_unskipped_slot = |slot: Slot| self.find_unskipped_slot(slot, config.ancestors);

let max_slot_info =
SlotInfoInEpoch::new(storage.max_slot_inclusive(), config.epoch_schedule);
let scanner = ScanState {
current_slot: Slot::default(),
accum: BinnedHashData::default(),
bin_calculator: &bin_calculator,
config,
mismatch_found: mismatch_found.clone(),
max_slot_info,
find_unskipped_slot: &find_unskipped_slot,
filler_account_suffix,
range,
bin_range,
stats,
sort_time: sort_time.clone(),
pubkey_to_bin_index: 0,
};
Expand Down
18 changes: 1 addition & 17 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use {
builtins::{self, BuiltinAction, BuiltinFeatureTransition, Builtins},
cost_tracker::CostTracker,
epoch_stakes::{EpochStakes, NodeVoteAccounts},
expected_rent_collection::{ExpectedRentCollection, SlotInfoInEpoch},
inline_spl_associated_token_account, inline_spl_token,
message_processor::MessageProcessor,
rent_collector::{CollectedInfo, RentCollector},
Expand Down Expand Up @@ -6381,22 +6380,7 @@ impl Bank {
ancestors: &Ancestors,
pubkey: &Pubkey,
) -> Option<(AccountSharedData, Slot)> {
match self.rc.accounts.load_with_fixed_root(ancestors, pubkey) {
Some((mut account, storage_slot)) => {
ExpectedRentCollection::maybe_update_rent_epoch_on_load(
&mut account,
&SlotInfoInEpoch::new_small(storage_slot),
&SlotInfoInEpoch::new_small(self.slot()),
self.epoch_schedule(),
self.rent_collector(),
pubkey,
&self.rewrites_skipped_this_slot,
);

Some((account, storage_slot))
}
None => None,
}
self.rc.accounts.load_with_fixed_root(ancestors, pubkey)
}

pub fn get_program_accounts(
Expand Down
Loading

0 comments on commit 5571aca

Please sign in to comment.