Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: touch ups
Browse files Browse the repository at this point in the history
mattsse committed Jan 18, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0b31970 commit 3fc4c40
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ use reth_transaction_pool::{
use revm::primitives::{AccessList, KzgSettings};
use std::sync::{
atomic::{AtomicU64, Ordering},
Arc, LazyLock,
Arc, OnceLock,
};

/// Type alias for default optimism transaction pool
@@ -36,34 +36,33 @@ pub type OpTransactionPool<Client, S> = Pool<
>;

/// Pool transaction for OP.
#[derive(Debug, derive_more::Deref)]
///
/// This type wraps the actual transaction and caches values that are frequently used by the pool.
/// For payload building this lazily tracks values that are required during payload building:
/// - Estimated compressed size of this transaction
#[derive(Debug, Clone, derive_more::Deref)]
pub struct OpPooledTransaction {
#[deref]
inner: EthPooledTransaction<OpTransactionSigned>,
estimated_tx_compressed_size: LazyLock<u64>,
/// The estimated size of this transaction, lazily computed.
estimated_tx_compressed_size: OnceLock<u32>,
}

impl OpPooledTransaction {
/// Create new instance of [Self].
pub fn new(transaction: RecoveredTx<OpTransactionSigned>, encoded_length: usize) -> Self {
Self {
inner: EthPooledTransaction::new(transaction, encoded_length),
estimated_tx_compressed_size: LazyLock::new(Default::default),
estimated_tx_compressed_size: Default::default(),
}
}

/// Returns the estimated compressed size of a transaction.
pub fn compressed_size(&self) -> u64 {
*self.estimated_tx_compressed_size
}
}

impl Clone for OpPooledTransaction {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
estimated_tx_compressed_size: LazyLock::new(Default::default),
}
/// Returns the estimated compressed size of a transaction in bytes scaled by 1e6.
// This value is computed based on the following formula:
// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
pub fn estimated_compressed_size(&self) -> u32 {
// TODO(mattsse): use standalone flz compute function
*self.estimated_tx_compressed_size.get_or_init(|| self.inner.encoded_length as u32)
}
}

@@ -73,7 +72,7 @@ impl From<RecoveredTx<op_alloy_consensus::OpPooledTransaction>> for OpPooledTran
let tx = tx.map_transaction(|tx| tx.into());
Self {
inner: EthPooledTransaction::new(tx, encoded_len),
estimated_tx_compressed_size: LazyLock::new(Default::default),
estimated_tx_compressed_size: Default::default(),
}
}
}

0 comments on commit 3fc4c40

Please sign in to comment.