@@ -368,10 +368,10 @@ impl<'a> InvokeContext<'a> {
368
368
369
369
self . pre_accounts = Vec :: with_capacity ( instruction_accounts. len ( ) ) ;
370
370
371
- for ( index_in_instruction , instruction_account) in
371
+ for ( instruction_account_index , instruction_account) in
372
372
instruction_accounts. iter ( ) . enumerate ( )
373
373
{
374
- if index_in_instruction != instruction_account. index_in_callee {
374
+ if instruction_account_index != instruction_account. index_in_callee {
375
375
continue ; // Skip duplicate account
376
376
}
377
377
if instruction_account. index_in_transaction
@@ -398,7 +398,8 @@ impl<'a> InvokeContext<'a> {
398
398
self . transaction_context
399
399
. get_instruction_context_at ( level)
400
400
. and_then ( |instruction_context| {
401
- instruction_context. try_borrow_program_account ( self . transaction_context )
401
+ instruction_context
402
+ . try_borrow_last_program_account ( self . transaction_context )
402
403
} )
403
404
. map ( |program_account| program_account. get_key ( ) == program_id)
404
405
. unwrap_or ( false )
@@ -407,7 +408,7 @@ impl<'a> InvokeContext<'a> {
407
408
. transaction_context
408
409
. get_current_instruction_context ( )
409
410
. and_then ( |instruction_context| {
410
- instruction_context. try_borrow_program_account ( self . transaction_context )
411
+ instruction_context. try_borrow_last_program_account ( self . transaction_context )
411
412
} )
412
413
. map ( |program_account| program_account. get_key ( ) == program_id)
413
414
. unwrap_or ( false ) ;
@@ -490,7 +491,7 @@ impl<'a> InvokeContext<'a> {
490
491
. get_current_instruction_context ( )
491
492
. map_err ( |_| InstructionError :: CallDepth ) ?;
492
493
let program_id = instruction_context
493
- . get_program_key ( self . transaction_context )
494
+ . get_last_program_key ( self . transaction_context )
494
495
. map_err ( |_| InstructionError :: CallDepth ) ?;
495
496
496
497
// Verify all executable accounts have zero outstanding refs
@@ -504,8 +505,10 @@ impl<'a> InvokeContext<'a> {
504
505
// Verify the per-account instruction results
505
506
let ( mut pre_sum, mut post_sum) = ( 0_u128 , 0_u128 ) ;
506
507
let mut pre_account_index = 0 ;
507
- for ( index_in_instruction, instruction_account) in instruction_accounts. iter ( ) . enumerate ( ) {
508
- if index_in_instruction != instruction_account. index_in_callee {
508
+ for ( instruction_account_index, instruction_account) in
509
+ instruction_accounts. iter ( ) . enumerate ( )
510
+ {
511
+ if instruction_account_index != instruction_account. index_in_callee {
509
512
continue ; // Skip duplicate account
510
513
}
511
514
{
@@ -581,13 +584,15 @@ impl<'a> InvokeContext<'a> {
581
584
let transaction_context = & self . transaction_context ;
582
585
let instruction_context = transaction_context. get_current_instruction_context ( ) ?;
583
586
let program_id = instruction_context
584
- . get_program_key ( transaction_context)
587
+ . get_last_program_key ( transaction_context)
585
588
. map_err ( |_| InstructionError :: CallDepth ) ?;
586
589
587
590
// Verify the per-account instruction results
588
591
let ( mut pre_sum, mut post_sum) = ( 0_u128 , 0_u128 ) ;
589
- for ( index_in_instruction, instruction_account) in instruction_accounts. iter ( ) . enumerate ( ) {
590
- if index_in_instruction != instruction_account. index_in_callee {
592
+ for ( instruction_account_index, instruction_account) in
593
+ instruction_accounts. iter ( ) . enumerate ( )
594
+ {
595
+ if instruction_account_index != instruction_account. index_in_callee {
591
596
continue ; // Skip duplicate account
592
597
}
593
598
if instruction_account. index_in_transaction
@@ -599,11 +604,7 @@ impl<'a> InvokeContext<'a> {
599
604
. get_account_at_index ( instruction_account. index_in_transaction ) ?;
600
605
let is_writable = if before_instruction_context_push {
601
606
instruction_context
602
- . try_borrow_instruction_account (
603
- self . transaction_context ,
604
- instruction_account. index_in_caller ,
605
- ) ?
606
- . is_writable ( )
607
+ . is_instruction_account_writable ( instruction_account. index_in_caller ) ?
607
608
} else {
608
609
instruction_account. is_writable
609
610
} ;
@@ -713,7 +714,7 @@ impl<'a> InvokeContext<'a> {
713
714
let instruction_context = self . transaction_context . get_current_instruction_context ( ) ?;
714
715
let mut deduplicated_instruction_accounts: Vec < InstructionAccount > = Vec :: new ( ) ;
715
716
let mut duplicate_indicies = Vec :: with_capacity ( instruction. accounts . len ( ) ) ;
716
- for ( index_in_instruction , account_meta) in instruction. accounts . iter ( ) . enumerate ( ) {
717
+ for ( instruction_account_index , account_meta) in instruction. accounts . iter ( ) . enumerate ( ) {
717
718
let index_in_transaction = self
718
719
. transaction_context
719
720
. find_index_of_account ( & account_meta. pubkey )
@@ -740,10 +741,10 @@ impl<'a> InvokeContext<'a> {
740
741
instruction_account. is_writable |= account_meta. is_writable ;
741
742
} else {
742
743
let index_in_caller = instruction_context
743
- . find_index_of_account ( self . transaction_context , & account_meta . pubkey )
744
- . map ( |index| {
745
- index . saturating_sub ( instruction_context . get_number_of_program_accounts ( ) )
746
- } )
744
+ . find_index_of_instruction_account (
745
+ self . transaction_context ,
746
+ & account_meta . pubkey ,
747
+ )
747
748
. ok_or_else ( || {
748
749
ic_msg ! (
749
750
self ,
@@ -756,7 +757,7 @@ impl<'a> InvokeContext<'a> {
756
757
deduplicated_instruction_accounts. push ( InstructionAccount {
757
758
index_in_transaction,
758
759
index_in_caller,
759
- index_in_callee : index_in_instruction ,
760
+ index_in_callee : instruction_account_index ,
760
761
is_signer : account_meta. is_signer ,
761
762
is_writable : account_meta. is_writable ,
762
763
} ) ;
@@ -804,13 +805,13 @@ impl<'a> InvokeContext<'a> {
804
805
// Find and validate executables / program accounts
805
806
let callee_program_id = instruction. program_id ;
806
807
let program_account_index = instruction_context
807
- . find_index_of_account ( self . transaction_context , & callee_program_id)
808
+ . find_index_of_instruction_account ( self . transaction_context , & callee_program_id)
808
809
. ok_or_else ( || {
809
810
ic_msg ! ( self , "Unknown program {}" , callee_program_id) ;
810
811
InstructionError :: MissingAccount
811
812
} ) ?;
812
813
let borrowed_program_account = instruction_context
813
- . try_borrow_account ( self . transaction_context , program_account_index) ?;
814
+ . try_borrow_instruction_account ( self . transaction_context , program_account_index) ?;
814
815
if !borrowed_program_account. is_executable ( ) {
815
816
ic_msg ! ( self , "Account {} is not executable" , callee_program_id) ;
816
817
return Err ( InstructionError :: AccountNotExecutable ) ;
@@ -952,7 +953,7 @@ impl<'a> InvokeContext<'a> {
952
953
953
954
let ( first_instruction_account, builtin_id) = {
954
955
let borrowed_root_account = instruction_context
955
- . try_borrow_account ( self . transaction_context , 0 )
956
+ . try_borrow_program_account ( self . transaction_context , 0 )
956
957
. map_err ( |_| InstructionError :: UnsupportedProgramId ) ?;
957
958
let owner_id = borrowed_root_account. get_owner ( ) ;
958
959
if solana_sdk:: native_loader:: check_id ( owner_id) {
@@ -964,7 +965,8 @@ impl<'a> InvokeContext<'a> {
964
965
965
966
for entry in self . builtin_programs {
966
967
if entry. program_id == builtin_id {
967
- let program_id = instruction_context. get_program_id ( self . transaction_context ) ;
968
+ let program_id =
969
+ * instruction_context. get_last_program_key ( self . transaction_context ) ?;
968
970
if builtin_id == program_id {
969
971
let logger = self . get_log_collector ( ) ;
970
972
stable_log:: program_invoke ( & logger, & program_id, self . get_stack_height ( ) ) ;
@@ -1123,19 +1125,19 @@ pub fn prepare_mock_invoke_context(
1123
1125
) -> MockInvokeContextPreparation {
1124
1126
let mut instruction_accounts: Vec < InstructionAccount > =
1125
1127
Vec :: with_capacity ( instruction_account_metas. len ( ) ) ;
1126
- for ( index_in_instruction , account_meta) in instruction_account_metas. iter ( ) . enumerate ( ) {
1128
+ for ( instruction_account_index , account_meta) in instruction_account_metas. iter ( ) . enumerate ( ) {
1127
1129
let index_in_transaction = transaction_accounts
1128
1130
. iter ( )
1129
1131
. position ( |( key, _account) | * key == account_meta. pubkey )
1130
1132
. unwrap_or ( transaction_accounts. len ( ) ) ;
1131
1133
let index_in_callee = instruction_accounts
1132
- . get ( 0 ..index_in_instruction )
1134
+ . get ( 0 ..instruction_account_index )
1133
1135
. unwrap ( )
1134
1136
. iter ( )
1135
1137
. position ( |instruction_account| {
1136
1138
instruction_account. index_in_transaction == index_in_transaction
1137
1139
} )
1138
- . unwrap_or ( index_in_instruction ) ;
1140
+ . unwrap_or ( instruction_account_index ) ;
1139
1141
instruction_accounts. push ( InstructionAccount {
1140
1142
index_in_transaction,
1141
1143
index_in_caller : index_in_transaction,
@@ -1295,7 +1297,7 @@ mod tests {
1295
1297
let transaction_context = & invoke_context. transaction_context ;
1296
1298
let instruction_context = transaction_context. get_current_instruction_context ( ) ?;
1297
1299
let instruction_data = instruction_context. get_instruction_data ( ) ;
1298
- let program_id = instruction_context. get_program_key ( transaction_context) ?;
1300
+ let program_id = instruction_context. get_last_program_key ( transaction_context) ?;
1299
1301
assert_eq ! (
1300
1302
program_id,
1301
1303
instruction_context
@@ -1528,12 +1530,12 @@ mod tests {
1528
1530
AccountMeta :: new_readonly( accounts. get( 2 ) . unwrap( ) . 0 , false ) ,
1529
1531
] ;
1530
1532
let instruction_accounts = ( 0 ..4 )
1531
- . map ( |index_in_instruction | InstructionAccount {
1532
- index_in_transaction : index_in_instruction ,
1533
- index_in_caller : index_in_instruction ,
1534
- index_in_callee : index_in_instruction ,
1533
+ . map ( |instruction_account_index | InstructionAccount {
1534
+ index_in_transaction : instruction_account_index ,
1535
+ index_in_caller : instruction_account_index ,
1536
+ index_in_callee : instruction_account_index ,
1535
1537
is_signer : false ,
1536
- is_writable : index_in_instruction < 2 ,
1538
+ is_writable : instruction_account_index < 2 ,
1537
1539
} )
1538
1540
. collect :: < Vec < _ > > ( ) ;
1539
1541
let mut transaction_context = TransactionContext :: new ( accounts, 2 , 8 ) ;
0 commit comments