@@ -323,42 +323,6 @@ impl<'ix_data> TransactionContext<'ix_data> {
323323 self . get_instruction_context_at_index_in_trace ( index_in_trace)
324324 }
325325
326- pub fn configure_cpi_instruction (
327- & mut self ,
328- program_index : IndexOfAccount ,
329- instruction_accounts : Vec < InstructionAccount > ,
330- deduplication_map : Vec < u16 > ,
331- instruction_data : Cow < ' ix_data , [ u8 ] > ,
332- parent_index : u16 ,
333- ) -> Result < ( ) , InstructionError > {
334- self . configure_next_instruction (
335- program_index,
336- instruction_accounts,
337- deduplication_map,
338- instruction_data,
339- ) ?;
340- self . transaction_frame . number_of_instructions = self
341- . transaction_frame
342- . number_of_instructions
343- . saturating_add ( 1 ) ;
344- self . transaction_frame . cpi_scratchpad = VmSlice :: new (
345- GUEST_INSTRUCTION_DATA_BASE_ADDRESS . saturating_add (
346- GUEST_REGION_SIZE
347- . saturating_mul ( self . transaction_frame . number_of_instructions as u64 ) ,
348- ) ,
349- 0 ,
350- ) ;
351-
352- // This ? operator is never going to fail because it is also called in
353- // `configure_next_instruction`
354- let instruction = self
355- . instruction_trace
356- . last_mut ( )
357- . ok_or ( InstructionError :: CallDepth ) ?;
358- instruction. index_of_parent_instruction = parent_index;
359- Ok ( ( ) )
360- }
361-
362326 /// Configures the next instruction.
363327 ///
364328 /// The last InstructionContext is always empty and pre-reserved for the next instruction.
@@ -368,6 +332,7 @@ impl<'ix_data> TransactionContext<'ix_data> {
368332 instruction_accounts : Vec < InstructionAccount > ,
369333 deduplication_map : Vec < u16 > ,
370334 instruction_data : Cow < ' ix_data , [ u8 ] > ,
335+ parent_index : Option < u16 > ,
371336 ) -> Result < ( ) , InstructionError > {
372337 debug_assert_eq ! ( deduplication_map. len( ) , MAX_ACCOUNTS_PER_TRANSACTION ) ;
373338 let trace_len = self . instruction_trace . len ( ) ;
@@ -378,6 +343,23 @@ impl<'ix_data> TransactionContext<'ix_data> {
378343 . last_mut ( )
379344 . ok_or ( InstructionError :: CallDepth ) ?;
380345
346+ // If we have a parent index, then we are dealing with a CPI.
347+ if let Some ( parent_index) = parent_index {
348+ self . transaction_frame . number_of_instructions = self
349+ . transaction_frame
350+ . number_of_instructions
351+ . saturating_add ( 1 ) ;
352+ instruction. index_of_parent_instruction = parent_index;
353+ }
354+
355+ self . transaction_frame . cpi_scratchpad = VmSlice :: new (
356+ GUEST_INSTRUCTION_DATA_BASE_ADDRESS . saturating_add (
357+ GUEST_REGION_SIZE
358+ . saturating_mul ( self . transaction_frame . number_of_instructions as u64 ) ,
359+ ) ,
360+ 0 ,
361+ ) ;
362+
381363 instruction. program_account_index_in_tx = program_index;
382364 instruction. configure_vm_slices (
383365 instruction_index as u64 ,
@@ -414,6 +396,7 @@ impl<'ix_data> TransactionContext<'ix_data> {
414396 instruction_accounts,
415397 dedup_map,
416398 Cow :: Owned ( instruction_data) ,
399+ None ,
417400 )
418401 }
419402
@@ -872,6 +855,7 @@ mod tests {
872855 vec ! [ InstructionAccount :: new( 1 , false , false ) ] ,
873856 vec ! [ 0 ; MAX_ACCOUNTS_PER_TRANSACTION ] ,
874857 Vec :: new ( ) . into ( ) ,
858+ None ,
875859 )
876860 . unwrap ( ) ;
877861 transaction_context. push ( ) . unwrap ( ) ;
@@ -899,6 +883,7 @@ mod tests {
899883 vec ! [ InstructionAccount :: new( 1 , false , false ) ] ,
900884 vec ! [ 0 ; MAX_ACCOUNTS_PER_TRANSACTION ] ,
901885 Vec :: new ( ) . into ( ) ,
886+ None ,
902887 )
903888 . unwrap ( ) ;
904889 transaction_context. push ( ) . unwrap ( ) ;
@@ -918,12 +903,12 @@ mod tests {
918903 ) ;
919904
920905 transaction_context
921- . configure_cpi_instruction (
906+ . configure_next_instruction (
922907 0 ,
923908 vec ! [ InstructionAccount :: new( 2 , false , true ) ] ,
924909 vec ! [ 0 ; 256 ] ,
925910 Vec :: new ( ) . into ( ) ,
926- 2 ,
911+ Some ( 2 ) ,
927912 )
928913 . unwrap ( ) ;
929914 assert_eq ! (
0 commit comments