Skip to content

Commit

Permalink
type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Dec 11, 2024
1 parent 1873f61 commit 5cd4087
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use {
super::{
scheduler_metrics::{SchedulerCountMetrics, SchedulerTimingMetrics},
transaction_state::TransactionState,
transaction_state_container::{SharedBytes, StateContainer, TransactionViewStateContainer},
transaction_state_container::{
SharedBytes, StateContainer, TransactionViewState, TransactionViewStateContainer,
},
},
crate::{
banking_stage::{
Expand Down Expand Up @@ -460,8 +462,7 @@ impl TransactionViewReceiveAndBuffer {
alt_resolved_slot: Slot,
sanitized_epoch: Epoch,
transaction_account_lock_limit: usize,
) -> Result<TransactionState<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>, ()>
{
) -> Result<TransactionViewState, ()> {
// Parsing and basic sanitization checks
let Ok(view) = SanitizedTransactionView::try_new_sanitized(bytes) else {
return Err(());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ impl<Tx: TransactionWithMeta> TransactionStateContainer<Tx> {
}

pub type SharedBytes = Arc<Vec<u8>>;
pub(crate) type RuntimeTransactionView = RuntimeTransaction<ResolvedTransactionView<SharedBytes>>;
pub(crate) type TransactionViewState = TransactionState<RuntimeTransactionView>;

/// A wrapper around `TransactionStateContainer` that allows re-uses
/// pre-allocated `Bytes` to copy packet data into and use for serialization.
/// This is used to avoid allocations in parsing transactions.
pub struct TransactionViewStateContainer {
inner: TransactionStateContainer<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>,
inner: TransactionStateContainer<RuntimeTransactionView>,
bytes_buffer: Box<[SharedBytes]>,
}

Expand All @@ -216,12 +218,7 @@ impl TransactionViewStateContainer {
pub(crate) fn try_insert_with_data(
&mut self,
data: &[u8],
f: impl FnOnce(
SharedBytes,
) -> Result<
TransactionState<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>,
(),
>,
f: impl FnOnce(SharedBytes) -> Result<TransactionState<RuntimeTransactionView>, ()>,
) -> bool {
// Get remaining capacity before inserting.
let remaining_capacity = self.remaining_capacity();
Expand Down Expand Up @@ -265,9 +262,7 @@ impl TransactionViewStateContainer {
}
}

impl StateContainer<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>
for TransactionViewStateContainer
{
impl StateContainer<RuntimeTransactionView> for TransactionViewStateContainer {
fn with_capacity(capacity: usize) -> Self {
let inner = TransactionStateContainer::with_capacity(capacity);
let bytes_buffer = (0..inner.id_to_transaction_state.capacity())
Expand Down Expand Up @@ -299,17 +294,15 @@ impl StateContainer<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>
fn get_mut_transaction_state(
&mut self,
id: TransactionId,
) -> Option<&mut TransactionState<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>>
{
) -> Option<&mut TransactionViewState> {
self.inner.get_mut_transaction_state(id)
}

#[inline]
fn get_transaction_ttl(
&self,
id: TransactionId,
) -> Option<&SanitizedTransactionTTL<RuntimeTransaction<ResolvedTransactionView<SharedBytes>>>>
{
) -> Option<&SanitizedTransactionTTL<RuntimeTransactionView>> {
self.inner.get_transaction_ttl(id)
}

Expand Down

0 comments on commit 5cd4087

Please sign in to comment.