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