@ -59,6 +59,11 @@ pub type TransactionLoaders = Vec<Vec<(Pubkey, Account)>>;
|
||||
|
||||
pub type TransactionLoadResult = (TransactionAccounts, TransactionLoaders, TransactionRent);
|
||||
|
||||
pub enum AccountAddressFilter {
|
||||
Exclude, // exclude all addresses matching the fiter
|
||||
Include, // only include addresses matching the filter
|
||||
}
|
||||
|
||||
impl Accounts {
|
||||
pub fn new(paths: Vec<PathBuf>) -> Self {
|
||||
Self::new_with_frozen_accounts(paths, &HashMap::default(), &[])
|
||||
@ -407,6 +412,39 @@ impl Accounts {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_largest_accounts(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
num: usize,
|
||||
filter_by_address: &HashSet<Pubkey>,
|
||||
filter: AccountAddressFilter,
|
||||
) -> Vec<(Pubkey, u64)> {
|
||||
let mut accounts_balances = self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
|collector: &mut Vec<(Pubkey, u64)>, option| {
|
||||
if let Some(data) = option
|
||||
.filter(|(pubkey, account, _)| {
|
||||
let should_include_pubkey = match filter {
|
||||
AccountAddressFilter::Exclude => !filter_by_address.contains(&pubkey),
|
||||
AccountAddressFilter::Include => filter_by_address.contains(&pubkey),
|
||||
};
|
||||
should_include_pubkey
|
||||
&& account.lamports != 0
|
||||
&& !(account.lamports == std::u64::MAX
|
||||
&& account.owner == solana_storage_program::id())
|
||||
})
|
||||
.map(|(pubkey, account, _slot)| (*pubkey, account.lamports))
|
||||
{
|
||||
collector.push(data)
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
accounts_balances.sort_by(|a, b| a.1.cmp(&b.1).reverse());
|
||||
accounts_balances.truncate(num);
|
||||
accounts_balances
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn verify_bank_hash(&self, slot: Slot, ancestors: &Ancestors) -> bool {
|
||||
if let Err(err) = self.accounts_db.verify_bank_hash(slot, ancestors) {
|
||||
|
@ -3,7 +3,10 @@
|
||||
//! on behalf of the caller, and a low-level API for when they have
|
||||
//! already been signed and verified.
|
||||
use crate::{
|
||||
accounts::{Accounts, TransactionAccounts, TransactionLoadResult, TransactionLoaders},
|
||||
accounts::{
|
||||
AccountAddressFilter, Accounts, TransactionAccounts, TransactionLoadResult,
|
||||
TransactionLoaders,
|
||||
},
|
||||
accounts_db::{AccountsDBSerialize, ErrorCounters, SnapshotStorage, SnapshotStorages},
|
||||
accounts_index::Ancestors,
|
||||
blockhash_queue::BlockhashQueue,
|
||||
@ -58,7 +61,7 @@ use solana_stake_program::stake_state::{self, Delegation};
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
collections::{HashMap, HashSet},
|
||||
io::{BufReader, Cursor, Error as IOError, Read},
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
@ -1844,6 +1847,17 @@ impl Bank {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_largest_accounts(
|
||||
&self,
|
||||
num: usize,
|
||||
filter_by_address: &HashSet<Pubkey>,
|
||||
filter: AccountAddressFilter,
|
||||
) -> Vec<(Pubkey, u64)> {
|
||||
self.rc
|
||||
.accounts
|
||||
.load_largest_accounts(&self.ancestors, num, filter_by_address, filter)
|
||||
}
|
||||
|
||||
pub fn transaction_count(&self) -> u64 {
|
||||
self.transaction_count.load(Ordering::Relaxed)
|
||||
}
|
||||
|
Reference in New Issue
Block a user