Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Increase transaction account lock limit from 64 to 128 (backport #27242)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Sep 16, 2022
1 parent 25ce9a7 commit e0838f8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ fn test_program_bpf_invoke_sanity() {
format!("Program log: invoke {program_lang} program"),
"Program log: Test max account infos exceeded".into(),
"skip".into(), // don't compare compute consumption logs
"Program failed to complete: Invoked an instruction with too many account info's (65 > 64)".into(),
"Program failed to complete: Invoked an instruction with too many account info's (129 > 128)".into(),
format!("Program {invoke_program_id} failed: Program failed to complete"),
]),
);
Expand Down
10 changes: 9 additions & 1 deletion programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,16 @@ fn check_account_infos(
.feature_set
.is_active(&feature_set::loosen_cpi_size_restriction::id())
{
let max_cpi_account_infos = if invoke_context
.feature_set
.is_active(&feature_set::increase_tx_account_lock_limit::id())
{
MAX_CPI_ACCOUNT_INFOS
} else {
64
};
let num_account_infos = num_account_infos as u64;
let max_account_infos = MAX_CPI_ACCOUNT_INFOS as u64;
let max_account_infos = max_cpi_account_infos as u64;
if num_account_infos > max_account_infos {
return Err(SyscallError::MaxInstructionAccountInfosExceeded {
num_account_infos,
Expand Down
26 changes: 25 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3880,6 +3880,25 @@ impl Bank {
}
}

<<<<<<< HEAD
=======
/// Get the max number of accounts that a transaction may lock in this block
pub fn get_transaction_account_lock_limit(&self) -> usize {
if let Some(transaction_account_lock_limit) =
self.runtime_config.transaction_account_lock_limit
{
transaction_account_lock_limit
} else if self
.feature_set
.is_active(&feature_set::increase_tx_account_lock_limit::id())
{
MAX_TX_ACCOUNT_LOCKS
} else {
64
}
}

>>>>>>> b9700244b5 (Increase transaction account lock limit from 64 to 128 (#27242))
/// Prepare a transaction batch from a list of legacy transactions. Used for tests only.
pub fn prepare_batch_for_tests(&self, txs: Vec<Transaction>) -> TransactionBatch {
let sanitized_txs = txs
Expand Down Expand Up @@ -8065,8 +8084,12 @@ pub(crate) mod tests {
system_instruction::{self, SystemError, MAX_PERMITTED_DATA_LENGTH},
system_program,
timing::duration_as_s,
<<<<<<< HEAD
transaction::MAX_TX_ACCOUNT_LOCKS,
transaction_context::InstructionContext,
=======
transaction_context::IndexOfAccount,
>>>>>>> b9700244b5 (Increase transaction account lock limit from 64 to 128 (#27242))
},
solana_vote_program::{
vote_instruction,
Expand Down Expand Up @@ -14287,7 +14310,8 @@ pub(crate) mod tests {
bank.last_blockhash(),
);

while tx.message.account_keys.len() <= MAX_TX_ACCOUNT_LOCKS {
let transaction_account_lock_limit = bank.get_transaction_account_lock_limit();
while tx.message.account_keys.len() <= transaction_account_lock_limit {
tx.message.account_keys.push(solana_sdk::pubkey::new_rand());
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/bpf/c/inc/sol/cpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ static const uint8_t MAX_CPI_INSTRUCTION_ACCOUNTS = 255;
/**
* Maximum number of account info structs that can be used in a single CPI
* invocation. A limit on account info structs is effectively the same as
* limiting the number of unique accounts. 64 was chosen to match the max
* limiting the number of unique accounts. 128 was chosen to match the max
* number of locked accounts per transaction (MAX_TX_ACCOUNT_LOCKS).
*/
static const uint8_t MAX_CPI_ACCOUNT_INFOS = 64;
static const uint16_t MAX_CPI_ACCOUNT_INFOS = 128;

/**
* Account Meta
Expand Down
4 changes: 2 additions & 2 deletions sdk/bpf/c/inc/sol/inc/cpi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ static const uint8_t MAX_CPI_INSTRUCTION_ACCOUNTS = 255;
/**
* Maximum number of account info structs that can be used in a single CPI
* invocation. A limit on account info structs is effectively the same as
* limiting the number of unique accounts. 64 was chosen to match the max
* limiting the number of unique accounts. 128 was chosen to match the max
* number of locked accounts per transaction (MAX_TX_ACCOUNT_LOCKS).
*/
static const uint8_t MAX_CPI_ACCOUNT_INFOS = 64;
static const uint16_t MAX_CPI_ACCOUNT_INFOS = 128;

/**
* Account Meta
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ pub const MAX_CPI_INSTRUCTION_ACCOUNTS: u8 = u8::MAX;

/// Maximum number of account info structs that can be used in a single CPI
/// invocation. A limit on account info structs is effectively the same as
/// limiting the number of unique accounts. 64 was chosen to match the max
/// limiting the number of unique accounts. 128 was chosen to match the max
/// number of locked accounts per transaction (MAX_TX_ACCOUNT_LOCKS).
pub const MAX_CPI_ACCOUNT_INFOS: usize = 64;
pub const MAX_CPI_ACCOUNT_INFOS: usize = 128;
21 changes: 21 additions & 0 deletions sdk/src/feature_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ pub mod return_none_for_zero_lamport_accounts {
solana_sdk::declare_id!("7K5HFrS1WAq6ND7RQbShXZXbtAookyTfaDQPTJNuZpze");
}

<<<<<<< HEAD
=======
pub mod epoch_accounts_hash {
solana_sdk::declare_id!("5GpmAKxaGsWWbPp4bNXFLJxZVvG92ctxf7jQnzTQjF3n");
}

pub mod remove_deprecated_request_unit_ix {
solana_sdk::declare_id!("EfhYd3SafzGT472tYQDUc4dPd2xdEfKs5fwkowUgVt4W");
}

pub mod increase_tx_account_lock_limit {
solana_sdk::declare_id!("9LZdXeKGeBV6hRLdxS1rHbHoEUsKqesCC2ZAPTPKJAbK");
}

>>>>>>> b9700244b5 (Increase transaction account lock limit from 64 to 128 (#27242))
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
Expand Down Expand Up @@ -629,6 +644,12 @@ lazy_static! {
(incremental_snapshot_only_incremental_hash_calculation::id(), "only hash accounts in incremental snapshot during incremental snapshot creation #26799"),
(vote_state_update_root_fix::id(), "fix root in vote state updates #27361"),
(return_none_for_zero_lamport_accounts::id(), "return none for zero lamport accounts #27800"),
<<<<<<< HEAD
=======
(epoch_accounts_hash::id(), "enable epoch accounts hash calculation #27539"),
(remove_deprecated_request_unit_ix::id(), "remove support for RequestUnitsDeprecated instruction #27500"),
(increase_tx_account_lock_limit::id(), "increase tx account lock limit to 128 #27241"),
>>>>>>> b9700244b5 (Increase transaction account lock limit from 64 to 128 (#27242))
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/transaction/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use {
};

/// Maximum number of accounts that a transaction may lock.
/// 64 was chosen because it is roughly twice the previous
/// number of account keys that could fit in a legacy tx.
pub const MAX_TX_ACCOUNT_LOCKS: usize = 64;
/// 128 was chosen because it is the minimum number of accounts
/// needed for the Neon EVM implementation.
pub const MAX_TX_ACCOUNT_LOCKS: usize = 128;

/// Sanitized transaction and the hash of its message
#[derive(Debug, Clone)]
Expand Down

0 comments on commit e0838f8

Please sign in to comment.