diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index b11763b1dd5048..980a09735ab8e8 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -497,8 +497,6 @@ impl Accounts { // accounts.iter().take(message.account_keys.len()) accounts.append(&mut account_deps); - let disable_builtin_loader_ownership_chains = - feature_set.is_active(&feature_set::disable_builtin_loader_ownership_chains::ID); let builtins_start_index = accounts.len(); let program_indices = message .instructions() @@ -506,66 +504,59 @@ impl Accounts { .map(|instruction| { let mut account_indices = Vec::new(); let mut program_index = instruction.program_id_index as usize; - for _ in 0..5 { - let (program_id, program_account) = accounts - .get(program_index) - .ok_or(TransactionError::ProgramAccountNotFound)?; - let account_found = accounts_found.get(program_index).unwrap_or(&true); - if native_loader::check_id(program_id) { - return Ok(account_indices); - } - if !account_found { - error_counters.account_not_found += 1; - return Err(TransactionError::ProgramAccountNotFound); - } - if !program_account.executable() { - error_counters.invalid_program_for_execution += 1; - return Err(TransactionError::InvalidProgramForExecution); - } - account_indices.insert(0, program_index as IndexOfAccount); - let owner_id = program_account.owner(); - if native_loader::check_id(owner_id) { - return Ok(account_indices); - } - program_index = if let Some(owner_index) = accounts - .get(builtins_start_index..) - .ok_or(TransactionError::ProgramAccountNotFound)? - .iter() - .position(|(key, _)| key == owner_id) + let (program_id, program_account) = accounts + .get(program_index) + .ok_or(TransactionError::ProgramAccountNotFound)?; + let account_found = accounts_found.get(program_index).unwrap_or(&true); + if native_loader::check_id(program_id) { + return Ok(account_indices); + } + if !account_found { + error_counters.account_not_found += 1; + return Err(TransactionError::ProgramAccountNotFound); + } + if !program_account.executable() { + error_counters.invalid_program_for_execution += 1; + return Err(TransactionError::InvalidProgramForExecution); + } + account_indices.insert(0, program_index as IndexOfAccount); + let owner_id = program_account.owner(); + if native_loader::check_id(owner_id) { + return Ok(account_indices); + } + program_index = if let Some(owner_index) = accounts + .get(builtins_start_index..) + .ok_or(TransactionError::ProgramAccountNotFound)? + .iter() + .position(|(key, _)| key == owner_id) + { + builtins_start_index.saturating_add(owner_index) + } else { + let owner_index = accounts.len(); + if let Some((owner_account, _)) = + self.accounts_db.load_with_fixed_root(ancestors, owner_id) { - builtins_start_index.saturating_add(owner_index) - } else { - let owner_index = accounts.len(); - if let Some((owner_account, _)) = - self.accounts_db.load_with_fixed_root(ancestors, owner_id) + if !native_loader::check_id(owner_account.owner()) + || !owner_account.executable() { - if disable_builtin_loader_ownership_chains - && !native_loader::check_id(owner_account.owner()) - || !owner_account.executable() - { - error_counters.invalid_program_for_execution += 1; - return Err(TransactionError::InvalidProgramForExecution); - } - Self::accumulate_and_check_loaded_account_data_size( - &mut accumulated_accounts_data_size, - owner_account.data().len(), - requested_loaded_accounts_data_size_limit, - error_counters, - )?; - accounts.push((*owner_id, owner_account)); - } else { - error_counters.account_not_found += 1; - return Err(TransactionError::ProgramAccountNotFound); + error_counters.invalid_program_for_execution += 1; + return Err(TransactionError::InvalidProgramForExecution); } - owner_index - }; - if disable_builtin_loader_ownership_chains { - account_indices.insert(0, program_index as IndexOfAccount); - return Ok(account_indices); + Self::accumulate_and_check_loaded_account_data_size( + &mut accumulated_accounts_data_size, + owner_account.data().len(), + requested_loaded_accounts_data_size_limit, + error_counters, + )?; + accounts.push((*owner_id, owner_account)); + } else { + error_counters.account_not_found += 1; + return Err(TransactionError::ProgramAccountNotFound); } - } - error_counters.call_chain_too_deep += 1; - Err(TransactionError::CallChainTooDeep) + owner_index + }; + account_indices.insert(0, program_index as IndexOfAccount); + Ok(account_indices) }) .collect::>>>()?;