Cleanup - Feature gate of `disable_builtin_loader_ownership_chains` (#34083)

* Cleans up feature gate of disable_builtin_loader_ownership_chains.
This commit is contained in:
Alexander Meißner 2023-11-15 17:17:31 +01:00 committed by GitHub
parent f005075369
commit 48ed70a8d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 59 deletions

View File

@ -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 {
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)
{
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);
}
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)
{
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);
}
owner_index
};
if disable_builtin_loader_ownership_chains {
account_indices.insert(0, program_index as IndexOfAccount);
return Ok(account_indices);
}
}
error_counters.call_chain_too_deep += 1;
Err(TransactionError::CallChainTooDeep)
owner_index
};
account_indices.insert(0, program_index as IndexOfAccount);
Ok(account_indices)
})
.collect::<Result<Vec<Vec<IndexOfAccount>>>>()?;