fix Instruction and CompiledInstruction field names (#4895)
* s/program_ids_index/program_id for Instruction * s/program_ids_index/program_id_index for CompiledInstruction
This commit is contained in:
parent
417066ad30
commit
091999a17e
|
@ -256,7 +256,7 @@ mod tests {
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
message.account_keys.insert(3, alice_pubkey);
|
message.account_keys.insert(3, alice_pubkey);
|
||||||
message.instructions[0].accounts[0] = 3;
|
message.instructions[0].accounts[0] = 3;
|
||||||
message.instructions[0].program_ids_index = 4;
|
message.instructions[0].program_id_index = 4;
|
||||||
|
|
||||||
// Ensure the transaction fails because of the unsigned key.
|
// Ensure the transaction fails because of the unsigned key.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -305,7 +305,7 @@ mod tests {
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
message.account_keys.insert(3, alice_pubkey);
|
message.account_keys.insert(3, alice_pubkey);
|
||||||
message.instructions[0].accounts[0] = 3;
|
message.instructions[0].accounts[0] = 3;
|
||||||
message.instructions[0].program_ids_index = 4;
|
message.instructions[0].program_id_index = 4;
|
||||||
|
|
||||||
// Ensure the transaction fails because of the unsigned key.
|
// Ensure the transaction fails because of the unsigned key.
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -236,11 +236,11 @@ impl Accounts {
|
||||||
.instructions
|
.instructions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ix| {
|
.map(|ix| {
|
||||||
if message.account_keys.len() <= ix.program_ids_index as usize {
|
if message.account_keys.len() <= ix.program_id_index as usize {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
return Err(TransactionError::AccountNotFound);
|
return Err(TransactionError::AccountNotFound);
|
||||||
}
|
}
|
||||||
let program_id = message.account_keys[ix.program_ids_index as usize];
|
let program_id = message.account_keys[ix.program_id_index as usize];
|
||||||
Self::load_executable_accounts(
|
Self::load_executable_accounts(
|
||||||
storage,
|
storage,
|
||||||
ancestors,
|
ancestors,
|
||||||
|
|
|
@ -2106,7 +2106,7 @@ mod tests {
|
||||||
system_transaction::transfer(&mint_keypair, &keypair.pubkey(), 1, genesis_block.hash());
|
system_transaction::transfer(&mint_keypair, &keypair.pubkey(), 1, genesis_block.hash());
|
||||||
|
|
||||||
let mut tx_invalid_program_index = tx.clone();
|
let mut tx_invalid_program_index = tx.clone();
|
||||||
tx_invalid_program_index.message.instructions[0].program_ids_index = 42;
|
tx_invalid_program_index.message.instructions[0].program_id_index = 42;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx_invalid_program_index),
|
bank.process_transaction(&tx_invalid_program_index),
|
||||||
Err(TransactionError::InvalidAccountIndex)
|
Err(TransactionError::InvalidAccountIndex)
|
||||||
|
|
|
@ -260,7 +260,7 @@ impl MessageProcessor {
|
||||||
) -> Result<(), TransactionError> {
|
) -> Result<(), TransactionError> {
|
||||||
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
|
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
|
||||||
let executable_index = message
|
let executable_index = message
|
||||||
.program_position(instruction.program_ids_index as usize)
|
.program_position(instruction.program_id_index as usize)
|
||||||
.ok_or(TransactionError::InvalidAccountIndex)?;
|
.ok_or(TransactionError::InvalidAccountIndex)?;
|
||||||
let executable_accounts = &mut loaders[executable_index];
|
let executable_accounts = &mut loaders[executable_index];
|
||||||
let mut program_accounts = get_subset_unchecked_mut(accounts, &instruction.accounts)
|
let mut program_accounts = get_subset_unchecked_mut(accounts, &instruction.accounts)
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl InstructionError {
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Instruction {
|
pub struct Instruction {
|
||||||
/// Pubkey of the instruction processor that executes this instruction
|
/// Pubkey of the instruction processor that executes this instruction
|
||||||
pub program_ids_index: Pubkey,
|
pub program_id: Pubkey,
|
||||||
/// Metadata for what accounts should be passed to the instruction processor
|
/// Metadata for what accounts should be passed to the instruction processor
|
||||||
pub accounts: Vec<AccountMeta>,
|
pub accounts: Vec<AccountMeta>,
|
||||||
/// Opaque data passed to the instruction processor
|
/// Opaque data passed to the instruction processor
|
||||||
|
@ -84,14 +84,10 @@ pub struct Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instruction {
|
impl Instruction {
|
||||||
pub fn new<T: Serialize>(
|
pub fn new<T: Serialize>(program_id: Pubkey, data: &T, accounts: Vec<AccountMeta>) -> Self {
|
||||||
program_ids_index: Pubkey,
|
|
||||||
data: &T,
|
|
||||||
accounts: Vec<AccountMeta>,
|
|
||||||
) -> Self {
|
|
||||||
let data = serialize(data).unwrap();
|
let data = serialize(data).unwrap();
|
||||||
Self {
|
Self {
|
||||||
program_ids_index,
|
program_id,
|
||||||
data,
|
data,
|
||||||
accounts,
|
accounts,
|
||||||
}
|
}
|
||||||
|
@ -131,7 +127,7 @@ impl AccountMeta {
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct CompiledInstruction {
|
pub struct CompiledInstruction {
|
||||||
/// Index into the transaction keys array indicating the program account that executes this instruction
|
/// Index into the transaction keys array indicating the program account that executes this instruction
|
||||||
pub program_ids_index: u8,
|
pub program_id_index: u8,
|
||||||
/// Ordered indices into the transaction keys array indicating which accounts to pass to the program
|
/// Ordered indices into the transaction keys array indicating which accounts to pass to the program
|
||||||
#[serde(with = "short_vec")]
|
#[serde(with = "short_vec")]
|
||||||
pub accounts: Vec<u8>,
|
pub accounts: Vec<u8>,
|
||||||
|
@ -144,13 +140,13 @@ impl CompiledInstruction {
|
||||||
pub fn new<T: Serialize>(program_ids_index: u8, data: &T, accounts: Vec<u8>) -> Self {
|
pub fn new<T: Serialize>(program_ids_index: u8, data: &T, accounts: Vec<u8>) -> Self {
|
||||||
let data = serialize(data).unwrap();
|
let data = serialize(data).unwrap();
|
||||||
Self {
|
Self {
|
||||||
program_ids_index,
|
program_id_index: program_ids_index,
|
||||||
data,
|
data,
|
||||||
accounts,
|
accounts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn program_id<'a>(&self, program_ids: &'a [Pubkey]) -> &'a Pubkey {
|
pub fn program_id<'a>(&self, program_ids: &'a [Pubkey]) -> &'a Pubkey {
|
||||||
&program_ids[self.program_ids_index as usize]
|
&program_ids[self.program_id_index as usize]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ fn compile_instruction(ix: Instruction, keys: &[Pubkey]) -> CompiledInstruction
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
CompiledInstruction {
|
CompiledInstruction {
|
||||||
program_ids_index: position(keys, &ix.program_ids_index),
|
program_id_index: position(keys, &ix.program_id),
|
||||||
data: ix.data.clone(),
|
data: ix.data.clone(),
|
||||||
accounts,
|
accounts,
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ fn get_keys(instructions: &[Instruction], payer: Option<&Pubkey>) -> Instruction
|
||||||
fn get_program_ids(instructions: &[Instruction]) -> Vec<Pubkey> {
|
fn get_program_ids(instructions: &[Instruction]) -> Vec<Pubkey> {
|
||||||
instructions
|
instructions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ix| ix.program_ids_index)
|
.map(|ix| ix.program_id)
|
||||||
.unique()
|
.unique()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ impl Message {
|
||||||
pub fn program_ids(&self) -> Vec<&Pubkey> {
|
pub fn program_ids(&self) -> Vec<&Pubkey> {
|
||||||
self.instructions
|
self.instructions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ix| &self.account_keys[ix.program_ids_index as usize])
|
.map(|ix| &self.account_keys[ix.program_id_index as usize])
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ impl Transaction {
|
||||||
pub fn verify_refs(&self) -> bool {
|
pub fn verify_refs(&self) -> bool {
|
||||||
let message = self.message();
|
let message = self.message();
|
||||||
for instruction in &message.instructions {
|
for instruction in &message.instructions {
|
||||||
if (instruction.program_ids_index as usize) >= message.account_keys.len() {
|
if (instruction.program_id_index as usize) >= message.account_keys.len() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for account_index in &instruction.accounts {
|
for account_index in &instruction.accounts {
|
||||||
|
|
Loading…
Reference in New Issue