From 56b881b5a3f54c585bf81709b8d86e2bec9ce322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Wed, 15 Nov 2023 15:38:31 +0100 Subject: [PATCH 1/2] Cleans up feature gate of disable_builtin_loader_ownership_chains. --- accounts-db/src/accounts.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index b11763b1dd5048..4881770fcc5e2a 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,7 +504,7 @@ 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)?; @@ -539,8 +537,7 @@ impl Accounts { if let Some((owner_account, _)) = self.accounts_db.load_with_fixed_root(ancestors, owner_id) { - if disable_builtin_loader_ownership_chains - && !native_loader::check_id(owner_account.owner()) + if !native_loader::check_id(owner_account.owner()) || !owner_account.executable() { error_counters.invalid_program_for_execution += 1; @@ -559,13 +556,9 @@ impl Accounts { } owner_index }; - if disable_builtin_loader_ownership_chains { - account_indices.insert(0, program_index as IndexOfAccount); - return Ok(account_indices); - } + account_indices.insert(0, program_index as IndexOfAccount); + return Ok(account_indices); } - error_counters.call_chain_too_deep += 1; - Err(TransactionError::CallChainTooDeep) }) .collect::>>>()?; From f4baf4a522b71abee1475b2e113c888d08b7986b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Wed, 15 Nov 2023 15:39:14 +0100 Subject: [PATCH 2/2] cargo fmt --- accounts-db/src/accounts.rs | 100 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 51 deletions(-) diff --git a/accounts-db/src/accounts.rs b/accounts-db/src/accounts.rs index 4881770fcc5e2a..980a09735ab8e8 100644 --- a/accounts-db/src/accounts.rs +++ b/accounts-db/src/accounts.rs @@ -504,61 +504,59 @@ impl Accounts { .map(|instruction| { let mut account_indices = Vec::new(); let mut program_index = instruction.program_id_index as usize; + 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 !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 - }; - 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); + } + owner_index + }; + account_indices.insert(0, program_index as IndexOfAccount); + Ok(account_indices) }) .collect::>>>()?;