Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename priority to compute_unit_price #35062

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use {
},
solana_runtime::{
bank::{Bank, LoadAndExecuteTransactionsOutput},
compute_budget_details::GetComputeBudgetDetails,
svm::account_loader::validate_fee_payer,
transaction_batch::TransactionBatch,
transaction_priority_details::GetTransactionPriorityDetails,
},
solana_sdk::{
clock::{Slot, FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET, MAX_PROCESSING_AGE},
Expand Down Expand Up @@ -586,8 +586,8 @@ impl Consumer {
.filter_map(|transaction| {
let round_compute_unit_price_enabled = false; // TODO get from working_bank.feature_set
transaction
.get_transaction_priority_details(round_compute_unit_price_enabled)
.map(|details| details.priority)
.get_compute_budget_details(round_compute_unit_price_enabled)
.map(|details| details.compute_unit_price)
})
.minmax();
let (min_prioritization_fees, max_prioritization_fees) =
Expand Down
28 changes: 13 additions & 15 deletions core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
solana_perf::packet::Packet,
solana_runtime::transaction_priority_details::{
GetTransactionPriorityDetails, TransactionPriorityDetails,
},
solana_runtime::compute_budget_details::{ComputeBudgetDetails, GetComputeBudgetDetails},
solana_sdk::{
feature_set,
hash::Hash,
Expand Down Expand Up @@ -42,7 +40,7 @@ pub struct ImmutableDeserializedPacket {
transaction: SanitizedVersionedTransaction,
message_hash: Hash,
is_simple_vote: bool,
priority_details: TransactionPriorityDetails,
compute_budget_details: ComputeBudgetDetails,
}

impl ImmutableDeserializedPacket {
Expand All @@ -54,21 +52,21 @@ impl ImmutableDeserializedPacket {
let is_simple_vote = packet.meta().is_simple_vote_tx();

// drop transaction if prioritization fails.
let mut priority_details = sanitized_transaction
.get_transaction_priority_details(packet.meta().round_compute_unit_price())
let mut compute_budget_details = sanitized_transaction
.get_compute_budget_details(packet.meta().round_compute_unit_price())
.ok_or(DeserializedPacketError::PrioritizationFailure)?;

// set priority to zero for vote transactions
// set compute unit price to zero for vote transactions
if is_simple_vote {
priority_details.priority = 0;
compute_budget_details.compute_unit_price = 0;
};

Ok(Self {
original_packet: packet,
transaction: sanitized_transaction,
message_hash,
is_simple_vote,
priority_details,
compute_budget_details,
})
}

Expand All @@ -88,16 +86,16 @@ impl ImmutableDeserializedPacket {
self.is_simple_vote
}

pub fn priority(&self) -> u64 {
self.priority_details.priority
pub fn compute_unit_price(&self) -> u64 {
self.compute_budget_details.compute_unit_price
}

pub fn compute_unit_limit(&self) -> u64 {
self.priority_details.compute_unit_limit
self.compute_budget_details.compute_unit_limit
}

pub fn priority_details(&self) -> TransactionPriorityDetails {
self.priority_details.clone()
pub fn compute_budget_details(&self) -> ComputeBudgetDetails {
self.compute_budget_details.clone()
}

// This function deserializes packets into transactions, computes the blake3 hash of transaction
Expand Down Expand Up @@ -131,7 +129,7 @@ impl PartialOrd for ImmutableDeserializedPacket {

impl Ord for ImmutableDeserializedPacket {
fn cmp(&self, other: &Self) -> Ordering {
self.priority().cmp(&other.priority())
self.compute_unit_price().cmp(&other.compute_unit_price())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ mod tests {
crossbeam_channel::{unbounded, Receiver},
itertools::Itertools,
solana_cost_model::cost_model::CostModel,
solana_runtime::transaction_priority_details::TransactionPriorityDetails,
solana_runtime::compute_budget_details::ComputeBudgetDetails,
solana_sdk::{
compute_budget::ComputeBudgetInstruction, feature_set::FeatureSet, hash::Hash,
message::Message, pubkey::Pubkey, signature::Keypair, signer::Signer,
Expand Down Expand Up @@ -562,12 +562,16 @@ mod tests {
>,
) -> TransactionStateContainer {
let mut container = TransactionStateContainer::with_capacity(10 * 1024);
for (index, (from_keypair, to_pubkeys, lamports, priority)) in
for (index, (from_keypair, to_pubkeys, lamports, compute_unit_price)) in
tx_infos.into_iter().enumerate()
{
let id = TransactionId::new(index as u64);
let transaction =
prioritized_tranfers(from_keypair.borrow(), to_pubkeys, lamports, priority);
let transaction = prioritized_tranfers(
from_keypair.borrow(),
to_pubkeys,
lamports,
compute_unit_price,
);
let transaction_cost = CostModel::calculate_cost(&transaction, &FeatureSet::default());
let transaction_ttl = SanitizedTransactionTTL {
transaction,
Expand All @@ -576,8 +580,8 @@ mod tests {
container.insert_new_transaction(
id,
transaction_ttl,
TransactionPriorityDetails {
priority,
ComputeBudgetDetails {
compute_unit_price,
compute_unit_limit: 1,
},
transaction_cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ impl SchedulerController {
let mut error_counts = TransactionErrorMetrics::default();
for chunk in packets.chunks(CHUNK_SIZE) {
let mut post_sanitization_count: usize = 0;
let (transactions, priority_details): (Vec<_>, Vec<_>) = chunk
let (transactions, compute_budget_details): (Vec<_>, Vec<_>) = chunk
.iter()
.filter_map(|packet| {
packet
.build_sanitized_transaction(feature_set, vote_only, bank.as_ref())
.map(|tx| (tx, packet.priority_details()))
.map(|tx| (tx, packet.compute_budget_details()))
})
.inspect(|_| saturating_add_assign!(post_sanitization_count, 1))
.filter(|(tx, _)| {
Expand All @@ -337,9 +337,9 @@ impl SchedulerController {
let post_lock_validation_count = transactions.len();

let mut post_transaction_check_count: usize = 0;
for ((transaction, priority_details), _) in transactions
for ((transaction, compute_budget_details), _) in transactions
.into_iter()
.zip(priority_details)
.zip(compute_budget_details)
.zip(check_results)
.filter(|(_, check_result)| check_result.0.is_ok())
{
Expand All @@ -355,7 +355,7 @@ impl SchedulerController {
if self.container.insert_new_transaction(
transaction_id,
transaction_ttl,
priority_details,
compute_budget_details,
transaction_cost,
) {
saturating_add_assign!(self.count_metrics.num_dropped_on_capacity, 1);
Expand Down
62 changes: 31 additions & 31 deletions core/src/banking_stage/transaction_scheduler/transaction_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
solana_cost_model::transaction_cost::TransactionCost,
solana_runtime::transaction_priority_details::TransactionPriorityDetails,
solana_runtime::compute_budget_details::ComputeBudgetDetails,
solana_sdk::{slot_history::Slot, transaction::SanitizedTransaction},
};

Expand Down Expand Up @@ -34,13 +34,13 @@ pub(crate) enum TransactionState {
/// The transaction is available for scheduling.
Unprocessed {
transaction_ttl: SanitizedTransactionTTL,
transaction_priority_details: TransactionPriorityDetails,
compute_budget_details: ComputeBudgetDetails,
transaction_cost: TransactionCost,
forwarded: bool,
},
/// The transaction is currently scheduled or being processed.
Pending {
transaction_priority_details: TransactionPriorityDetails,
compute_budget_details: ComputeBudgetDetails,
transaction_cost: TransactionCost,
forwarded: bool,
},
Expand All @@ -50,28 +50,28 @@ impl TransactionState {
/// Creates a new `TransactionState` in the `Unprocessed` state.
pub(crate) fn new(
transaction_ttl: SanitizedTransactionTTL,
transaction_priority_details: TransactionPriorityDetails,
compute_budget_details: ComputeBudgetDetails,
transaction_cost: TransactionCost,
) -> Self {
Self::Unprocessed {
transaction_ttl,
transaction_priority_details,
compute_budget_details,
transaction_cost,
forwarded: false,
}
}

/// Returns a reference to the priority details of the transaction.
pub(crate) fn transaction_priority_details(&self) -> &TransactionPriorityDetails {
/// Returns a reference to the compute budget details of the transaction.
pub(crate) fn compute_budget_details(&self) -> &ComputeBudgetDetails {
match self {
Self::Unprocessed {
transaction_priority_details,
compute_budget_details,
..
} => transaction_priority_details,
} => compute_budget_details,
Self::Pending {
transaction_priority_details,
compute_budget_details,
..
} => transaction_priority_details,
} => compute_budget_details,
}
}

Expand All @@ -87,9 +87,9 @@ impl TransactionState {
}
}

/// Returns the priority of the transaction.
pub(crate) fn priority(&self) -> u64 {
self.transaction_priority_details().priority
/// Returns the compute unit price of the transaction.
pub(crate) fn compute_unit_price(&self) -> u64 {
self.compute_budget_details().compute_unit_price
}

/// Returns whether or not the transaction has already been forwarded.
Expand Down Expand Up @@ -119,12 +119,12 @@ impl TransactionState {
match self.take() {
TransactionState::Unprocessed {
transaction_ttl,
transaction_priority_details,
compute_budget_details,
transaction_cost,
forwarded,
} => {
*self = TransactionState::Pending {
transaction_priority_details,
compute_budget_details,
transaction_cost,
forwarded,
};
Expand All @@ -146,13 +146,13 @@ impl TransactionState {
match self.take() {
TransactionState::Unprocessed { .. } => panic!("already unprocessed"),
TransactionState::Pending {
transaction_priority_details,
compute_budget_details,
transaction_cost,
forwarded,
} => {
*self = Self::Unprocessed {
transaction_ttl,
transaction_priority_details,
compute_budget_details,
transaction_cost,
forwarded,
}
Expand All @@ -179,8 +179,8 @@ impl TransactionState {
core::mem::replace(
self,
Self::Pending {
transaction_priority_details: TransactionPriorityDetails {
priority: 0,
compute_budget_details: ComputeBudgetDetails {
compute_unit_price: 0,
compute_unit_limit: 0,
},
transaction_cost: TransactionCost::SimpleVote {
Expand All @@ -203,15 +203,15 @@ mod tests {
},
};

fn create_transaction_state(priority: u64) -> TransactionState {
fn create_transaction_state(compute_unit_price: u64) -> TransactionState {
let from_keypair = Keypair::new();
let ixs = vec![
system_instruction::transfer(
&from_keypair.pubkey(),
&solana_sdk::pubkey::new_rand(),
1,
),
ComputeBudgetInstruction::set_compute_unit_price(priority),
ComputeBudgetInstruction::set_compute_unit_price(compute_unit_price),
];
let message = Message::new(&ixs, Some(&from_keypair.pubkey()));
let tx = Transaction::new(&[&from_keypair], message, Hash::default());
Expand All @@ -227,8 +227,8 @@ mod tests {

TransactionState::new(
transaction_ttl,
TransactionPriorityDetails {
priority,
ComputeBudgetDetails {
compute_unit_price,
compute_unit_limit: 0,
},
transaction_cost,
Expand Down Expand Up @@ -294,16 +294,16 @@ mod tests {
}

#[test]
fn test_transaction_priority_details() {
let priority = 15;
let mut transaction_state = create_transaction_state(priority);
assert_eq!(transaction_state.priority(), priority);
fn test_compute_unit_price() {
let compute_unit_price = 15;
let mut transaction_state = create_transaction_state(compute_unit_price);
assert_eq!(transaction_state.compute_unit_price(), compute_unit_price);

// ensure priority is not lost through state transitions
// ensure compute unit price is not lost through state transitions
let transaction_ttl = transaction_state.transition_to_pending();
assert_eq!(transaction_state.priority(), priority);
assert_eq!(transaction_state.compute_unit_price(), compute_unit_price);
transaction_state.transition_to_unprocessed(transaction_ttl);
assert_eq!(transaction_state.priority(), priority);
assert_eq!(transaction_state.compute_unit_price(), compute_unit_price);
}

#[test]
Expand Down
Loading
Loading