Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +1196 to +1198
Copy link
Copy Markdown
Contributor Author

@brooksprumo brooksprumo Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was/am worried where Bank::default_with_accounts() is called. I've only seen it in tests, and in those cases the accounts data len here is always zero, and the time the get_total_accounts_stats() takes to run is 50-100 us on my MBP. Let me know if this should be changed though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we rename it to default_for_tests or something and make tests be explicit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, Bank::default_with_accounts() is called by Bank::new_with_paths(), which is called by blockstore_processor when starting from Bank 0. So I'm going to leave the bank functions named the way they are. I feel pretty good, since starting from Bank 0 should have zero accounts (or very few), and the get_total_accounts_stats to get the accounts_data_len will be fast.


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