From a4089c7924e4d05cadb383bc524c95cd44a0efb4 Mon Sep 17 00:00:00 2001 From: Tao Zhu <82401714+taozhu-chicago@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:17:56 -0500 Subject: [PATCH] Priority queue supports deprecated compute budget ix (#32567) Supports deprecated compute budget instruction when getting transaction's priority details (cherry picked from commit 19f5b49abbcaf215ce674fb8311b5cea770ac774) --- runtime/src/transaction_priority_details.rs | 58 ++++++++++++++++++--- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/runtime/src/transaction_priority_details.rs b/runtime/src/transaction_priority_details.rs index d454fe8a8bd2d9..096147e04b4004 100644 --- a/runtime/src/transaction_priority_details.rs +++ b/runtime/src/transaction_priority_details.rs @@ -27,11 +27,11 @@ pub trait GetTransactionPriorityDetails { let prioritization_fee_details = compute_budget .process_instructions( instructions, - true, // use default units per instruction - false, // stop supporting prioritization by request_units_deprecated instruction - true, // enable request heap frame instruction - true, // enable support set accounts data size instruction - // TODO: round_compute_unit_price_enabled: bool + true, // use default units per instruction + true, // supports prioritization by request_units_deprecated instruction + true, // enable request heap frame instruction + true, // enable support set accounts data size instruction + // TODO: round_compute_unit_price_enabled: bool ) .ok()?; Some(TransactionPriorityDetails { @@ -70,7 +70,8 @@ mod tests { use { super::*, solana_sdk::{ - compute_budget::ComputeBudgetInstruction, + compute_budget::{self, ComputeBudgetInstruction}, + instruction::Instruction, message::Message, pubkey::Pubkey, signature::{Keypair, Signer}, @@ -193,4 +194,49 @@ mod tests { }) ); } + + #[test] + fn test_get_priority_with_deprecated_compute_unit_request() { + let priority = 1_000; + let units = 200_000; + let additional_fee = units * priority / 1_000_000; + let keypair = Keypair::new(); + let transaction = Transaction::new_unsigned(Message::new( + &[ + system_instruction::transfer(&keypair.pubkey(), &Pubkey::new_unique(), 1), + Instruction::new_with_borsh( + compute_budget::id(), + &ComputeBudgetInstruction::RequestUnitsDeprecated { + units, + additional_fee, + }, + vec![], + ), + ], + Some(&keypair.pubkey()), + )); + + // assert for SanitizedVersionedTransaction + let versioned_transaction = VersionedTransaction::from(transaction.clone()); + let sanitized_versioned_transaction = + SanitizedVersionedTransaction::try_new(versioned_transaction).unwrap(); + assert_eq!( + sanitized_versioned_transaction.get_transaction_priority_details(false), + Some(TransactionPriorityDetails { + priority: priority as u64, + compute_unit_limit: units as u64 + }) + ); + + // assert for SanitizedTransaction + let sanitized_transaction = + SanitizedTransaction::try_from_legacy_transaction(transaction).unwrap(); + assert_eq!( + sanitized_transaction.get_transaction_priority_details(false), + Some(TransactionPriorityDetails { + priority: priority as u64, + compute_unit_limit: units as u64 + }) + ); + } }