general solana question, on localhost I am getting a "Program ETsjka7.....jsa87 consumed 200_000 of 200_000 compute units" error. I saw on twitter the max compute budget is 1.4m on mainnet, is this true and how do I change the max compute budget on localhost?
2 Answers
Here is how you can change the compute budget using web3.js. In the code snippet we increase it to 400k CU
import * as anchor from "@project-serum/anchor";
const ix = anchor.web3.SystemProgram.transfer({
fromPubkey: fromKeypair.publicKey,
toPubkey: toKeypair.publicKey,
lamports: lamportsToSend,
});
const modifyComputeUnits =
anchor.web3.ComputeBudgetProgram.setComputeUnitLimit({
units: 400_000,
});
let tx = new anchor.web3.Transaction()
.add(ix)
.add(modifyComputeUnits);
let txHash = await anchor.web3.sendAndConfirmTransaction(
devnetConnection,
tx,
[borrowerKeypair]
);
According the the Solana Cook Book the max default CU is 200K which can be increased to a maximum of 1.4 million CU.
What you saw on twitter is not quite correct.
The maximum CU/tx is 1.4M, but only if you request more than the default. Without requesting, the max CU/tx is calculated as max(200k * instruction_count, 1.4M)
. So presumably your failing transaction has just one instruction.
Rather than manipulate the test validator's runtime, which will allow you to do what you want, but in a way that won't work on the public clusters, you should instead request more CUs in your transaction as you will need to when you're ready to deploy. To do this you need to add the appropriate ComputeBudget
program instruction which unfortunately is not well documented in the JS docs, but you can read about it in the solana-sdk
crate rustdocs