3

I am making a CPI to a heavy instruction in another program and running into insufficient compute limit issues. How do I increase the compute limit for my instruction. I once saw up to 1.4M compute units for an instruction.

2 Answers 2

4

https://solanacookbook.com/references/basic-transactions.html#how-to-change-compute-budget-fee-priority-for-a-transaction

Use ComputeBudgetProgram.setComputeUnitLimit({ units: number }) to set the new compute budget. The value provided will replace the default value. Transactions should request the minimum amount of CU required for execution to maximize throughput, or minimize fees.

const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({ 
  units: 1000000 
});

const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({ 
  microLamports: 1 
});

const transaction = new Transaction()
.add(modifyComputeUnits)
.add(addPriorityFee)
.add(
    SystemProgram.transfer({
      fromPubkey: payer.publicKey,
      toPubkey: toAccount,
      lamports: 10000000,
    })
  );
3

I haven't really found great docs on it, but I believe the way it works is that your transaction's first instruction must be this: https://github.com/solana-labs/solana/blob/00929f836348d76cb3503d0ba5f76f0d275bcc66/sdk/src/compute_budget.rs#L34

Frontend implementation here: https://github.com/solana-labs/solana/blob/master/web3.js/src/programs/compute-budget.ts

Code demonstration in the tests here: https://github.com/solana-labs/solana/blob/master/web3.js/test/program-tests/compute-budget.test.ts

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.