Solana: ComputeBudget in Typescript SDK

1.1k views Asked by At

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.

1

There are 1 answers

2
Jon C On

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