6

As a followup to in a program, is it possible to tell if an instruction was invoked by a CPI call?, I was curious if the instructions sysvar would ever contain CPI instruction data.

For a more concrete example I ran an experiment with the following tx structure,

Instruction 1
Instruction 2
  Instruction 2a
  Instruction 2b
  Instruction 2c
Instruction 3

When in the middle of executing 2b, the instruction sysvar account info only had data for 1,2,3, and NOT 2a, 2b, 2c. Can someone confirm that this is expected?

1 Answer 1

4

Yes, the instructions sysvar only includes instructions that are present in the toplevel transaction. This is due to the implementation: the instructions sysvar is filled before the transaction is executed, only the current index is updated between executions of different instructions from the same transaction.

Instructions executed via CPIs can only be known dynamically (it is not possible to know which CPIs a program will perform before executing that program), so it would not be possible to include them ahead of time in the instructions sysvar. The only thing you could for CPIs is a sysvar containing the history of already-executed CPIs in the current TX, but there is no such sysvar in solana right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.