From 0f39e9e6a4f6a3a0ab38cea4a26600ba0beb7d99 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgerald Date: Fri, 5 Aug 2022 11:05:19 -0500 Subject: [PATCH] Separate file for ImmutableDeserializedPacket type --- core/src/banking_stage.rs | 2 + .../src/forward_packet_batches_by_accounts.rs | 4 +- core/src/immutable_deserialized_packet.rs | 68 +++++++++++++++++++ core/src/lib.rs | 1 + core/src/unprocessed_packet_batches.rs | 60 ++-------------- 5 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 core/src/immutable_deserialized_packet.rs diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index b93bbf3d0420e2..a4161003adf6b2 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -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, diff --git a/core/src/forward_packet_batches_by_accounts.rs b/core/src/forward_packet_batches_by_accounts.rs index 14fcfe486fa8d6..ccd367349a4fdc 100644 --- a/core/src/forward_packet_batches_by_accounts.rs +++ b/core/src/forward_packet_batches_by_accounts.rs @@ -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, diff --git a/core/src/immutable_deserialized_packet.rs b/core/src/immutable_deserialized_packet.rs new file mode 100644 index 00000000000000..3188083b435be0 --- /dev/null +++ b/core/src/immutable_deserialized_packet.rs @@ -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 { + Some(self.cmp(other)) + } +} + +impl Ord for ImmutableDeserializedPacket { + fn cmp(&self, other: &Self) -> Ordering { + self.priority().cmp(&other.priority()) + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index 9be6ab5b9cc4ba..4133f08152bb64 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -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; diff --git a/core/src/unprocessed_packet_batches.rs b/core/src/unprocessed_packet_batches.rs index 3305e264b77d4f..6ad7ee247d2d1c 100644 --- a/core/src/unprocessed_packet_batches.rs +++ b/core/src/unprocessed_packet_batches.rs @@ -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}, @@ -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)] @@ -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, }) } @@ -143,18 +109,6 @@ impl Ord for DeserializedPacket { } } -impl PartialOrd for ImmutableDeserializedPacket { - fn partial_cmp(&self, other: &Self) -> Option { - 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.