Make ledger-tool accounts print rent_epoch and slot (#11845)

This commit is contained in:
Ryo Onodera
2020-08-27 12:28:40 +09:00
committed by GitHub
parent 36e8441149
commit 57174cdabe
3 changed files with 45 additions and 12 deletions

View File

@@ -437,18 +437,22 @@ impl Accounts {
}
}
fn is_loadable(account: &Account) -> bool {
// Don't ever load zero lamport accounts into runtime because
// the existence of zero-lamport accounts are never deterministic!!
account.lamports > 0
}
fn load_while_filtering<F: Fn(&Account) -> bool>(
collector: &mut Vec<(Pubkey, Account)>,
option: Option<(&Pubkey, Account, Slot)>,
some_account_tuple: 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))
if let Some(mapped_account_tuple) = some_account_tuple
.filter(|(_, account, _)| Self::is_loadable(account) && filter(account))
.map(|(pubkey, account, _slot)| (*pubkey, account))
{
collector.push(data)
collector.push(mapped_account_tuple)
}
}
@@ -459,14 +463,27 @@ impl Accounts {
) -> Vec<(Pubkey, Account)> {
self.accounts_db.scan_accounts(
ancestors,
|collector: &mut Vec<(Pubkey, Account)>, option| {
Self::load_while_filtering(collector, option, |account| {
|collector: &mut Vec<(Pubkey, Account)>, some_account_tuple| {
Self::load_while_filtering(collector, some_account_tuple, |account| {
program_id.is_none() || Some(&account.owner) == program_id
})
},
)
}
pub fn load_all(&self, ancestors: &Ancestors) -> Vec<(Pubkey, Account, Slot)> {
self.accounts_db.scan_accounts(
ancestors,
|collector: &mut Vec<(Pubkey, Account, Slot)>, some_account_tuple| {
if let Some((pubkey, account, slot)) =
some_account_tuple.filter(|(_, account, _)| Self::is_loadable(account))
{
collector.push((*pubkey, account, slot))
}
},
)
}
pub fn load_to_collect_rent_eagerly<R: RangeBounds<Pubkey>>(
&self,
ancestors: &Ancestors,

View File

@@ -2685,6 +2685,10 @@ impl Bank {
.load_by_program(&self.ancestors, program_id)
}
pub fn get_all_accounts_with_modified_slots(&self) -> Vec<(Pubkey, Account, Slot)> {
self.rc.accounts.load_all(&self.ancestors)
}
pub fn get_program_accounts_modified_since_parent(
&self,
program_id: &Pubkey,