3

I want to increase compute budget, but I got following error message. How to add compute_budget instruction ?

Rust

    let payer = &Keypair::from_base58_string("*******************");
    let rpc = RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
    let budget_instr = ComputeBudgetInstruction::set_compute_unit_limit(1_400_000);
    let recent_blockhash = rpc.get_latest_blockhash()?;
    let message = Message::new(&[budget_instr], Some(&payer.pubkey()));
    let txn = Transaction::new(&[payer], message, recent_blockhash);
    let signature = rpc.send_and_confirm_transaction(&txn);
    match signature {
        Ok(sig) => println!("send tx.{:?}", sig),
        Err(err) => println!("error: {:?}", err),
    }
    Ok(())

Error message

error: ClientError { request: Some(SendTransaction), kind: RpcError(RpcResponseError
 { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0:
 invalid instruction data", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult 
{ err: Some(InstructionError(0, InvalidInstructionData)), logs: Some([]), accounts: None,
 units_consumed: Some(0), return_data: None }) }) }

After all, I fixed forcefully like this, refferring someone's tx. it works well.

Rust

#[derive(Debug, PartialEq, Eq, Clone, BorshSerialize, BorshDeserialize)]
pub struct ComputeBudgetInstruction {
    buffer: u8,
    limit: u32,
    price: u32,
}

pub fn budget_instruction() -> Instruction {
    let budget_id = Pubkey::from_str("ComputeBudget111111111111111111111111111111").unwrap();
    let data = ComputeBudgetInstruction {
        buffer: 0,
        limit: 1_400_000,
        price: 1,
    };
    Instruction::new_with_borsh(budget_id, &data, vec![])
}

#[tokio::main]
async fn main() -> Result<(), Error> {

.....

    let payer = &Keypair::from_base58_string("*******************");
    let rpc = RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
    let budget_instr = budget_instruction();
    let main_instr = ......;
    let recent_blockhash = rpc.get_latest_blockhash()?;
    let message = Message::new(&[budget_instr, main_instr], Some(&payer.pubkey()));
    let txn = Transaction::new(&[payer], message, recent_blockhash);
    let signature = rpc.send_and_confirm_transaction(&txn);
    match signature {
        Ok(sig) => println!("send tx.{:?}", sig),
        Err(err) => println!("error: {:?}", err),
    }
    Ok(())

solana docs about compute-budget

https://docs.solana.com/developing/programming-model/runtime#compute-budget

3
  • which cluster are you targeting? the feature that enables this instruction may not be activated
    – trent.sol
    Commented Jul 14, 2022 at 3:42
  • mainnet-beta. My instruction's compute budget was decreased from 1_400_000 to 200_000 from July 12 and all my instructions failed.
    – picorypt
    Commented Jul 14, 2022 at 4:15
  • right. the new compute budget instructions haven't been activated there as they are still under testing on devnet. in the mean time you can use the deprecated instruction as referenced below
    – trent.sol
    Commented Jul 14, 2022 at 16:10

1 Answer 1

4

try using this inplace of set_compute_limit ComputeBudgetInstruction::RequestUnitsDeprecated(1_400_000u32);

3
  • Does this require extra payment? Commented Jul 14, 2022 at 4:20
  • Thank you Nabeel, but it does not work in my enviroment. I fixed forcefully like above for now.
    – picorypt
    Commented Jul 14, 2022 at 4:41
  • curious, if you use the solana sdk in ur rust client , github.com/solana-labs/solana/blob/master/sdk/src/… and use one of the instruction helpers and see if this works, ideally this is how it should work. not sure what version is being used on mainnet tbh, which version of the api is valid, request_units | request_units_deprecated | set_compute_units Commented Jul 14, 2022 at 12:28

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.