From 091999a17e5cfbf43a6c53d7e5ef1e05f9b679f9 Mon Sep 17 00:00:00 2001 From: TristanDebrunner Date: Mon, 1 Jul 2019 18:34:22 -0600 Subject: [PATCH] fix Instruction and CompiledInstruction field names (#4895) * s/program_ids_index/program_id for Instruction * s/program_ids_index/program_id_index for CompiledInstruction --- programs/budget_api/src/budget_processor.rs | 4 ++-- runtime/src/accounts.rs | 4 ++-- runtime/src/bank.rs | 2 +- runtime/src/message_processor.rs | 2 +- sdk/src/instruction.rs | 16 ++++++---------- sdk/src/message.rs | 6 +++--- sdk/src/transaction.rs | 2 +- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/programs/budget_api/src/budget_processor.rs b/programs/budget_api/src/budget_processor.rs index 569898e6a7..b7500298d7 100644 --- a/programs/budget_api/src/budget_processor.rs +++ b/programs/budget_api/src/budget_processor.rs @@ -256,7 +256,7 @@ mod tests { // Attack! Part 2: Point the instruction to the expected, but unsigned, key. message.account_keys.insert(3, alice_pubkey); 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. assert_eq!( @@ -305,7 +305,7 @@ mod tests { // Attack! Part 2: Point the instruction to the expected, but unsigned, key. message.account_keys.insert(3, alice_pubkey); 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. assert_eq!( diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 8b3a86d7b7..c1c7164e7f 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -236,11 +236,11 @@ impl Accounts { .instructions .iter() .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; 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( storage, ancestors, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 70a79eb4c6..6e15b63a11 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2106,7 +2106,7 @@ mod tests { system_transaction::transfer(&mint_keypair, &keypair.pubkey(), 1, genesis_block.hash()); 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!( bank.process_transaction(&tx_invalid_program_index), Err(TransactionError::InvalidAccountIndex) diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index 815abcb4d1..bb9a7c65eb 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -260,7 +260,7 @@ impl MessageProcessor { ) -> Result<(), TransactionError> { for (instruction_index, instruction) in message.instructions.iter().enumerate() { let executable_index = message - .program_position(instruction.program_ids_index as usize) + .program_position(instruction.program_id_index as usize) .ok_or(TransactionError::InvalidAccountIndex)?; let executable_accounts = &mut loaders[executable_index]; let mut program_accounts = get_subset_unchecked_mut(accounts, &instruction.accounts) diff --git a/sdk/src/instruction.rs b/sdk/src/instruction.rs index 6781ab154d..7bc5fc64e6 100644 --- a/sdk/src/instruction.rs +++ b/sdk/src/instruction.rs @@ -76,7 +76,7 @@ impl InstructionError { #[derive(Debug, PartialEq, Clone)] pub struct 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 pub accounts: Vec, /// Opaque data passed to the instruction processor @@ -84,14 +84,10 @@ pub struct Instruction { } impl Instruction { - pub fn new( - program_ids_index: Pubkey, - data: &T, - accounts: Vec, - ) -> Self { + pub fn new(program_id: Pubkey, data: &T, accounts: Vec) -> Self { let data = serialize(data).unwrap(); Self { - program_ids_index, + program_id, data, accounts, } @@ -131,7 +127,7 @@ impl AccountMeta { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct CompiledInstruction { /// 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 #[serde(with = "short_vec")] pub accounts: Vec, @@ -144,13 +140,13 @@ impl CompiledInstruction { pub fn new(program_ids_index: u8, data: &T, accounts: Vec) -> Self { let data = serialize(data).unwrap(); Self { - program_ids_index, + program_id_index: program_ids_index, data, accounts, } } 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] } } diff --git a/sdk/src/message.rs b/sdk/src/message.rs index aa46e1fd34..46a93e7954 100644 --- a/sdk/src/message.rs +++ b/sdk/src/message.rs @@ -18,7 +18,7 @@ fn compile_instruction(ix: Instruction, keys: &[Pubkey]) -> CompiledInstruction .collect(); CompiledInstruction { - program_ids_index: position(keys, &ix.program_ids_index), + program_id_index: position(keys, &ix.program_id), data: ix.data.clone(), accounts, } @@ -118,7 +118,7 @@ fn get_keys(instructions: &[Instruction], payer: Option<&Pubkey>) -> Instruction fn get_program_ids(instructions: &[Instruction]) -> Vec { instructions .iter() - .map(|ix| ix.program_ids_index) + .map(|ix| ix.program_id) .unique() .collect() } @@ -205,7 +205,7 @@ impl Message { pub fn program_ids(&self) -> Vec<&Pubkey> { self.instructions .iter() - .map(|ix| &self.account_keys[ix.program_ids_index as usize]) + .map(|ix| &self.account_keys[ix.program_id_index as usize]) .collect() } diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 08427323ae..e4e176d538 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -224,7 +224,7 @@ impl Transaction { pub fn verify_refs(&self) -> bool { let message = self.message(); 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; } for account_index in &instruction.accounts {