From ae48ac97ddb34dbb7945d0bc5ee3449afd00e629 Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:52:15 -0600 Subject: [PATCH] fix account resize test by requesting max tx data size (#28826) * fix account resize test by requesting max tx data size * define data size limit in incremental of 1024 --- program-runtime/src/compute_budget.rs | 4 ++-- runtime/src/bank.rs | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/program-runtime/src/compute_budget.rs b/program-runtime/src/compute_budget.rs index 2e362eea2..8318e0d2d 100644 --- a/program-runtime/src/compute_budget.rs +++ b/program-runtime/src/compute_budget.rs @@ -25,7 +25,7 @@ pub enum LoadedAccountsDataLimitType { /// Get default value of `ComputeBudget::accounts_data_size_limit` if not set specifically. It /// sets to 10MB initially, may be changed with feature gate. -const DEFAULT_LOADED_ACCOUNTS_DATA_LIMIT: u32 = 10_000_000; +const DEFAULT_LOADED_ACCOUNTS_DATA_LIMIT: u32 = 10 * 1024 * 1024; pub fn get_default_loaded_accounts_data_limit(limit_type: &LoadedAccountsDataLimitType) -> u32 { match limit_type { LoadedAccountsDataLimitType::V0 => DEFAULT_LOADED_ACCOUNTS_DATA_LIMIT, @@ -34,7 +34,7 @@ pub fn get_default_loaded_accounts_data_limit(limit_type: &LoadedAccountsDataLim /// Get max value of `ComputeBudget::accounts_data_size_limit`, it caps value user /// sets via `ComputeBudgetInstruction::set_compute_unit_limit`. It is set to 100MB /// initially, can be changed with feature gate. -const MAX_LOADED_ACCOUNTS_DATA_LIMIT: u32 = 100_000_000; +const MAX_LOADED_ACCOUNTS_DATA_LIMIT: u32 = 100 * 1024 * 1024; pub fn get_max_loaded_accounts_data_limit(limit_type: &LoadedAccountsDataLimitType) -> u32 { match limit_type { LoadedAccountsDataLimitType::V0 => MAX_LOADED_ACCOUNTS_DATA_LIMIT, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index bc192a8f4..72abccfa0 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -19509,7 +19509,10 @@ pub(crate) mod tests { account_metas, ); Transaction::new_signed_with_payer( - &[instruction], + &[ + instruction, + ComputeBudgetInstruction::set_accounts_data_size_limit(u32::MAX), + ], Some(&payer.pubkey()), &[payer], recent_blockhash, @@ -19811,6 +19814,7 @@ pub(crate) mod tests { &mock_program_id, mock_realloc_process_instruction, ); + let recent_blockhash = bank.last_blockhash(); let funding_keypair = Keypair::new(); @@ -19827,7 +19831,7 @@ pub(crate) mod tests { let account_balance = LAMPORTS_PER_SOL; let account_size = rng.gen_range( 1, - (MAX_PERMITTED_DATA_LENGTH / 4) as usize - MAX_PERMITTED_DATA_INCREASE, + MAX_PERMITTED_DATA_LENGTH as usize - MAX_PERMITTED_DATA_INCREASE, ); let account_data = AccountSharedData::new(account_balance, account_size, &mock_program_id); @@ -19857,9 +19861,8 @@ pub(crate) mod tests { { let account_pubkey = Pubkey::new_unique(); let account_balance = LAMPORTS_PER_SOL; - let account_size = rng - .gen_range(MAX_PERMITTED_DATA_LENGTH / 8, MAX_PERMITTED_DATA_LENGTH / 4) - as usize; + let account_size = + rng.gen_range(MAX_PERMITTED_DATA_LENGTH / 2, MAX_PERMITTED_DATA_LENGTH) as usize; let account_data = AccountSharedData::new(account_balance, account_size, &mock_program_id); bank.store_account(&account_pubkey, &account_data);