This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
collect min prioritization fees when replaying sanitized transactions (…
…#26709) * Collect blocks' minimum prioritization fees when replaying sanitized transactions * Limits block min-fee metrics reporting to top 10 writable accounts * Add service thread to asynchronously update and finalize prioritization fee cache * Add bench test for prioritization_fee_cache Co-authored-by: Tyera Eulberg <teulberg@gmail.com> (cherry picked from commit 8bb039d) # Conflicts: # core/src/immutable_deserialized_packet.rs # core/src/replay_stage.rs # core/src/tvu.rs # core/src/unprocessed_packet_batches.rs # core/src/validator.rs
- Loading branch information
1 parent
081ceb0
commit d9760df
Showing
16 changed files
with
1,504 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use { | ||
solana_perf::packet::Packet, | ||
solana_runtime::transaction_priority_details::{ | ||
GetTransactionPriorityDetails, TransactionPriorityDetails, | ||
}, | ||
solana_sdk::{ | ||
hash::Hash, | ||
message::Message, | ||
sanitize::SanitizeError, | ||
short_vec::decode_shortu16_len, | ||
signature::Signature, | ||
transaction::{SanitizedVersionedTransaction, VersionedTransaction}, | ||
}, | ||
std::{cmp::Ordering, mem::size_of}, | ||
thiserror::Error, | ||
}; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum DeserializedPacketError { | ||
#[error("ShortVec Failed to Deserialize")] | ||
// short_vec::decode_shortu16_len() currently returns () on error | ||
ShortVecError(()), | ||
#[error("Deserialization Error: {0}")] | ||
DeserializationError(#[from] bincode::Error), | ||
#[error("overflowed on signature size {0}")] | ||
SignatureOverflowed(usize), | ||
#[error("packet failed sanitization {0}")] | ||
SanitizeError(#[from] SanitizeError), | ||
#[error("transaction failed prioritization")] | ||
PrioritizationFailure, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub struct ImmutableDeserializedPacket { | ||
original_packet: Packet, | ||
transaction: SanitizedVersionedTransaction, | ||
message_hash: Hash, | ||
is_simple_vote: bool, | ||
priority_details: TransactionPriorityDetails, | ||
} | ||
|
||
impl ImmutableDeserializedPacket { | ||
pub fn new( | ||
packet: Packet, | ||
priority_details: Option<TransactionPriorityDetails>, | ||
) -> Result<Self, DeserializedPacketError> { | ||
let versioned_transaction: VersionedTransaction = packet.deserialize_slice(..)?; | ||
let sanitized_transaction = SanitizedVersionedTransaction::try_from(versioned_transaction)?; | ||
let message_bytes = packet_message(&packet)?; | ||
let message_hash = Message::hash_raw_message(message_bytes); | ||
let is_simple_vote = packet.meta.is_simple_vote_tx(); | ||
|
||
// drop transaction if prioritization fails. | ||
let priority_details = priority_details | ||
.or_else(|| sanitized_transaction.get_transaction_priority_details()) | ||
.ok_or(DeserializedPacketError::PrioritizationFailure)?; | ||
|
||
Ok(Self { | ||
original_packet: packet, | ||
transaction: sanitized_transaction, | ||
message_hash, | ||
is_simple_vote, | ||
priority_details, | ||
}) | ||
} | ||
|
||
pub fn original_packet(&self) -> &Packet { | ||
&self.original_packet | ||
} | ||
|
||
pub fn transaction(&self) -> &SanitizedVersionedTransaction { | ||
&self.transaction | ||
} | ||
|
||
pub fn message_hash(&self) -> &Hash { | ||
&self.message_hash | ||
} | ||
|
||
pub fn is_simple_vote(&self) -> bool { | ||
self.is_simple_vote | ||
} | ||
|
||
pub fn priority(&self) -> u64 { | ||
self.priority_details.priority | ||
} | ||
|
||
pub fn compute_unit_limit(&self) -> u64 { | ||
self.priority_details.compute_unit_limit | ||
} | ||
} | ||
|
||
impl PartialOrd for ImmutableDeserializedPacket { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} | ||
|
||
impl Ord for ImmutableDeserializedPacket { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
self.priority().cmp(&other.priority()) | ||
} | ||
} | ||
|
||
/// Read the transaction message from packet data | ||
fn packet_message(packet: &Packet) -> Result<&[u8], DeserializedPacketError> { | ||
let (sig_len, sig_size) = packet | ||
.data(..) | ||
.and_then(|bytes| decode_shortu16_len(bytes).ok()) | ||
.ok_or(DeserializedPacketError::ShortVecError(()))?; | ||
sig_len | ||
.checked_mul(size_of::<Signature>()) | ||
.and_then(|v| v.checked_add(sig_size)) | ||
.and_then(|msg_start| packet.data(msg_start..)) | ||
.ok_or(DeserializedPacketError::SignatureOverflowed(sig_size)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use { | ||
super::*, | ||
solana_sdk::{signature::Keypair, system_transaction}, | ||
}; | ||
|
||
#[test] | ||
fn simple_deserialized_packet() { | ||
let tx = system_transaction::transfer( | ||
&Keypair::new(), | ||
&solana_sdk::pubkey::new_rand(), | ||
1, | ||
Hash::new_unique(), | ||
); | ||
let packet = Packet::from_data(None, &tx).unwrap(); | ||
let deserialized_packet = ImmutableDeserializedPacket::new(packet, None); | ||
|
||
assert!(matches!(deserialized_packet, Ok(_))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.