0

I'm basically trying to work out if there's any limit to inner instructions that would limit how much I can rely on them for understanding a transaction. I understand from the docs that a list of them can be returned for each transaction instruction.

So if I have a transaction that calls into program A at instruction index 0, and that program makes 2 CPI calls, there'd be two inner instructions.

Does this work recursively too? If I have programs A, B and C, and they call each other:

A --CPI to-> B --CPI to-> C --CPI to-> token program transfer instruction

Then if I call A in a transaction at index 0, will I get something like this?:

{
  index: 0,
  instructions: [
    {
      programIdIndex: // the one for B,
      accounts: //,
      data: //
    },
    {
      programIdIndex: // the one for C,
      accounts: //,
      data: //
    },
    {
      programIdIndex: // the one for token program,
      accounts: // token transfer accounts
      data: // token transfer data
    },
  ]

Assuming this does work, are there any limitations to this recursion, other than the existing limits of transaction size? Given there's no re-entrancy, are we able to always unroll inner instructions fully?

1
  • 1
    It does work recursively -- everything will be in innerInstructions
    – Jon C
    Feb 26 at 19:51

1 Answer 1

2

There only limit is that the CPI depth is currently limited to 4:

https://solana.com/docs/programs/limitations#cpi-call-depth-calldepth-error

So your A->B->C->Transfer example is fine, but it's at max depth. It's pretty common to see something like:

A->B->Transfer
    ->Transfer Again
    ->Transfer Again
   B<-Return
A<-Return
1
  • Thanks, that's helpful! It makes me think that inner instructions should unroll them all, since the max depth is only 4.
    – Callum M
    Feb 23 at 11:13

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.