Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
rename several priorities to compute_unit_price
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Feb 2, 2024
1 parent dd30175 commit e7b0e24
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 50 deletions.
2 changes: 1 addition & 1 deletion core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl Consumer {
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)
.map(|details| details.compute_unit_price)
})
.minmax();
let (min_prioritization_fees, max_prioritization_fees) =
Expand Down
8 changes: 4 additions & 4 deletions core/src/banking_stage/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ImmutableDeserializedPacket {

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

Ok(Self {
Expand Down Expand Up @@ -88,8 +88,8 @@ impl ImmutableDeserializedPacket {
self.is_simple_vote
}

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

pub fn compute_unit_limit(&self) -> u64 {
Expand Down Expand Up @@ -131,7 +131,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 @@ -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 @@ -577,7 +581,7 @@ mod tests {
id,
transaction_ttl,
TransactionPriorityDetails {
priority,
compute_unit_price,
compute_unit_limit: 1,
},
transaction_cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl TransactionState {

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

/// Returns whether or not the transaction has already been forwarded.
Expand Down Expand Up @@ -180,7 +180,7 @@ impl TransactionState {
self,
Self::Pending {
transaction_priority_details: TransactionPriorityDetails {
priority: 0,
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 @@ -228,7 +228,7 @@ mod tests {
TransactionState::new(
transaction_ttl,
TransactionPriorityDetails {
priority,
compute_unit_price,
compute_unit_limit: 0,
},
transaction_cost,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ impl TransactionStateContainer {
transaction_priority_details: TransactionPriorityDetails,
transaction_cost: TransactionCost,
) -> bool {
let priority_id =
TransactionPriorityId::new(transaction_priority_details.priority, transaction_id);
let priority_id = TransactionPriorityId::new(
transaction_priority_details.compute_unit_price,
transaction_id,
);
self.id_to_transaction_state.insert(
transaction_id,
TransactionState::new(
Expand Down Expand Up @@ -210,7 +212,7 @@ mod tests {
(
transaction_ttl,
TransactionPriorityDetails {
priority,
compute_unit_price: priority,
compute_unit_limit: 0,
},
transaction_cost,
Expand Down
16 changes: 10 additions & 6 deletions core/src/banking_stage/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl PartialOrd for DeserializedPacket {
impl Ord for DeserializedPacket {
fn cmp(&self, other: &Self) -> Ordering {
self.immutable_section()
.priority()
.cmp(&other.immutable_section().priority())
.compute_unit_price()
.cmp(&other.immutable_section().compute_unit_price())
}
}

Expand Down Expand Up @@ -193,12 +193,16 @@ impl UnprocessedPacketBatches {
self.packet_priority_queue.is_empty()
}

pub fn get_min_priority(&self) -> Option<u64> {
self.packet_priority_queue.peek_min().map(|x| x.priority())
pub fn get_min_compute_unit_price(&self) -> Option<u64> {
self.packet_priority_queue
.peek_min()
.map(|x| x.compute_unit_price())
}

pub fn get_max_priority(&self) -> Option<u64> {
self.packet_priority_queue.peek_max().map(|x| x.priority())
pub fn get_max_compute_unit_price(&self) -> Option<u64> {
self.packet_priority_queue
.peek_max()
.map(|x| x.compute_unit_price())
}

fn push_internal(&mut self, deserialized_packet: DeserializedPacket) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/banking_stage/unprocessed_transaction_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl UnprocessedTransactionStorage {
match self {
Self::VoteStorage(_) => None,
Self::LocalTransactionStorage(transaction_storage) => {
transaction_storage.get_min_priority()
transaction_storage.get_min_compute_unit_price()
}
}
}
Expand All @@ -295,7 +295,7 @@ impl UnprocessedTransactionStorage {
match self {
Self::VoteStorage(_) => None,
Self::LocalTransactionStorage(transaction_storage) => {
transaction_storage.get_max_priority()
transaction_storage.get_max_compute_unit_price()
}
}
}
Expand Down Expand Up @@ -547,12 +547,12 @@ impl ThreadLocalUnprocessedPackets {
self.unprocessed_packet_batches.len()
}

pub fn get_min_priority(&self) -> Option<u64> {
self.unprocessed_packet_batches.get_min_priority()
pub fn get_min_compute_unit_price(&self) -> Option<u64> {
self.unprocessed_packet_batches.get_min_compute_unit_price()
}

pub fn get_max_priority(&self) -> Option<u64> {
self.unprocessed_packet_batches.get_max_priority()
pub fn get_max_compute_unit_price(&self) -> Option<u64> {
self.unprocessed_packet_batches.get_max_compute_unit_price()
}

fn max_receive_size(&self) -> usize {
Expand Down
24 changes: 12 additions & 12 deletions program-runtime/src/prioritization_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ pub enum PrioritizationFeeType {
#[derive(Default, Debug, PartialEq, Eq)]
pub struct PrioritizationFeeDetails {
fee: u64,
priority: u64,
compute_unit_price: u64,
}

impl PrioritizationFeeDetails {
pub fn new(fee_type: PrioritizationFeeType, compute_unit_limit: u64) -> Self {
match fee_type {
PrioritizationFeeType::ComputeUnitPrice(cu_price) => {
PrioritizationFeeType::ComputeUnitPrice(compute_unit_price) => {
let micro_lamport_fee: MicroLamports =
(cu_price as u128).saturating_mul(compute_unit_limit as u128);
(compute_unit_price as u128).saturating_mul(compute_unit_limit as u128);
let fee = micro_lamport_fee
.saturating_add(MICRO_LAMPORTS_PER_LAMPORT.saturating_sub(1) as u128)
.checked_div(MICRO_LAMPORTS_PER_LAMPORT as u128)
Expand All @@ -27,7 +27,7 @@ impl PrioritizationFeeDetails {

Self {
fee,
priority: cu_price,
compute_unit_price,
}
}
}
Expand All @@ -37,8 +37,8 @@ impl PrioritizationFeeDetails {
self.fee
}

pub fn get_priority(&self) -> u64 {
self.priority
pub fn get_compute_unit_price(&self) -> u64 {
self.compute_unit_price
}
}

Expand All @@ -62,7 +62,7 @@ mod test {
FeeDetails::new(FeeType::ComputeUnitPrice(MICRO_LAMPORTS_PER_LAMPORT - 1), 1),
FeeDetails {
fee: 1,
priority: MICRO_LAMPORTS_PER_LAMPORT - 1,
compute_unit_price: MICRO_LAMPORTS_PER_LAMPORT - 1,
},
"should round up (<1.0) lamport fee to 1 lamport"
);
Expand All @@ -71,15 +71,15 @@ mod test {
FeeDetails::new(FeeType::ComputeUnitPrice(MICRO_LAMPORTS_PER_LAMPORT), 1),
FeeDetails {
fee: 1,
priority: MICRO_LAMPORTS_PER_LAMPORT,
compute_unit_price: MICRO_LAMPORTS_PER_LAMPORT,
},
);

assert_eq!(
FeeDetails::new(FeeType::ComputeUnitPrice(MICRO_LAMPORTS_PER_LAMPORT + 1), 1),
FeeDetails {
fee: 2,
priority: MICRO_LAMPORTS_PER_LAMPORT + 1,
compute_unit_price: MICRO_LAMPORTS_PER_LAMPORT + 1,
},
"should round up (>1.0) lamport fee to 2 lamports"
);
Expand All @@ -88,7 +88,7 @@ mod test {
FeeDetails::new(FeeType::ComputeUnitPrice(200), 100_000),
FeeDetails {
fee: 20,
priority: 200,
compute_unit_price: 200,
},
);

Expand All @@ -99,15 +99,15 @@ mod test {
),
FeeDetails {
fee: u64::MAX,
priority: MICRO_LAMPORTS_PER_LAMPORT,
compute_unit_price: MICRO_LAMPORTS_PER_LAMPORT,
},
);

assert_eq!(
FeeDetails::new(FeeType::ComputeUnitPrice(u64::MAX), u64::MAX),
FeeDetails {
fee: u64::MAX,
priority: u64::MAX,
compute_unit_price: u64::MAX,
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/prioritization_fee_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl PrioritizationFeeCache {
.send(CacheServiceUpdate::TransactionUpdate {
slot: bank.slot(),
bank_id: bank.bank_id(),
transaction_fee: priority_details.priority,
transaction_fee: priority_details.compute_unit_price,
writable_accounts,
})
.unwrap_or_else(|err| {
Expand Down
16 changes: 8 additions & 8 deletions runtime/src/transaction_priority_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TransactionPriorityDetails {
pub priority: u64,
pub compute_unit_price: u64,
pub compute_unit_limit: u64,
}

Expand All @@ -25,7 +25,7 @@ pub trait GetTransactionPriorityDetails {
) -> Option<TransactionPriorityDetails> {
let compute_budget_limits = process_compute_budget_instructions(instructions).ok()?;
Some(TransactionPriorityDetails {
priority: compute_budget_limits.compute_unit_price,
compute_unit_price: compute_budget_limits.compute_unit_price,
compute_unit_limit: u64::from(compute_budget_limits.compute_unit_limit),
})
}
Expand Down Expand Up @@ -87,7 +87,7 @@ mod tests {
assert_eq!(
sanitized_versioned_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: 0,
compute_unit_price: 0,
compute_unit_limit:
solana_program_runtime::compute_budget_processor::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT
as u64,
Expand All @@ -100,7 +100,7 @@ mod tests {
assert_eq!(
sanitized_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: 0,
compute_unit_price: 0,
compute_unit_limit:
solana_program_runtime::compute_budget_processor::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT
as u64,
Expand All @@ -127,7 +127,7 @@ mod tests {
assert_eq!(
sanitized_versioned_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: 0,
compute_unit_price: 0,
compute_unit_limit: requested_cu as u64,
})
);
Expand All @@ -138,7 +138,7 @@ mod tests {
assert_eq!(
sanitized_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: 0,
compute_unit_price: 0,
compute_unit_limit: requested_cu as u64,
})
);
Expand All @@ -163,7 +163,7 @@ mod tests {
assert_eq!(
sanitized_versioned_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: requested_price,
compute_unit_price: requested_price,
compute_unit_limit:
solana_program_runtime::compute_budget_processor::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT
as u64,
Expand All @@ -176,7 +176,7 @@ mod tests {
assert_eq!(
sanitized_transaction.get_transaction_priority_details(false),
Some(TransactionPriorityDetails {
priority: requested_price,
compute_unit_price: requested_price,
compute_unit_limit:
solana_program_runtime::compute_budget_processor::DEFAULT_INSTRUCTION_COMPUTE_UNIT_LIMIT
as u64,
Expand Down

0 comments on commit e7b0e24

Please sign in to comment.