Skip to content

Commit

Permalink
Separate file for ImmutableDeserializedPacket type
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Aug 5, 2022
1 parent 4e43aa6 commit 0f39e9e
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 54 deletions.
2 changes: 2 additions & 0 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! The `banking_stage` processes Transaction messages. It is intended to be used
//! to construct a software pipeline. The stage uses all available CPU cores and
//! can do its processing in parallel with signature verification on the GPU.
use {
crate::{
forward_packet_batches_by_accounts::ForwardPacketBatchesByAccounts,
immutable_deserialized_packet::ImmutableDeserializedPacket,
leader_slot_banking_stage_metrics::{LeaderSlotMetricsTracker, ProcessTransactionsSummary},
leader_slot_banking_stage_timing_metrics::{
LeaderExecuteAndCommitTimings, RecordTransactionsTimings,
Expand Down
4 changes: 3 additions & 1 deletion core/src/forward_packet_batches_by_accounts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use {
crate::unprocessed_packet_batches::{self, ImmutableDeserializedPacket},
crate::{
immutable_deserialized_packet::ImmutableDeserializedPacket, unprocessed_packet_batches,
},
solana_perf::packet::Packet,
solana_runtime::{
bank::Bank,
Expand Down
68 changes: 68 additions & 0 deletions core/src/immutable_deserialized_packet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use {
crate::transaction_priority_details::TransactionPriorityDetails,
solana_perf::packet::Packet,
solana_sdk::{hash::Hash, transaction::SanitizedVersionedTransaction},
};

#[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(
original_packet: Packet,
transaction: SanitizedVersionedTransaction,
message_hash: Hash,
is_simple_vote: bool,
priority_details: TransactionPriorityDetails,
) -> Self {
Self {
original_packet,
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())
}
}
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod fork_choice;
pub mod forward_packet_batches_by_accounts;
pub mod gen_keys;
pub mod heaviest_subtree_fork_choice;
pub mod immutable_deserialized_packet;
pub mod latest_validator_votes_for_frozen_banks;
pub mod leader_slot_banking_stage_metrics;
pub mod leader_slot_banking_stage_timing_metrics;
Expand Down
60 changes: 7 additions & 53 deletions core/src/unprocessed_packet_batches.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
crate::transaction_priority_details::{
GetTransactionPriorityDetails, TransactionPriorityDetails,
crate::{
immutable_deserialized_packet::ImmutableDeserializedPacket,
transaction_priority_details::{GetTransactionPriorityDetails, TransactionPriorityDetails},
},
min_max_heap::MinMaxHeap,
solana_perf::packet::{Packet, PacketBatch},
Expand Down Expand Up @@ -41,41 +42,6 @@ pub enum DeserializedPacketError {
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 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
}
}

/// Holds deserialized messages, as well as computed message_hash and other things needed to create
/// SanitizedTransaction
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -113,13 +79,13 @@ impl DeserializedPacket {
.ok_or(DeserializedPacketError::PrioritizationFailure)?;

Ok(Self {
immutable_section: Rc::new(ImmutableDeserializedPacket {
original_packet: packet,
transaction: sanitized_transaction,
immutable_section: Rc::new(ImmutableDeserializedPacket::new(
packet,
sanitized_transaction,
message_hash,
is_simple_vote,
priority_details,
}),
)),
forwarded: false,
})
}
Expand All @@ -143,18 +109,6 @@ impl Ord for DeserializedPacket {
}
}

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())
}
}

/// Currently each banking_stage thread has a `UnprocessedPacketBatches` buffer to store
/// PacketBatch's received from sigverify. Banking thread continuously scans the buffer
/// to pick proper packets to add to the block.
Expand Down

0 comments on commit 0f39e9e

Please sign in to comment.