0

I am currently trying to increase the Compute-Budget on my Solana Program on devnet. I am using solana version 1.9.9.

I have checked the anchor discord, and found this implementation to request a larger compute-budget. however, when I run this code-snippet

    const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4))
    );

    const additionalComputeIx: TransactionInstruction = new TransactionInstruction({
        keys: [],
        programId: new PublicKey("ComputeBudget111111111111111111111111111111"),
        data,
    });
    ...

I get invalid instruction data. any idea why this could be?

I was getting Compute Budget Exceeded before adding this instruction to the transaction.

DaveTheAl
  • 1,995
  • 4
  • 35
  • 65

1 Answers1

3

You're very close! The instruction definition for requesting an increase from the compute budget program contains a little-endian u32 for the units, but then also a little-endian u32 for the additional fee to add, which you must include, even if it's 0. So instead, you should try:

const data = Buffer.from(
        Uint8Array.of(0, ...new BN(256000).toArray("le", 4), ...new BN(0).toArray("le", 4))
    );

More information about the instruction at https://github.com/solana-labs/solana/blob/a6742b5838ffe6f37afcb24ab32ad2287a1514cf/sdk/src/compute_budget.rs#L10

Jon C
  • 7,019
  • 10
  • 17
  • damn, thanks a lot! :) just to understand, how would I determine the additional fee? also I will try this out the moment devnet comes online again xd – DaveTheAl Apr 18 '22 at 14:32
  • 1
    That's up to you -- it's whatever extra you want to add to make sure your transaction is processed during times of congestion. You can probably stick with 0 on devnet :-) – Jon C Apr 18 '22 at 14:52