Adds missing program_id in InvokeContext::push() calls. (#20621)
This commit is contained in:
parent
005d6863fd
commit
06cad19c91
|
@ -129,8 +129,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> {
|
||||||
if self.invoke_stack.is_empty() {
|
if self.invoke_stack.is_empty() {
|
||||||
self.pre_accounts = Vec::with_capacity(instruction.accounts.len());
|
self.pre_accounts = Vec::with_capacity(instruction.accounts.len());
|
||||||
let mut work = |_unique_index: usize, account_index: usize| {
|
let mut work = |_unique_index: usize, account_index: usize| {
|
||||||
if account_index < message.account_keys.len() && account_index < self.accounts.len()
|
if account_index < self.accounts.len() {
|
||||||
{
|
|
||||||
let account = self.accounts[account_index].1.borrow();
|
let account = self.accounts[account_index].1.borrow();
|
||||||
self.pre_accounts
|
self.pre_accounts
|
||||||
.push(PreAccount::new(&self.accounts[account_index].0, &account));
|
.push(PreAccount::new(&self.accounts[account_index].0, &account));
|
||||||
|
@ -696,7 +695,13 @@ mod tests {
|
||||||
let mut depth_reached = 0;
|
let mut depth_reached = 0;
|
||||||
for program_id in invoke_stack.iter() {
|
for program_id in invoke_stack.iter() {
|
||||||
if Err(InstructionError::CallDepth)
|
if Err(InstructionError::CallDepth)
|
||||||
== invoke_context.push(program_id, &message, &message.instructions[0], &[], None)
|
== invoke_context.push(
|
||||||
|
program_id,
|
||||||
|
&message,
|
||||||
|
&message.instructions[0],
|
||||||
|
&[MAX_DEPTH + depth_reached],
|
||||||
|
None,
|
||||||
|
)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1188,7 +1193,8 @@ mod tests {
|
||||||
|
|
||||||
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
||||||
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
||||||
let readonly_account = AccountSharedData::new(168, 1, &caller_program_id);
|
let readonly_account = AccountSharedData::new(168, 1, &solana_sdk::pubkey::new_rand());
|
||||||
|
let loader_account = AccountSharedData::new(0, 0, &native_loader::id());
|
||||||
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
||||||
program_account.set_executable(true);
|
program_account.set_executable(true);
|
||||||
|
|
||||||
|
@ -1205,10 +1211,11 @@ mod tests {
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
Rc::new(RefCell::new(readonly_account)),
|
Rc::new(RefCell::new(readonly_account)),
|
||||||
),
|
),
|
||||||
|
(caller_program_id, Rc::new(RefCell::new(loader_account))),
|
||||||
(callee_program_id, Rc::new(RefCell::new(program_account))),
|
(callee_program_id, Rc::new(RefCell::new(program_account))),
|
||||||
];
|
];
|
||||||
let account_indices = [0, 1, 2];
|
let account_indices = [0, 1, 2];
|
||||||
let program_indices = vec![3];
|
let program_indices = [3, 4];
|
||||||
|
|
||||||
let programs: Vec<(_, ProcessInstructionWithContext)> =
|
let programs: Vec<(_, ProcessInstructionWithContext)> =
|
||||||
vec![(callee_program_id, mock_process_instruction)];
|
vec![(callee_program_id, mock_process_instruction)];
|
||||||
|
@ -1218,7 +1225,8 @@ mod tests {
|
||||||
AccountMeta::new_readonly(accounts[2].0, false),
|
AccountMeta::new_readonly(accounts[2].0, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
let caller_instruction = CompiledInstruction::new(2, &(), vec![0, 1, 2, 3]);
|
let caller_instruction =
|
||||||
|
CompiledInstruction::new(program_indices[0] as u8, &(), vec![0, 1, 2, 3, 4]);
|
||||||
let callee_instruction = Instruction::new_with_bincode(
|
let callee_instruction = Instruction::new_with_bincode(
|
||||||
callee_program_id,
|
callee_program_id,
|
||||||
&MockInstruction::NoopSuccess,
|
&MockInstruction::NoopSuccess,
|
||||||
|
@ -1226,9 +1234,6 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(&[callee_instruction], None);
|
let message = Message::new(&[callee_instruction], None);
|
||||||
|
|
||||||
let feature_set = FeatureSet::all_enabled();
|
|
||||||
let demote_program_write_locks = feature_set.is_active(&demote_program_write_locks::id());
|
|
||||||
|
|
||||||
let ancestors = Ancestors::default();
|
let ancestors = Ancestors::default();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let fee_calculator = FeeCalculator::default();
|
let fee_calculator = FeeCalculator::default();
|
||||||
|
@ -1241,7 +1246,7 @@ mod tests {
|
||||||
Rc::new(RefCell::new(MockComputeMeter::default())),
|
Rc::new(RefCell::new(MockComputeMeter::default())),
|
||||||
Rc::new(RefCell::new(Executors::default())),
|
Rc::new(RefCell::new(Executors::default())),
|
||||||
None,
|
None,
|
||||||
Arc::new(feature_set),
|
Arc::new(FeatureSet::all_enabled()),
|
||||||
Arc::new(Accounts::default_for_tests()),
|
Arc::new(Accounts::default_for_tests()),
|
||||||
&ancestors,
|
&ancestors,
|
||||||
&blockhash,
|
&blockhash,
|
||||||
|
@ -1252,12 +1257,14 @@ mod tests {
|
||||||
&caller_program_id,
|
&caller_program_id,
|
||||||
&message,
|
&message,
|
||||||
&caller_instruction,
|
&caller_instruction,
|
||||||
&program_indices,
|
&program_indices[..1],
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// not owned account modified by the caller (before the invoke)
|
// not owned account modified by the caller (before the invoke)
|
||||||
|
let demote_program_write_locks =
|
||||||
|
invoke_context.is_feature_active(&demote_program_write_locks::id());
|
||||||
let caller_write_privileges = message
|
let caller_write_privileges = message
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1268,7 +1275,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
InstructionProcessor::process_cross_program_instruction(
|
InstructionProcessor::process_cross_program_instruction(
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices[1..],
|
||||||
&account_indices,
|
&account_indices,
|
||||||
&caller_write_privileges,
|
&caller_write_privileges,
|
||||||
&mut invoke_context,
|
&mut invoke_context,
|
||||||
|
@ -1282,7 +1289,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
InstructionProcessor::process_cross_program_instruction(
|
InstructionProcessor::process_cross_program_instruction(
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices[1..],
|
||||||
&account_indices,
|
&account_indices,
|
||||||
&caller_write_privileges,
|
&caller_write_privileges,
|
||||||
&mut invoke_context,
|
&mut invoke_context,
|
||||||
|
@ -1291,6 +1298,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
|
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
|
||||||
|
|
||||||
|
invoke_context.pop();
|
||||||
|
|
||||||
let cases = vec![
|
let cases = vec![
|
||||||
(MockInstruction::NoopSuccess, Ok(())),
|
(MockInstruction::NoopSuccess, Ok(())),
|
||||||
(
|
(
|
||||||
|
@ -1303,40 +1312,19 @@ mod tests {
|
||||||
Err(InstructionError::ExternalAccountDataModified),
|
Err(InstructionError::ExternalAccountDataModified),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
for case in cases {
|
for case in cases {
|
||||||
let callee_instruction =
|
let callee_instruction =
|
||||||
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
|
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
|
||||||
let message = Message::new(&[callee_instruction], None);
|
let message = Message::new(&[callee_instruction], None);
|
||||||
|
|
||||||
let ancestors = Ancestors::default();
|
|
||||||
let blockhash = Hash::default();
|
|
||||||
let fee_calculator = FeeCalculator::default();
|
|
||||||
let mut invoke_context = ThisInvokeContext::new(
|
|
||||||
Rent::default(),
|
|
||||||
&accounts,
|
|
||||||
programs.as_slice(),
|
|
||||||
None,
|
|
||||||
ComputeBudget::default(),
|
|
||||||
Rc::new(RefCell::new(MockComputeMeter::default())),
|
|
||||||
Rc::new(RefCell::new(Executors::default())),
|
|
||||||
None,
|
|
||||||
Arc::new(FeatureSet::all_enabled()),
|
|
||||||
Arc::new(Accounts::default_for_tests()),
|
|
||||||
&ancestors,
|
|
||||||
&blockhash,
|
|
||||||
&fee_calculator,
|
|
||||||
);
|
|
||||||
invoke_context
|
invoke_context
|
||||||
.push(
|
.push(
|
||||||
&caller_program_id,
|
&caller_program_id,
|
||||||
&message,
|
&message,
|
||||||
&caller_instruction,
|
&caller_instruction,
|
||||||
&program_indices,
|
&program_indices[..1],
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let caller_write_privileges = message
|
let caller_write_privileges = message
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1346,13 +1334,14 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
InstructionProcessor::process_cross_program_instruction(
|
InstructionProcessor::process_cross_program_instruction(
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices[1..],
|
||||||
&account_indices,
|
&account_indices,
|
||||||
&caller_write_privileges,
|
&caller_write_privileges,
|
||||||
&mut invoke_context,
|
&mut invoke_context,
|
||||||
),
|
),
|
||||||
case.1
|
case.1
|
||||||
);
|
);
|
||||||
|
invoke_context.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1363,7 +1352,8 @@ mod tests {
|
||||||
|
|
||||||
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
||||||
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
||||||
let readonly_account = AccountSharedData::new(168, 1, &caller_program_id);
|
let readonly_account = AccountSharedData::new(168, 1, &solana_sdk::pubkey::new_rand());
|
||||||
|
let loader_account = AccountSharedData::new(0, 0, &native_loader::id());
|
||||||
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
||||||
program_account.set_executable(true);
|
program_account.set_executable(true);
|
||||||
|
|
||||||
|
@ -1380,9 +1370,10 @@ mod tests {
|
||||||
solana_sdk::pubkey::new_rand(),
|
solana_sdk::pubkey::new_rand(),
|
||||||
Rc::new(RefCell::new(readonly_account)),
|
Rc::new(RefCell::new(readonly_account)),
|
||||||
),
|
),
|
||||||
|
(caller_program_id, Rc::new(RefCell::new(loader_account))),
|
||||||
(callee_program_id, Rc::new(RefCell::new(program_account))),
|
(callee_program_id, Rc::new(RefCell::new(program_account))),
|
||||||
];
|
];
|
||||||
let program_indices = vec![3];
|
let program_indices = [3];
|
||||||
let programs: Vec<(_, ProcessInstructionWithContext)> =
|
let programs: Vec<(_, ProcessInstructionWithContext)> =
|
||||||
vec![(callee_program_id, mock_process_instruction)];
|
vec![(callee_program_id, mock_process_instruction)];
|
||||||
let metas = vec![
|
let metas = vec![
|
||||||
|
@ -1391,7 +1382,8 @@ mod tests {
|
||||||
AccountMeta::new_readonly(accounts[2].0, false),
|
AccountMeta::new_readonly(accounts[2].0, false),
|
||||||
];
|
];
|
||||||
|
|
||||||
let caller_instruction = CompiledInstruction::new(2, &(), vec![0, 1, 2, 3]);
|
let caller_instruction =
|
||||||
|
CompiledInstruction::new(program_indices[0] as u8, &(), vec![0, 1, 2, 3, 4]);
|
||||||
let callee_instruction = Instruction::new_with_bincode(
|
let callee_instruction = Instruction::new_with_bincode(
|
||||||
callee_program_id,
|
callee_program_id,
|
||||||
&MockInstruction::NoopSuccess,
|
&MockInstruction::NoopSuccess,
|
||||||
|
@ -1399,7 +1391,6 @@ mod tests {
|
||||||
);
|
);
|
||||||
let message = Message::new(&[callee_instruction.clone()], None);
|
let message = Message::new(&[callee_instruction.clone()], None);
|
||||||
|
|
||||||
let feature_set = FeatureSet::all_enabled();
|
|
||||||
let ancestors = Ancestors::default();
|
let ancestors = Ancestors::default();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let fee_calculator = FeeCalculator::default();
|
let fee_calculator = FeeCalculator::default();
|
||||||
|
@ -1412,7 +1403,7 @@ mod tests {
|
||||||
Rc::new(RefCell::new(MockComputeMeter::default())),
|
Rc::new(RefCell::new(MockComputeMeter::default())),
|
||||||
Rc::new(RefCell::new(Executors::default())),
|
Rc::new(RefCell::new(Executors::default())),
|
||||||
None,
|
None,
|
||||||
Arc::new(feature_set),
|
Arc::new(FeatureSet::all_enabled()),
|
||||||
Arc::new(Accounts::default_for_tests()),
|
Arc::new(Accounts::default_for_tests()),
|
||||||
&ancestors,
|
&ancestors,
|
||||||
&blockhash,
|
&blockhash,
|
||||||
|
@ -1454,6 +1445,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
|
accounts[2].1.borrow_mut().data_as_mut_slice()[0] = 0;
|
||||||
|
|
||||||
|
invoke_context.pop();
|
||||||
|
|
||||||
// Other test cases
|
// Other test cases
|
||||||
let cases = vec![
|
let cases = vec![
|
||||||
(MockInstruction::NoopSuccess, Ok(())),
|
(MockInstruction::NoopSuccess, Ok(())),
|
||||||
|
@ -1475,25 +1468,6 @@ mod tests {
|
||||||
let callee_instruction =
|
let callee_instruction =
|
||||||
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
|
Instruction::new_with_bincode(callee_program_id, &case.0, metas.clone());
|
||||||
let message = Message::new(&[callee_instruction.clone()], None);
|
let message = Message::new(&[callee_instruction.clone()], None);
|
||||||
|
|
||||||
let ancestors = Ancestors::default();
|
|
||||||
let blockhash = Hash::default();
|
|
||||||
let fee_calculator = FeeCalculator::default();
|
|
||||||
let mut invoke_context = ThisInvokeContext::new(
|
|
||||||
Rent::default(),
|
|
||||||
&accounts,
|
|
||||||
programs.as_slice(),
|
|
||||||
None,
|
|
||||||
ComputeBudget::default(),
|
|
||||||
Rc::new(RefCell::new(MockComputeMeter::default())),
|
|
||||||
Rc::new(RefCell::new(Executors::default())),
|
|
||||||
None,
|
|
||||||
Arc::new(FeatureSet::all_enabled()),
|
|
||||||
Arc::new(Accounts::default_for_tests()),
|
|
||||||
&ancestors,
|
|
||||||
&blockhash,
|
|
||||||
&fee_calculator,
|
|
||||||
);
|
|
||||||
invoke_context
|
invoke_context
|
||||||
.push(
|
.push(
|
||||||
&caller_program_id,
|
&caller_program_id,
|
||||||
|
@ -1503,7 +1477,6 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
InstructionProcessor::native_invoke(
|
InstructionProcessor::native_invoke(
|
||||||
&mut invoke_context,
|
&mut invoke_context,
|
||||||
|
@ -1513,6 +1486,7 @@ mod tests {
|
||||||
),
|
),
|
||||||
case.1
|
case.1
|
||||||
);
|
);
|
||||||
|
invoke_context.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue