Introduce eager rent collection (#9527)
* Switch AccountsIndex.account_maps from HashMap to BTreeMap * Introduce eager rent collection * Start to add tests * Avoid too short eager rent collection cycles * Add more tests * Add more tests... * Refacotr!!!!!! * Refactoring follow up * More tiny cleanups * Don't rewrite 0-lamport accounts to be deterministic * Refactor a bit * Do hard fork, restore tests, and perf. mitigation * Fix build... * Refactor and add switch over for testnet (TdS) * Use to_be_bytes * cleanup * More tiny cleanup * Rebase cleanup * Set Bank::genesis_hash when resuming from snapshot * Reorder fns and clean ups * Better naming and commenting * Yet more naming clarifications * Make prefix width strictly uniform for 2-base partition_count * Fix typo... * Revert cluster-dependent gate * kick ci? * kick ci? * kick ci?
This commit is contained in:
@@ -27,6 +27,7 @@ use solana_sdk::{
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
io::{BufReader, Error as IOError, Read},
|
||||
ops::RangeBounds,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
};
|
||||
@@ -455,6 +456,21 @@ impl Accounts {
|
||||
}
|
||||
}
|
||||
|
||||
fn load_while_filtering<F: Fn(&Account) -> bool>(
|
||||
collector: &mut Vec<(Pubkey, Account)>,
|
||||
option: Option<(&Pubkey, Account, Slot)>,
|
||||
filter: F,
|
||||
) {
|
||||
if let Some(data) = option
|
||||
// Don't ever load zero lamport accounts into runtime because
|
||||
// the existence of zero-lamport accounts are never deterministic!!
|
||||
.filter(|(_, account, _)| account.lamports > 0 && filter(account))
|
||||
.map(|(pubkey, account, _slot)| (*pubkey, account))
|
||||
{
|
||||
collector.push(data)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_by_program(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
@@ -463,15 +479,23 @@ impl Accounts {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, option| {
|
||||
if let Some(data) = option
|
||||
.filter(|(_, account, _)| {
|
||||
(program_id.is_none() || Some(&account.owner) == program_id)
|
||||
&& account.lamports != 0
|
||||
})
|
||||
.map(|(pubkey, account, _slot)| (*pubkey, account))
|
||||
{
|
||||
collector.push(data)
|
||||
}
|
||||
Self::load_while_filtering(collector, option, |account| {
|
||||
program_id.is_none() || Some(&account.owner) == program_id
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn load_to_collect_rent_eagerly<R: RangeBounds<Pubkey>>(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
range: R,
|
||||
) -> Vec<(Pubkey, Account)> {
|
||||
self.accounts_db.range_scan_accounts(
|
||||
ancestors,
|
||||
range,
|
||||
|collector: &mut Vec<(Pubkey, Account)>, option| {
|
||||
Self::load_while_filtering(collector, option, |_| true)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user