Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
pubkey,
AccountSharedData::new(0, allocation_size, &Pubkey::new_unique()),
));
instruction_accounts.push(InstructionAccount::new(0, 0, 0, false, true));
instruction_accounts.push(InstructionAccount::new(0, 0, false, true));
vec![]
}
Err(_) => {
Expand Down Expand Up @@ -480,7 +480,6 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
idx
};
InstructionAccount::new(
txn_acct_index as IndexOfAccount,
txn_acct_index as IndexOfAccount,
txn_acct_index as IndexOfAccount,
account_info.is_signer.unwrap_or(false),
Expand Down
32 changes: 6 additions & 26 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,23 +368,9 @@ impl<'a> InvokeContext<'a> {
};
instruction_accounts.push(cloned_account);
} else {
let index_in_caller = instruction_context
.find_index_of_instruction_account(
self.transaction_context,
&account_meta.pubkey,
)
.ok_or_else(|| {
ic_msg!(
self,
"Instruction references an unknown account {}",
account_meta.pubkey,
);
InstructionError::MissingAccount
})?;
*index_in_callee = instruction_accounts.len() as u8;
instruction_accounts.push(InstructionAccount::new(
index_in_transaction,
index_in_caller,
instruction_account_index as IndexOfAccount,
account_meta.is_signer,
account_meta.is_writable,
Expand Down Expand Up @@ -413,10 +399,11 @@ impl<'a> InvokeContext<'a> {
continue;
}

let borrowed_account = instruction_context.try_borrow_instruction_account(
self.transaction_context,
instruction_account.index_in_caller,
let index_in_caller = instruction_context.get_index_of_account_in_instruction(
instruction_account.index_in_transaction,
)?;
let borrowed_account = instruction_context
.try_borrow_instruction_account(self.transaction_context, index_in_caller)?;

// Readonly in caller cannot become writable in callee
if instruction_account.is_writable() && !borrowed_account.is_writable() {
Expand Down Expand Up @@ -506,7 +493,6 @@ impl<'a> InvokeContext<'a> {

let index_in_transaction = *index_in_transaction as usize;
instruction_accounts.push(InstructionAccount::new(
index_in_transaction as IndexOfAccount,
index_in_transaction as IndexOfAccount,
*index_in_callee as IndexOfAccount,
message.is_signer(index_in_transaction),
Expand Down Expand Up @@ -901,7 +887,6 @@ pub fn mock_process_instruction_with_feature_set<
})
.unwrap_or(instruction_account_index) as IndexOfAccount;
instruction_accounts.push(InstructionAccount::new(
index_in_transaction,
index_in_transaction,
index_in_callee,
account_meta.is_signer,
Expand Down Expand Up @@ -1022,7 +1007,6 @@ mod tests {
let instruction_accounts = (0..4)
.map(|instruction_account_index| {
InstructionAccount::new(
instruction_account_index,
instruction_account_index,
instruction_account_index,
false,
Expand Down Expand Up @@ -1128,7 +1112,6 @@ mod tests {
AccountSharedData::new(index as u64, 1, invoke_stack.get(index).unwrap()),
));
instruction_accounts.push(InstructionAccount::new(
index as IndexOfAccount,
index as IndexOfAccount,
instruction_accounts.len() as IndexOfAccount,
false,
Expand All @@ -1141,7 +1124,6 @@ mod tests {
AccountSharedData::new(1, 1, &solana_pubkey::Pubkey::default()),
));
instruction_accounts.push(InstructionAccount::new(
index as IndexOfAccount,
index as IndexOfAccount,
index as IndexOfAccount,
false,
Expand Down Expand Up @@ -1219,7 +1201,6 @@ mod tests {
let instruction_accounts = (0..4)
.map(|instruction_account_index| {
InstructionAccount::new(
instruction_account_index,
instruction_account_index,
instruction_account_index,
false,
Expand Down Expand Up @@ -1277,7 +1258,6 @@ mod tests {
let instruction_accounts = (0..4)
.map(|instruction_account_index| {
InstructionAccount::new(
instruction_account_index,
instruction_account_index,
instruction_account_index,
false,
Expand Down Expand Up @@ -1368,8 +1348,8 @@ mod tests {
(program_key, program_account),
];
let instruction_accounts = vec![
InstructionAccount::new(0, 0, 0, false, true),
InstructionAccount::new(1, 1, 1, false, false),
InstructionAccount::new(0, 0, false, true),
InstructionAccount::new(1, 1, false, false),
];
with_mock_invoke_context!(invoke_context, transaction_context, transaction_accounts);
let mut program_cache_for_tx_batch = ProgramCacheForTxBatch::default();
Expand Down
1 change: 0 additions & 1 deletion program-runtime/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ mod tests {
.position(|account_index| account_index == index_in_transaction)
.unwrap_or(index_in_instruction);
InstructionAccount::new(
*index_in_transaction,
*index_in_transaction,
index_in_callee as IndexOfAccount,
false,
Expand Down
16 changes: 10 additions & 6 deletions program-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ impl solana_sysvar::program_stubs::SyscallStubs for SyscallStubs {
.ok_or(InstructionError::MissingAccount)
.unwrap();
let account_info = &account_infos[account_info_index];
let index_in_caller = instruction_context
.get_index_of_account_in_instruction(instruction_account.index_in_transaction)
.unwrap();
let mut borrowed_account = instruction_context
.try_borrow_instruction_account(
transaction_context,
instruction_account.index_in_caller,
)
.try_borrow_instruction_account(transaction_context, index_in_caller)
.unwrap();
if borrowed_account.get_lamports() != account_info.lamports() {
borrowed_account
Expand All @@ -324,7 +324,8 @@ impl solana_sysvar::program_stubs::SyscallStubs for SyscallStubs {
.unwrap();
}
if instruction_account.is_writable() {
account_indices.push((instruction_account.index_in_caller, account_info_index));
account_indices
.push((instruction_account.index_in_transaction, account_info_index));
}
}

Expand All @@ -338,7 +339,10 @@ impl solana_sysvar::program_stubs::SyscallStubs for SyscallStubs {
let instruction_context = transaction_context
.get_current_instruction_context()
.unwrap();
for (index_in_caller, account_info_index) in account_indices.into_iter() {
for (index_in_transaction, account_info_index) in account_indices.into_iter() {
let index_in_caller = instruction_context
.get_index_of_account_in_instruction(index_in_transaction)
.unwrap();
let borrowed_account = instruction_context
.try_borrow_instruction_account(transaction_context, index_in_caller)
.unwrap();
Expand Down
1 change: 0 additions & 1 deletion programs/bpf_loader/benches/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ fn create_inputs(owner: Pubkey, num_instruction_accounts: usize) -> TransactionC
.unwrap_or(instruction_account_index) as IndexOfAccount;
instruction_accounts.push(InstructionAccount::new(
index_in_transaction,
instruction_account_index as IndexOfAccount,
index_in_callee,
false,
instruction_account_index >= 4,
Expand Down
2 changes: 1 addition & 1 deletion programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! with_mock_invoke_context {
AccountSharedData::new(2, $account_size, &program_key),
),
];
let instruction_accounts = vec![InstructionAccount::new(2, 2, 0, false, true)];
let instruction_accounts = vec![InstructionAccount::new(2, 0, false, true)];
solana_program_runtime::with_mock_invoke_context!(
$invoke_context,
transaction_context,
Expand Down
4 changes: 2 additions & 2 deletions programs/system/src/system_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ mod test {
(system_program::id(), AccountSharedData::default()),
];
let $instruction_accounts = vec![
InstructionAccount::new(0, 0, 0, true, true),
InstructionAccount::new(1, 1, 1, false, true),
InstructionAccount::new(0, 0, true, true),
InstructionAccount::new(1, 1, false, true),
];
with_mock_invoke_context!($invoke_context, transaction_context, transaction_accounts);
};
Expand Down
4 changes: 2 additions & 2 deletions programs/vote/src/vote_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ mod tests {
let mut instruction_context = InstructionContext::default();
instruction_context.configure(
vec![0],
vec![InstructionAccount::new(1, 1, 0, false, true)],
vec![InstructionAccount::new(1, 0, false, true)],
&[],
);

Expand Down Expand Up @@ -1318,7 +1318,7 @@ mod tests {
let mut instruction_context = InstructionContext::default();
instruction_context.configure(
vec![0],
vec![InstructionAccount::new(1, 1, 0, false, true)],
vec![InstructionAccount::new(1, 0, false, true)],
&[],
);

Expand Down
27 changes: 1 addition & 26 deletions svm/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use {
solana_sysvar_id::SysvarId,
solana_timings::ExecuteTimings,
solana_transaction_context::{
ExecutionRecord, IndexOfAccount, InstructionAccount, TransactionAccount, TransactionContext,
ExecutionRecord, IndexOfAccount, TransactionAccount, TransactionContext,
},
std::{
collections::{hash_map::Entry, HashMap},
Expand Down Expand Up @@ -389,31 +389,6 @@ fn execute_fixture_as_instr(
SVMTransactionExecutionCost::default(),
);

let mut instruction_accounts: Vec<InstructionAccount> =
Vec::with_capacity(sanitized_message.instructions()[0].accounts.len());

for (instruction_acct_idx, index_txn) in sanitized_message.instructions()[0]
.accounts
.iter()
.enumerate()
{
let index_in_callee = sanitized_message.instructions()[0]
.accounts
.get(0..instruction_acct_idx)
.unwrap()
.iter()
.position(|idx| *idx == *index_txn)
.unwrap_or(instruction_acct_idx);

instruction_accounts.push(InstructionAccount::new(
*index_txn as IndexOfAccount,
*index_txn as IndexOfAccount,
index_in_callee as IndexOfAccount,
sanitized_message.is_signer(*index_txn as usize),
sanitized_message.is_writable(*index_txn as usize),
));
}

invoke_context
.prepare_next_top_level_instruction(
sanitized_message,
Expand Down
36 changes: 18 additions & 18 deletions syscalls/src/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,10 @@ where
continue; // Skip duplicate account
}

let callee_account = instruction_context.try_borrow_instruction_account(
transaction_context,
instruction_account.index_in_caller,
)?;
let index_in_caller = instruction_context
.get_index_of_account_in_instruction(instruction_account.index_in_transaction)?;
let callee_account = instruction_context
.try_borrow_instruction_account(transaction_context, index_in_caller)?;
let account_key = invoke_context
.transaction_context
.get_key_of_account_at_index(instruction_account.index_in_transaction)?;
Expand All @@ -817,16 +817,17 @@ where
} else if let Some(caller_account_index) =
account_info_keys.iter().position(|key| *key == account_key)
{
let serialized_metadata = accounts_metadata
.get(instruction_account.index_in_caller as usize)
.ok_or_else(|| {
ic_msg!(
invoke_context,
"Internal error: index mismatch for account {}",
account_key
);
Box::new(InstructionError::MissingAccount)
})?;
let serialized_metadata =
accounts_metadata
.get(index_in_caller as usize)
.ok_or_else(|| {
ic_msg!(
invoke_context,
"Internal error: index mismatch for account {}",
account_key
);
Box::new(InstructionError::MissingAccount)
})?;

// build the CallerAccount corresponding to this account.
if caller_account_index >= account_infos.len() {
Expand Down Expand Up @@ -857,7 +858,7 @@ where
)?;

accounts.push(TranslatedAccount {
index_in_caller: instruction_account.index_in_caller,
index_in_caller,
caller_account,
update_caller_account_region: instruction_account.is_writable() || update_caller,
update_caller_account_info: instruction_account.is_writable(),
Expand Down Expand Up @@ -1309,7 +1310,6 @@ mod tests {
.enumerate()
.map(|(index_in_callee, index_in_transaction)| {
InstructionAccount::new(
*index_in_transaction as IndexOfAccount,
*index_in_transaction as IndexOfAccount,
index_in_callee as IndexOfAccount,
false,
Expand Down Expand Up @@ -1855,8 +1855,8 @@ mod tests {
.configure(
vec![0],
vec![
InstructionAccount::new(1, 0, 0, false, true),
InstructionAccount::new(1, 0, 0, false, true),
InstructionAccount::new(1, 0, false, true),
InstructionAccount::new(1, 0, false, true),
],
&[],
);
Expand Down
1 change: 0 additions & 1 deletion syscalls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4448,7 +4448,6 @@ mod tests {
{
let instruction_accounts = vec![InstructionAccount::new(
index_in_trace.saturating_add(1) as IndexOfAccount,
0, // This is incorrect / inconsistent but not required
0,
false,
false,
Expand Down
Loading
Loading