Browse Source

Revert "Bring instruction accounts check earlier (#9117)" (#9129)

This reverts commit f418e2dbed4bfd0ac774a732b018e2b1b884cc47.
Lucas Ste 3 days ago
parent
commit
6c6fa84a5f
1 changed files with 9 additions and 7 deletions
  1. 9 7
      program-runtime/src/invoke_context.rs

+ 9 - 7
program-runtime/src/invoke_context.rs

@@ -34,7 +34,7 @@ use {
     solana_transaction_context::{
         instruction::InstructionContext, instruction_accounts::InstructionAccount,
         transaction_accounts::KeyedAccountSharedData, IndexOfAccount, TransactionContext,
-        MAX_ACCOUNTS_PER_INSTRUCTION, MAX_ACCOUNTS_PER_TRANSACTION,
+        MAX_ACCOUNTS_PER_TRANSACTION,
     },
     std::{
         alloc::Layout,
@@ -296,6 +296,9 @@ impl<'a, 'ix_data> InvokeContext<'a, 'ix_data> {
         instruction: Instruction,
         signers: &[Pubkey],
     ) -> Result<(), InstructionError> {
+        // We reference accounts by an u8 index, so we have a total of 256 accounts.
+        // This algorithm allocates the array on the stack for speed.
+        // On AArch64 in release mode, this function only consumes 640 bytes of stack.
         let mut transaction_callee_map: Vec<u8> = vec![u8::MAX; MAX_ACCOUNTS_PER_TRANSACTION];
         let mut instruction_accounts: Vec<InstructionAccount> =
             Vec::with_capacity(instruction.accounts.len());
@@ -441,13 +444,12 @@ impl<'a, 'ix_data> InvokeContext<'a, 'ix_data> {
         program_account_index: IndexOfAccount,
         data: &'ix_data [u8],
     ) -> Result<(), InstructionError> {
+        // We reference accounts by an u8 index, so we have a total of 256 accounts.
+        // This algorithm allocates the array on the stack for speed.
+        // On AArch64 in release mode, this function only consumes 464 bytes of stack (when it is
+        // not inlined).
         let mut transaction_callee_map: Vec<u8> = vec![u8::MAX; MAX_ACCOUNTS_PER_TRANSACTION];
-        if instruction.accounts.len() > MAX_ACCOUNTS_PER_INSTRUCTION {
-            // We cannot serialize more than 255 accounts per instruction. We raise this error
-            // during serialization already, so this check only brings the error to an earlier
-            // stage.
-            return Err(InstructionError::MaxAccountsExceeded);
-        }
+        debug_assert!(instruction.accounts.len() <= transaction_callee_map.len());
 
         let mut instruction_accounts: Vec<InstructionAccount> =
             Vec::with_capacity(instruction.accounts.len());