Skip to content

Commit

Permalink
Add accounts_data_len to Bank (solana-labs#21781)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Dec 11, 2021
1 parent e08139f commit eeb97fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 20 additions & 3 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ use {
ptr,
rc::Rc,
sync::{
atomic::{AtomicBool, AtomicU64, Ordering::Relaxed},
atomic::{
AtomicBool, AtomicU64,
Ordering::{Acquire, Relaxed, Release},
},
Arc, LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard,
},
time::{Duration, Instant},
Expand Down Expand Up @@ -1042,6 +1045,10 @@ pub struct Bank {
pub cost_tracker: RwLock<CostTracker>,

sysvar_cache: RwLock<Vec<(Pubkey, Vec<u8>)>>,

/// Current size of the accounts data. Used when processing messages to enforce a limit on its
/// maximum size.
accounts_data_len: AtomicU64,
}

impl Default for BlockhashQueue {
Expand Down Expand Up @@ -1127,7 +1134,7 @@ impl Bank {
}

fn default_with_accounts(accounts: Accounts) -> Self {
Self {
let bank = Self {
rc: BankRc::new(accounts, Slot::default()),
src: StatusCacheRc::default(),
blockhash_queue: RwLock::<BlockhashQueue>::default(),
Expand Down Expand Up @@ -1183,7 +1190,14 @@ impl Bank {
vote_only_bank: false,
cost_tracker: RwLock::<CostTracker>::default(),
sysvar_cache: RwLock::new(Vec::new()),
}
accounts_data_len: AtomicU64::default(),
};

let total_accounts_stats = bank.get_total_accounts_stats().unwrap();
bank.accounts_data_len
.store(total_accounts_stats.data_len as u64, Release);

bank
}

pub fn new_with_paths_for_tests(
Expand Down Expand Up @@ -1429,6 +1443,7 @@ impl Bank {
freeze_started: AtomicBool::new(false),
cost_tracker: RwLock::new(CostTracker::default()),
sysvar_cache: RwLock::new(Vec::new()),
accounts_data_len: AtomicU64::new(parent.accounts_data_len.load(Acquire)),
};

let mut ancestors = Vec::with_capacity(1 + new.parents().len());
Expand Down Expand Up @@ -1541,6 +1556,7 @@ impl Bank {
debug_keys: Option<Arc<HashSet<Pubkey>>>,
additional_builtins: Option<&Builtins>,
debug_do_not_add_builtins: bool,
accounts_data_len: u64,
) -> Self {
fn new<T: Default>() -> T {
T::default()
Expand Down Expand Up @@ -1603,6 +1619,7 @@ impl Bank {
vote_only_bank: false,
cost_tracker: RwLock::new(CostTracker::default()),
sysvar_cache: RwLock::new(Vec::new()),
accounts_data_len: AtomicU64::new(accounts_data_len),
};
bank.finish_init(
genesis_config,
Expand Down
5 changes: 1 addition & 4 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ where
accounts_db_config,
accounts_update_notifier,
)?;
debug!(
"accounts data len: {}",
reconstructed_accounts_db_info.accounts_data_len
);

let bank_rc = BankRc::new(Accounts::new_empty(accounts_db), bank_fields.slot);

Expand All @@ -363,6 +359,7 @@ where
debug_keys,
additional_builtins,
debug_do_not_add_builtins,
reconstructed_accounts_db_info.accounts_data_len,
);

info!("rent_collector: {:?}", bank.rent_collector());
Expand Down

0 comments on commit eeb97fe

Please sign in to comment.