Refactor: Add AccountKeys struct for static and dynamic message keys (#22960)
This commit is contained in:
@ -250,10 +250,11 @@ impl Accounts {
|
||||
// If a fee can pay for execution then the program will be scheduled
|
||||
let mut payer_index = None;
|
||||
let mut tx_rent: TransactionRent = 0;
|
||||
let mut accounts = Vec::with_capacity(message.account_keys_len());
|
||||
let mut account_deps = Vec::with_capacity(message.account_keys_len());
|
||||
let account_keys = message.account_keys();
|
||||
let mut accounts = Vec::with_capacity(account_keys.len());
|
||||
let mut account_deps = Vec::with_capacity(account_keys.len());
|
||||
let mut rent_debits = RentDebits::default();
|
||||
for (i, key) in message.account_keys_iter().enumerate() {
|
||||
for (i, key) in account_keys.iter().enumerate() {
|
||||
let account = if !message.is_non_loader_key(i) {
|
||||
// Fill in an empty account for the program slots.
|
||||
AccountSharedData::default()
|
||||
@ -328,7 +329,7 @@ impl Accounts {
|
||||
};
|
||||
accounts.push((*key, account));
|
||||
}
|
||||
debug_assert_eq!(accounts.len(), message.account_keys_len());
|
||||
debug_assert_eq!(accounts.len(), account_keys.len());
|
||||
// Appends the account_deps at the end of the accounts,
|
||||
// this way they can be accessed in a uniform way.
|
||||
// At places where only the accounts are needed,
|
||||
@ -1176,7 +1177,7 @@ impl Accounts {
|
||||
let message = tx.message();
|
||||
let loaded_transaction = tx_load_result.as_mut().unwrap();
|
||||
let mut fee_payer_index = None;
|
||||
for (i, (address, account)) in (0..message.account_keys_len())
|
||||
for (i, (address, account)) in (0..message.account_keys().len())
|
||||
.zip(loaded_transaction.accounts.iter_mut())
|
||||
.filter(|(i, _)| message.is_non_loader_key(*i))
|
||||
{
|
||||
|
@ -838,7 +838,7 @@ impl NonceFull {
|
||||
accounts: &[TransactionAccount],
|
||||
rent_debits: &RentDebits,
|
||||
) -> Result<Self> {
|
||||
let fee_payer = (0..message.account_keys_len()).find_map(|i| {
|
||||
let fee_payer = (0..message.account_keys().len()).find_map(|i| {
|
||||
if let Some((k, a)) = &accounts.get(i) {
|
||||
if message.is_non_loader_key(i) {
|
||||
return Some((k, a));
|
||||
@ -3464,7 +3464,7 @@ impl Bank {
|
||||
&self,
|
||||
transaction: SanitizedTransaction,
|
||||
) -> TransactionSimulationResult {
|
||||
let number_of_accounts = transaction.message().account_keys_len();
|
||||
let number_of_accounts = transaction.message().account_keys().len();
|
||||
let batch = self.prepare_simulation_batch(transaction);
|
||||
let mut timings = ExecuteTimings::default();
|
||||
|
||||
@ -3648,7 +3648,7 @@ impl Bank {
|
||||
let mut balances: TransactionBalances = vec![];
|
||||
for transaction in batch.sanitized_transactions() {
|
||||
let mut transaction_balances: Vec<u64> = vec![];
|
||||
for account_key in transaction.message().account_keys_iter() {
|
||||
for account_key in transaction.message().account_keys().iter() {
|
||||
transaction_balances.push(self.get_balance(account_key));
|
||||
}
|
||||
balances.push(transaction_balances);
|
||||
@ -4045,7 +4045,7 @@ impl Bank {
|
||||
|
||||
for (execution_result, tx) in execution_results.iter().zip(sanitized_txs) {
|
||||
if let Some(debug_keys) = &self.transaction_debug_keys {
|
||||
for key in tx.message().account_keys_iter() {
|
||||
for key in tx.message().account_keys().iter() {
|
||||
if debug_keys.contains(key) {
|
||||
let result = execution_result.flattened_result();
|
||||
info!("slot: {} result: {:?} tx: {:?}", self.slot, result, tx);
|
||||
@ -4062,7 +4062,7 @@ impl Bank {
|
||||
.mentioned_addresses
|
||||
.is_empty()
|
||||
{
|
||||
for key in tx.message().account_keys_iter() {
|
||||
for key in tx.message().account_keys().iter() {
|
||||
if transaction_log_collector_config
|
||||
.mentioned_addresses
|
||||
.contains(key)
|
||||
@ -5971,7 +5971,7 @@ impl Bank {
|
||||
) {
|
||||
let message = tx.message();
|
||||
for (_i, (pubkey, account)) in
|
||||
(0..message.account_keys_len()).zip(loaded_transaction.accounts.iter())
|
||||
(0..message.account_keys().len()).zip(loaded_transaction.accounts.iter())
|
||||
{
|
||||
self.stakes_cache.check_and_store(pubkey, account);
|
||||
}
|
||||
@ -6764,16 +6764,16 @@ pub(crate) mod tests {
|
||||
let message = new_sanitized_message(&instructions, Some(&from_address));
|
||||
let accounts = [
|
||||
(
|
||||
*message.get_account_key(0).unwrap(),
|
||||
*message.account_keys().get(0).unwrap(),
|
||||
rent_collected_from_account.clone(),
|
||||
),
|
||||
(
|
||||
*message.get_account_key(1).unwrap(),
|
||||
*message.account_keys().get(1).unwrap(),
|
||||
rent_collected_nonce_account.clone(),
|
||||
),
|
||||
(*message.get_account_key(2).unwrap(), to_account.clone()),
|
||||
(*message.account_keys().get(2).unwrap(), to_account.clone()),
|
||||
(
|
||||
*message.get_account_key(3).unwrap(),
|
||||
*message.account_keys().get(3).unwrap(),
|
||||
recent_blockhashes_sysvar_account.clone(),
|
||||
),
|
||||
];
|
||||
@ -6795,16 +6795,16 @@ pub(crate) mod tests {
|
||||
let message = new_sanitized_message(&instructions, Some(&nonce_address));
|
||||
let accounts = [
|
||||
(
|
||||
*message.get_account_key(0).unwrap(),
|
||||
*message.account_keys().get(0).unwrap(),
|
||||
rent_collected_nonce_account,
|
||||
),
|
||||
(
|
||||
*message.get_account_key(1).unwrap(),
|
||||
*message.account_keys().get(1).unwrap(),
|
||||
rent_collected_from_account,
|
||||
),
|
||||
(*message.get_account_key(2).unwrap(), to_account),
|
||||
(*message.account_keys().get(2).unwrap(), to_account),
|
||||
(
|
||||
*message.get_account_key(3).unwrap(),
|
||||
*message.account_keys().get(3).unwrap(),
|
||||
recent_blockhashes_sysvar_account,
|
||||
),
|
||||
];
|
||||
|
@ -19,7 +19,7 @@ impl Bank {
|
||||
transaction_context: &TransactionContext,
|
||||
message: &SanitizedMessage,
|
||||
) -> Vec<TransactionAccountStateInfo> {
|
||||
(0..message.account_keys_len())
|
||||
(0..message.account_keys().len())
|
||||
.map(|i| {
|
||||
let rent_state = if message.is_writable(i) {
|
||||
let state = if let Ok(account) = transaction_context.get_account_at_index(i) {
|
||||
|
@ -157,14 +157,18 @@ impl CostModel {
|
||||
transaction: &SanitizedTransaction,
|
||||
) {
|
||||
let message = transaction.message();
|
||||
message.account_keys_iter().enumerate().for_each(|(i, k)| {
|
||||
let is_writable = message.is_writable(i);
|
||||
message
|
||||
.account_keys()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.for_each(|(i, k)| {
|
||||
let is_writable = message.is_writable(i);
|
||||
|
||||
if is_writable {
|
||||
tx_cost.writable_accounts.push(*k);
|
||||
tx_cost.write_lock_cost += WRITE_LOCK_UNITS;
|
||||
}
|
||||
});
|
||||
if is_writable {
|
||||
tx_cost.writable_accounts.push(*k);
|
||||
tx_cost.write_lock_cost += WRITE_LOCK_UNITS;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn get_data_bytes_cost(&self, transaction: &SanitizedTransaction) -> u64 {
|
||||
|
@ -44,7 +44,7 @@ pub fn parse_sanitized_vote_transaction(tx: &SanitizedTransaction) -> Option<Par
|
||||
return None;
|
||||
}
|
||||
let first_account = usize::from(*first_instruction.accounts.first()?);
|
||||
let key = message.get_account_key(first_account)?;
|
||||
let key = message.account_keys().get(first_account)?;
|
||||
let (vote, switch_proof_hash) = parse_vote_instruction_data(&first_instruction.data)?;
|
||||
Some((*key, vote, switch_proof_hash))
|
||||
}
|
||||
|
Reference in New Issue
Block a user