@@ -20,9 +20,8 @@ struct fd_borrowed_account {
20
20
fd_txn_account_t * acct;
21
21
fd_exec_instr_ctx_t const * instr_ctx;
22
22
23
- /* Agave's index_in_instruction includes program and instruction accounts,
24
- with the program account occupying index 0,
25
- so the value for instruction accounts will be off by one. */
23
+ /* index_in_instruction will be USHORT_MAX for borrowed program accounts because
24
+ they are not stored in the list of instruction accounts in the instruction context */
26
25
ushort index_in_instruction;
27
26
};
28
27
typedef struct fd_borrowed_account fd_borrowed_account_t ;
@@ -294,7 +293,7 @@ fd_borrowed_account_is_executable_internal( fd_borrowed_account_t const * borrow
294
293
fd_borrowed_account_is_executable ( borrowed_acct );
295
294
}
296
295
297
- /* fd_borrowed_account_is_signer mirror the Agave functions
296
+ /* fd_borrowed_account_is_signer mirrors the Agave function
298
297
solana_sdk::transaction_context::BorrowedAccount::is_signer.
299
298
Returns 1 if the account is a signer or is writable and 0 otherwise.
300
299
@@ -305,27 +304,14 @@ fd_borrowed_account_is_signer( fd_borrowed_account_t const * borrowed_acct ) {
305
304
fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx ;
306
305
fd_instr_info_t const * instr = instr_ctx->instr ;
307
306
308
- /* The index in instruction is 1-indexed for instruction accounts, with the program account
309
- occupying index 0. */
310
- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction > instr_ctx->instr ->acct_cnt ) ) {
307
+ if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction >=instr_ctx->instr ->acct_cnt ) ) {
311
308
return 0 ;
312
309
}
313
310
314
- /* Check if account is a program account
315
- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1053 */
316
- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction <
317
- fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) ) ) {
318
- return 0 ;
319
- }
320
-
321
- /* Converts the index_in_instruction
322
- into an instruction account index by subtracting the number of program accounts.
323
- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1045-L1046 */
324
- ulong idx = fd_ulong_sat_sub ( (ulong)borrowed_acct->index_in_instruction , fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) );
325
- return fd_instr_acc_is_signer_idx ( instr, idx );
311
+ return fd_instr_acc_is_signer_idx ( instr, borrowed_acct->index_in_instruction );
326
312
}
327
313
328
- /* fd_borrowed_account_is_writer mirror the Agave functions
314
+ /* fd_borrowed_account_is_writer mirrors the Agave function
329
315
solana_sdk::transaction_context::BorrowedAccount::is_writer.
330
316
Returns 1 if the account is a signer or is writable and 0 otherwise.
331
317
@@ -336,24 +322,11 @@ fd_borrowed_account_is_writable( fd_borrowed_account_t const * borrowed_acct ) {
336
322
fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx ;
337
323
fd_instr_info_t const * instr = instr_ctx->instr ;
338
324
339
- /* The index in instruction is 1-indexed for instruction accounts, with the program account
340
- occupying index 0. */
341
- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction > instr_ctx->instr ->acct_cnt ) ) {
342
- return 0 ;
343
- }
344
-
345
- /* Check if account is a program account
346
- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1053 */
347
- if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction <
348
- fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) ) ) {
325
+ if ( FD_UNLIKELY ( borrowed_acct->index_in_instruction >=instr_ctx->instr ->acct_cnt ) ) {
349
326
return 0 ;
350
327
}
351
328
352
- /* Converts the index_in_instruction
353
- into an instruction account index by subtracting the number of program accounts.
354
- https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L1058-L1059 */
355
- ulong idx = fd_ulong_sat_sub ( (ulong)borrowed_acct->index_in_instruction , fd_exec_instr_ctx_get_number_of_program_accounts ( instr_ctx ) );
356
- return fd_instr_acc_is_writable_idx ( instr, idx );
329
+ return fd_instr_acc_is_writable_idx ( instr, borrowed_acct->index_in_instruction );
357
330
}
358
331
359
332
/* fd_borrowed_account_is_owned_by_current_program mirrors Agave's
0 commit comments