diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 258f1aaf11a..e8f26335408 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -773,27 +773,28 @@ impl MessageProcessor { let invoke_context = invoke_context.borrow(); // Translate and verify caller's data - let keyed_accounts = invoke_context.get_keyed_accounts()?; - let keyed_accounts = keyed_account_indices + let caller_keyed_accounts = invoke_context.get_keyed_accounts()?; + let callee_keyed_accounts = keyed_account_indices .iter() - .map(|index| keyed_account_at_index(keyed_accounts, *index)) + .map(|index| keyed_account_at_index(caller_keyed_accounts, *index)) .collect::, InstructionError>>()?; - let (message, callee_program_id, _) = - Self::create_message(&instruction, &keyed_accounts, signers, &invoke_context)?; - let keyed_accounts = invoke_context.get_keyed_accounts()?; - let mut caller_write_privileges = keyed_account_indices - .iter() - .map(|index| keyed_accounts[*index].is_writable()) - .collect::>(); - caller_write_privileges.insert(0, false); - let mut accounts = vec![]; - let mut keyed_account_indices_reordered = vec![]; - let keyed_accounts = invoke_context.get_keyed_accounts()?; + let (message, callee_program_id, _) = Self::create_message( + &instruction, + &callee_keyed_accounts, + signers, + &invoke_context, + )?; + + let mut accounts = Vec::with_capacity(message.account_keys.len()); + let mut caller_write_privileges = Vec::with_capacity(message.account_keys.len()); + let mut keyed_account_indices_reordered = + Vec::with_capacity(message.account_keys.len()); 'root: for account_key in message.account_keys.iter() { for keyed_account_index in keyed_account_indices { - let keyed_account = &keyed_accounts[*keyed_account_index]; + let keyed_account = &caller_keyed_accounts[*keyed_account_index]; if account_key == keyed_account.unsigned_key() { accounts.push((*account_key, Rc::new(keyed_account.account.clone()))); + caller_write_privileges.push(keyed_account.is_writable()); keyed_account_indices_reordered.push(*keyed_account_index); continue 'root; }