Add fn to get max accounts data size from Bank (#26478)
This commit is contained in:
parent
38d53ef8a2
commit
3b759bcffb
|
@ -1866,7 +1866,11 @@ impl Bank {
|
||||||
cost_tracker: RwLock::new(CostTracker::new_with_account_data_size_limit(
|
cost_tracker: RwLock::new(CostTracker::new_with_account_data_size_limit(
|
||||||
feature_set
|
feature_set
|
||||||
.is_active(&feature_set::cap_accounts_data_len::id())
|
.is_active(&feature_set::cap_accounts_data_len::id())
|
||||||
.then(|| MAX_ACCOUNTS_DATA_LEN.saturating_sub(accounts_data_size_initial)),
|
.then(|| {
|
||||||
|
parent
|
||||||
|
.accounts_data_size_limit()
|
||||||
|
.saturating_sub(accounts_data_size_initial)
|
||||||
|
}),
|
||||||
)),
|
)),
|
||||||
sysvar_cache: RwLock::new(SysvarCache::default()),
|
sysvar_cache: RwLock::new(SysvarCache::default()),
|
||||||
accounts_data_size_initial,
|
accounts_data_size_initial,
|
||||||
|
@ -4279,7 +4283,8 @@ impl Bank {
|
||||||
transaction_accounts,
|
transaction_accounts,
|
||||||
compute_budget.max_invoke_depth.saturating_add(1),
|
compute_budget.max_invoke_depth.saturating_add(1),
|
||||||
tx.message().instructions().len(),
|
tx.message().instructions().len(),
|
||||||
MAX_ACCOUNTS_DATA_LEN.saturating_sub(prev_accounts_data_len),
|
self.accounts_data_size_limit()
|
||||||
|
.saturating_sub(prev_accounts_data_len),
|
||||||
);
|
);
|
||||||
|
|
||||||
let pre_account_state_info =
|
let pre_account_state_info =
|
||||||
|
@ -4653,6 +4658,11 @@ impl Bank {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The maximum allowed size, in bytes, of the accounts data
|
||||||
|
pub fn accounts_data_size_limit(&self) -> u64 {
|
||||||
|
MAX_ACCOUNTS_DATA_LEN
|
||||||
|
}
|
||||||
|
|
||||||
/// Load the accounts data size, in bytes
|
/// Load the accounts data size, in bytes
|
||||||
pub fn load_accounts_data_size(&self) -> u64 {
|
pub fn load_accounts_data_size(&self) -> u64 {
|
||||||
// Mixed integer ops currently not stable, so copying the impl.
|
// Mixed integer ops currently not stable, so copying the impl.
|
||||||
|
@ -6383,7 +6393,8 @@ impl Bank {
|
||||||
.is_active(&feature_set::cap_accounts_data_len::id())
|
.is_active(&feature_set::cap_accounts_data_len::id())
|
||||||
{
|
{
|
||||||
self.cost_tracker = RwLock::new(CostTracker::new_with_account_data_size_limit(Some(
|
self.cost_tracker = RwLock::new(CostTracker::new_with_account_data_size_limit(Some(
|
||||||
MAX_ACCOUNTS_DATA_LEN.saturating_sub(self.accounts_data_size_initial),
|
self.accounts_data_size_limit()
|
||||||
|
.saturating_sub(self.accounts_data_size_initial),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7761,7 +7772,6 @@ pub(crate) mod tests {
|
||||||
},
|
},
|
||||||
crossbeam_channel::{bounded, unbounded},
|
crossbeam_channel::{bounded, unbounded},
|
||||||
solana_program_runtime::{
|
solana_program_runtime::{
|
||||||
accounts_data_meter::MAX_ACCOUNTS_DATA_LEN,
|
|
||||||
compute_budget::MAX_COMPUTE_UNIT_LIMIT,
|
compute_budget::MAX_COMPUTE_UNIT_LIMIT,
|
||||||
invoke_context::InvokeContext,
|
invoke_context::InvokeContext,
|
||||||
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
|
prioritization_fee::{PrioritizationFeeDetails, PrioritizationFeeType},
|
||||||
|
@ -17731,15 +17741,13 @@ pub(crate) mod tests {
|
||||||
const NUM_ACCOUNTS: u64 = 20;
|
const NUM_ACCOUNTS: u64 = 20;
|
||||||
const ACCOUNT_SIZE: u64 = MAX_PERMITTED_DATA_LENGTH / (NUM_ACCOUNTS + 1);
|
const ACCOUNT_SIZE: u64 = MAX_PERMITTED_DATA_LENGTH / (NUM_ACCOUNTS + 1);
|
||||||
const REMAINING_ACCOUNTS_DATA_SIZE: u64 = NUM_ACCOUNTS * ACCOUNT_SIZE;
|
const REMAINING_ACCOUNTS_DATA_SIZE: u64 = NUM_ACCOUNTS * ACCOUNT_SIZE;
|
||||||
const INITIAL_ACCOUNTS_DATA_SIZE: u64 =
|
|
||||||
MAX_ACCOUNTS_DATA_LEN - REMAINING_ACCOUNTS_DATA_SIZE;
|
|
||||||
|
|
||||||
let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000);
|
let (genesis_config, mint_keypair) = create_genesis_config(1_000_000_000_000);
|
||||||
let mut bank = Bank::new_for_tests(&genesis_config);
|
let mut bank = Bank::new_for_tests(&genesis_config);
|
||||||
bank.activate_feature(&feature_set::cap_accounts_data_len::id());
|
bank.activate_feature(&feature_set::cap_accounts_data_len::id());
|
||||||
bank.set_accounts_data_size_initial_for_tests(
|
bank.accounts_data_size_initial = bank.accounts_data_size_limit()
|
||||||
INITIAL_ACCOUNTS_DATA_SIZE - bank.load_accounts_data_size_delta() as u64,
|
- REMAINING_ACCOUNTS_DATA_SIZE
|
||||||
);
|
- bank.load_accounts_data_size_delta() as u64;
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let result = loop {
|
let result = loop {
|
||||||
|
@ -17757,7 +17765,7 @@ pub(crate) mod tests {
|
||||||
let accounts_data_size_before = bank.load_accounts_data_size();
|
let accounts_data_size_before = bank.load_accounts_data_size();
|
||||||
let result = bank.process_transaction(&txn);
|
let result = bank.process_transaction(&txn);
|
||||||
let accounts_data_size_after = bank.load_accounts_data_size();
|
let accounts_data_size_after = bank.load_accounts_data_size();
|
||||||
assert!(accounts_data_size_after <= MAX_ACCOUNTS_DATA_LEN);
|
assert!(accounts_data_size_after <= bank.accounts_data_size_limit());
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
assert_eq!(i, NUM_ACCOUNTS);
|
assert_eq!(i, NUM_ACCOUNTS);
|
||||||
break result;
|
break result;
|
||||||
|
|
Loading…
Reference in New Issue